From c333fcec32b1f90bf0da6bb14d2609c20e38a74f Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Fri, 26 Jun 2026 22:21:55 +0900 Subject: style: switch from tabs to 2-space indentation (incl. svelte) --- src/features/system-prompt/index.ts | 18 +- .../system-prompt/logic/view-model.test.ts | 148 +++---- src/features/system-prompt/logic/view-model.ts | 74 ++-- .../system-prompt/ui/SystemPromptBuilder.svelte | 467 +++++++++++---------- 4 files changed, 354 insertions(+), 353 deletions(-) (limited to 'src/features/system-prompt') diff --git a/src/features/system-prompt/index.ts b/src/features/system-prompt/index.ts index 7c77675..661b341 100644 --- a/src/features/system-prompt/index.ts +++ b/src/features/system-prompt/index.ts @@ -1,17 +1,17 @@ export type { - LoadSystemPrompt, - LoadSystemPromptVariables, - SaveSystemPrompt, - SystemPromptLoadResult, - SystemPromptSaveResult, - SystemPromptVariablesResult, - VariableGroup, + LoadSystemPrompt, + LoadSystemPromptVariables, + SaveSystemPrompt, + SystemPromptLoadResult, + SystemPromptSaveResult, + SystemPromptVariablesResult, + VariableGroup, } from "./logic/view-model"; export { buildTag, groupVariables, insertTag } from "./logic/view-model"; export { default as SystemPromptBuilder } from "./ui/SystemPromptBuilder.svelte"; /** Public module manifest — aggregated by the shell's "Loaded Modules" view. */ export const manifest = { - name: "system-prompt", - description: "Global system prompt template builder with variable placeholders", + name: "system-prompt", + description: "Global system prompt template builder with variable placeholders", } as const; diff --git a/src/features/system-prompt/logic/view-model.test.ts b/src/features/system-prompt/logic/view-model.test.ts index a0736cc..223327b 100644 --- a/src/features/system-prompt/logic/view-model.test.ts +++ b/src/features/system-prompt/logic/view-model.test.ts @@ -1,90 +1,90 @@ import type { SystemPromptVariable } from "@dispatch/transport-contract"; import { describe, expect, it } from "vitest"; import { - buildIfNotTag, - buildIfTag, - buildTag, - groupVariables, - insertTag, - isDynamicVariable, + buildIfNotTag, + buildIfTag, + buildTag, + groupVariables, + insertTag, + isDynamicVariable, } from "./view-model"; describe("system-prompt view-model", () => { - describe("buildTag", () => { - it("builds a variable placeholder", () => { - expect(buildTag("system", "time")).toBe("[system:time]"); - }); - }); + describe("buildTag", () => { + it("builds a variable placeholder", () => { + expect(buildTag("system", "time")).toBe("[system:time]"); + }); + }); - describe("buildIfTag", () => { - it("builds an opening conditional tag", () => { - expect(buildIfTag("file", "AGENTS.md")).toBe("[if file:AGENTS.md]"); - }); - }); + describe("buildIfTag", () => { + it("builds an opening conditional tag", () => { + expect(buildIfTag("file", "AGENTS.md")).toBe("[if file:AGENTS.md]"); + }); + }); - describe("buildIfNotTag", () => { - it("builds a negated opening conditional tag", () => { - expect(buildIfNotTag("prompt", "cwd")).toBe("[if !prompt:cwd]"); - }); - }); + describe("buildIfNotTag", () => { + it("builds a negated opening conditional tag", () => { + expect(buildIfNotTag("prompt", "cwd")).toBe("[if !prompt:cwd]"); + }); + }); - describe("insertTag", () => { - it("inserts a tag at the cursor position", () => { - expect(insertTag("Hello world", "[system:time]", 5, 5)).toEqual({ - template: "Hello[system:time] world", - cursor: 18, - }); - }); + describe("insertTag", () => { + it("inserts a tag at the cursor position", () => { + expect(insertTag("Hello world", "[system:time]", 5, 5)).toEqual({ + template: "Hello[system:time] world", + cursor: 18, + }); + }); - it("replaces the selected text", () => { - const tag = buildTag("file", "README.md"); - expect(insertTag("Hello world", tag, 6, 11)).toEqual({ - template: `Hello ${tag}`, - cursor: 6 + tag.length, - }); - }); + it("replaces the selected text", () => { + const tag = buildTag("file", "README.md"); + expect(insertTag("Hello world", tag, 6, 11)).toEqual({ + template: `Hello ${tag}`, + cursor: 6 + tag.length, + }); + }); - it("inserts at the end", () => { - const tag = buildTag("git", "branch"); - expect(insertTag("", tag, 0, 0)).toEqual({ - template: tag, - cursor: tag.length, - }); - }); - }); + it("inserts at the end", () => { + const tag = buildTag("git", "branch"); + expect(insertTag("", tag, 0, 0)).toEqual({ + template: tag, + cursor: tag.length, + }); + }); + }); - describe("groupVariables", () => { - it("groups by type in first-appearing order", () => { - const variables: SystemPromptVariable[] = [ - { type: "system", name: "time", description: "" }, - { type: "prompt", name: "cwd", description: "" }, - { type: "system", name: "date", description: "" }, - { type: "git", name: "branch", description: "" }, - ]; - const groups = groupVariables(variables); - expect(groups.map((g) => g.type)).toEqual(["system", "prompt", "git"]); - expect(groups[0]?.variables.map((v) => v.name)).toEqual(["time", "date"]); - expect(groups[1]?.variables.map((v) => v.name)).toEqual(["cwd"]); - expect(groups[2]?.variables.map((v) => v.name)).toEqual(["branch"]); - }); + describe("groupVariables", () => { + it("groups by type in first-appearing order", () => { + const variables: SystemPromptVariable[] = [ + { type: "system", name: "time", description: "" }, + { type: "prompt", name: "cwd", description: "" }, + { type: "system", name: "date", description: "" }, + { type: "git", name: "branch", description: "" }, + ]; + const groups = groupVariables(variables); + expect(groups.map((g) => g.type)).toEqual(["system", "prompt", "git"]); + expect(groups[0]?.variables.map((v) => v.name)).toEqual(["time", "date"]); + expect(groups[1]?.variables.map((v) => v.name)).toEqual(["cwd"]); + expect(groups[2]?.variables.map((v) => v.name)).toEqual(["branch"]); + }); - it("returns an empty array when no variables", () => { - expect(groupVariables([])).toEqual([]); - }); - }); + it("returns an empty array when no variables", () => { + expect(groupVariables([])).toEqual([]); + }); + }); - describe("isDynamicVariable", () => { - it("returns true when dynamic is true", () => { - expect( - isDynamicVariable({ type: "file", name: "path", description: "", dynamic: true }), - ).toBe(true); - }); + describe("isDynamicVariable", () => { + it("returns true when dynamic is true", () => { + expect( + isDynamicVariable({ type: "file", name: "path", description: "", dynamic: true }), + ).toBe(true); + }); - it("returns false when dynamic is missing or false", () => { - expect(isDynamicVariable({ type: "system", name: "time", description: "" })).toBe(false); - expect( - isDynamicVariable({ type: "system", name: "time", description: "", dynamic: false }), - ).toBe(false); - }); - }); + it("returns false when dynamic is missing or false", () => { + expect(isDynamicVariable({ type: "system", name: "time", description: "" })).toBe(false); + expect( + isDynamicVariable({ type: "system", name: "time", description: "", dynamic: false }), + ).toBe(false); + }); + }); }); diff --git a/src/features/system-prompt/logic/view-model.ts b/src/features/system-prompt/logic/view-model.ts index 6924208..e202ee3 100644 --- a/src/features/system-prompt/logic/view-model.ts +++ b/src/features/system-prompt/logic/view-model.ts @@ -14,20 +14,20 @@ import type { SystemPromptVariable } from "@dispatch/transport-contract"; // ── Injected ports (composition root adapts the store to these shapes) ───────── export type SystemPromptLoadResult = - | { readonly ok: true; readonly template: string } - | { readonly ok: false; readonly error: string }; + | { readonly ok: true; readonly template: string } + | { readonly ok: false; readonly error: string }; export type LoadSystemPrompt = () => Promise; export type SystemPromptSaveResult = - | { readonly ok: true; readonly template: string } - | { readonly ok: false; readonly error: string }; + | { readonly ok: true; readonly template: string } + | { readonly ok: false; readonly error: string }; export type SaveSystemPrompt = (template: string) => Promise; export type SystemPromptVariablesResult = - | { readonly ok: true; readonly variables: readonly SystemPromptVariable[] } - | { readonly ok: false; readonly error: string }; + | { readonly ok: true; readonly variables: readonly SystemPromptVariable[] } + | { readonly ok: false; readonly error: string }; export type LoadSystemPromptVariables = () => Promise; @@ -35,24 +35,24 @@ export type LoadSystemPromptVariables = () => Promise(); - for (const v of variables) { - if (!map.has(v.type)) { - map.set(v.type, []); - order.push(v.type); - } - map.get(v.type)?.push(v); - } - return order.map((type) => ({ type, variables: map.get(type) ?? [] })); + const order: string[] = []; + const map = new Map(); + for (const v of variables) { + if (!map.has(v.type)) { + map.set(v.type, []); + order.push(v.type); + } + map.get(v.type)?.push(v); + } + return order.map((type) => ({ type, variables: map.get(type) ?? [] })); } /** Whether a variable is "dynamic" (any name is valid, e.g. `file:`). */ export function isDynamicVariable(variable: SystemPromptVariable): boolean { - return variable.dynamic === true; + return variable.dynamic === true; } diff --git a/src/features/system-prompt/ui/SystemPromptBuilder.svelte b/src/features/system-prompt/ui/SystemPromptBuilder.svelte index 4e07317..2e92e26 100644 --- a/src/features/system-prompt/ui/SystemPromptBuilder.svelte +++ b/src/features/system-prompt/ui/SystemPromptBuilder.svelte @@ -1,242 +1,243 @@ -- cgit v1.2.3