lsd-pi 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/resources/extensions/slash-commands/plan.js +11 -7
  2. package/dist/resources/extensions/subagent/agents.js +19 -9
  3. package/dist/resources/extensions/subagent/index.js +112 -20
  4. package/dist/resources/extensions/subagent/launch-helpers.js +3 -2
  5. package/package.json +1 -1
  6. package/packages/pi-ai/dist/providers/anthropic-shared.d.ts.map +1 -1
  7. package/packages/pi-ai/dist/providers/anthropic-shared.js +11 -1
  8. package/packages/pi-ai/dist/providers/anthropic-shared.js.map +1 -1
  9. package/packages/pi-ai/src/providers/anthropic-shared.ts +12 -1
  10. package/packages/pi-coding-agent/dist/core/agent-session.d.ts +1 -0
  11. package/packages/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  12. package/packages/pi-coding-agent/dist/core/agent-session.js +62 -6
  13. package/packages/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  14. package/packages/pi-coding-agent/dist/core/sdk.js +1 -1
  15. package/packages/pi-coding-agent/dist/core/sdk.js.map +1 -1
  16. package/packages/pi-coding-agent/dist/core/skill-tool.test.js +15 -0
  17. package/packages/pi-coding-agent/dist/core/skill-tool.test.js.map +1 -1
  18. package/packages/pi-coding-agent/dist/core/skills.d.ts.map +1 -1
  19. package/packages/pi-coding-agent/dist/core/skills.js +1 -0
  20. package/packages/pi-coding-agent/dist/core/skills.js.map +1 -1
  21. package/packages/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
  22. package/packages/pi-coding-agent/dist/core/system-prompt.js +1 -0
  23. package/packages/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
  24. package/packages/pi-coding-agent/dist/tests/path-display.test.js +1 -0
  25. package/packages/pi-coding-agent/dist/tests/path-display.test.js.map +1 -1
  26. package/packages/pi-coding-agent/package.json +1 -1
  27. package/packages/pi-coding-agent/src/core/agent-session.ts +60 -7
  28. package/packages/pi-coding-agent/src/core/sdk.ts +1 -1
  29. package/packages/pi-coding-agent/src/core/skill-tool.test.ts +18 -0
  30. package/packages/pi-coding-agent/src/core/skills.ts +1 -0
  31. package/packages/pi-coding-agent/src/core/system-prompt.ts +3 -0
  32. package/packages/pi-coding-agent/src/tests/path-display.test.ts +1 -0
  33. package/pkg/package.json +1 -1
  34. package/src/resources/extensions/slash-commands/plan.ts +14 -8
  35. package/src/resources/extensions/subagent/agents.ts +22 -7
  36. package/src/resources/extensions/subagent/index.ts +138 -18
  37. package/src/resources/extensions/subagent/launch-helpers.ts +2 -1
@@ -148,7 +148,7 @@ export async function createAgentSession(options = {}) {
148
148
  ? ["hashline_read", "bash", "hashline_edit", "write", "lsp", "bg_shell", "tool_search", "tool_enable", "Skill", "subagent", "await_subagent", "ask_user_questions"]
149
149
  : ["read", "bash", "edit", "write", "lsp", "bg_shell", "tool_search", "tool_enable", "Skill", "subagent", "await_subagent", "ask_user_questions"];
150
150
  const defaultActiveToolNames = toolProfile === "full"
151
- ? Object.keys(allTools)
151
+ ? []
152
152
  : balancedToolNames;
153
153
  const initialActiveToolNames = options.tools
154
154
  ? options.tools.map((t) => t.name).filter((n) => typeof n === "string" && n in allTools)
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/core/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAyC,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,wBAAwB,EAA4B,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAE,YAAY,EA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,CAAC,YAAY;QAClC,cAAc;QACd,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,aAAa;QACb,sBAAsB;QACtB,kBAAkB;QAClB,cAAc,EAAE,IAAI,cAAc,CAAC,eAAe,CAAC;KACtD,CAAC,CAAC;IACH,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,EAAE,CAAC;IAExD,OAAO;QACH,OAAO;QACP,gBAAgB;QAChB,oBAAoB;KACvB,CAAC;AACN,CAAC","sourcesContent":["import { join } from \"node:path\";\nimport { Agent, type AgentMessage, type ThinkingLevel } from \"@gsd/pi-agent-core\";\nimport { supportsAdaptiveThinking, type Message, type Model } from \"@gsd/pi-ai\";\nimport { getAgentDir, getDocsPath } from \"../config.js\";\nimport { AgentSession } from \"./agent-session.js\";\nimport { AuthStorage } from \"./auth-storage.js\";\nimport { DEFAULT_THINKING_LEVEL } from \"./defaults.js\";\nimport type { ExtensionRunner, LoadExtensionsResult, ToolDefinition } from \"./extensions/index.js\";\nimport { convertToLlm } from \"./messages.js\";\nimport { ModelRegistry } from \"./model-registry.js\";\nimport { findInitialModel } from \"./model-resolver.js\";\nimport type { ResourceLoader } from \"./resource-loader.js\";\nimport { DefaultResourceLoader } from \"./resource-loader.js\";\nimport { SessionManager } from \"./session-manager.js\";\nimport { SettingsManager } from \"./settings-manager.js\";\nimport { time } from \"./timings.js\";\nimport { SandboxManager } from \"./sandbox/index.js\";\nimport {\n allTools,\n bashTool,\n codingTools,\n createBashTool,\n createCodingTools,\n createEditTool,\n createFindTool,\n createGrepTool,\n createLsTool,\n createReadOnlyTools,\n createReadTool,\n createWriteTool,\n editTool,\n findTool,\n grepTool,\n hashlineCodingTools,\n hashlineEditTool,\n hashlineReadTool,\n createHashlineCodingTools,\n createHashlineEditTool,\n createHashlineReadTool,\n lsTool,\n readOnlyTools,\n readTool,\n type Tool,\n writeTool,\n} from \"./tools/index.js\";\n\nexport interface CreateAgentSessionOptions {\n /** Working directory for project-local discovery. Default: process.cwd() */\n cwd?: string;\n /** Global config directory. Default: ~/.pi/agent */\n agentDir?: string;\n\n /** Auth storage for credentials. Default: AuthStorage.create(agentDir/auth.json) */\n authStorage?: AuthStorage;\n /** Model registry. Default: new ModelRegistry(authStorage, agentDir/models.json) */\n modelRegistry?: ModelRegistry;\n\n /** Model to use. Default: from settings, else first available */\n model?: Model<any>;\n /** Thinking level. Default: from settings, else 'medium' (clamped to model capabilities) */\n thinkingLevel?: ThinkingLevel;\n /** Models available for cycling (Ctrl+P in interactive mode) */\n scopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;\n\n /** Built-in tools to use. Default: codingTools [read, bash, edit, write] */\n tools?: Tool[];\n /** Custom tools to register (in addition to built-in tools). */\n customTools?: ToolDefinition[];\n\n /** Resource loader. When omitted, DefaultResourceLoader is used. */\n resourceLoader?: ResourceLoader;\n\n /** Session manager. Default: SessionManager.create(cwd) */\n sessionManager?: SessionManager;\n\n /** Settings manager. Default: SettingsManager.create(cwd, agentDir) */\n settingsManager?: SettingsManager;\n}\n\n/** Result from createAgentSession */\nexport interface CreateAgentSessionResult {\n /** The created session */\n session: AgentSession;\n /** Extensions result (for UI context setup in interactive mode) */\n extensionsResult: LoadExtensionsResult;\n /** Warning if session was restored with a different model than saved */\n modelFallbackMessage?: string;\n}\n\n// Re-exports\n\nexport type {\n ExtensionAPI,\n ExtensionCommandContext,\n ExtensionContext,\n ExtensionFactory,\n SlashCommandInfo,\n SlashCommandLocation,\n SlashCommandSource,\n ToolDefinition,\n} from \"./extensions/index.js\";\nexport type { PromptTemplate } from \"./prompt-templates.js\";\nexport type { Skill } from \"./skills.js\";\nexport type { Tool } from \"./tools/index.js\";\n\nexport {\n // Pre-built tools (use process.cwd())\n readTool,\n bashTool,\n editTool,\n writeTool,\n grepTool,\n findTool,\n lsTool,\n codingTools,\n readOnlyTools,\n allTools as allBuiltInTools,\n // Tool factories (for custom cwd)\n createCodingTools,\n createReadOnlyTools,\n createReadTool,\n createBashTool,\n createEditTool,\n createWriteTool,\n createGrepTool,\n createFindTool,\n createLsTool,\n // Hashline edit mode\n hashlineCodingTools,\n hashlineEditTool,\n hashlineReadTool,\n createHashlineCodingTools,\n createHashlineEditTool,\n createHashlineReadTool,\n};\n\n// Helper Functions\n\nfunction getDefaultAgentDir(): string {\n return getAgentDir();\n}\n\nfunction shouldPreferAdaptiveThinkingByDefault(\n model: Model<any> | undefined,\n settingsManager: SettingsManager,\n): boolean {\n return !!model &&\n model.provider === \"anthropic\" &&\n model.reasoning === true &&\n settingsManager.getAnthropicAdaptiveByDefault() &&\n supportsAdaptiveThinking(model.id);\n}\n\n/**\n * Create an AgentSession with the specified options.\n *\n * @example\n * ```typescript\n * // Minimal - uses defaults\n * const { session } = await createAgentSession();\n *\n * // With explicit model\n * import { getModel } from '@gsd/pi-ai';\n * const { session } = await createAgentSession({\n * model: getModel('anthropic', 'claude-opus-4-5'),\n * thinkingLevel: 'high',\n * });\n *\n * // Continue previous session\n * const { session, modelFallbackMessage } = await createAgentSession({\n * continueSession: true,\n * });\n *\n * // Full control\n * const loader = new DefaultResourceLoader({\n * cwd: process.cwd(),\n * agentDir: getAgentDir(),\n * settingsManager: SettingsManager.create(),\n * });\n * await loader.reload();\n * const { session } = await createAgentSession({\n * model: myModel,\n * tools: [readTool, bashTool],\n * resourceLoader: loader,\n * sessionManager: SessionManager.inMemory(),\n * });\n * ```\n */\nexport async function createAgentSession(options: CreateAgentSessionOptions = {}): Promise<CreateAgentSessionResult> {\n const cwd = options.cwd ?? process.cwd();\n const agentDir = options.agentDir ?? getDefaultAgentDir();\n let resourceLoader = options.resourceLoader;\n\n // Use provided or create AuthStorage and ModelRegistry\n const authPath = options.agentDir ? join(agentDir, \"auth.json\") : undefined;\n const modelsPath = options.agentDir ? join(agentDir, \"models.json\") : undefined;\n const authStorage = options.authStorage ?? AuthStorage.create(authPath);\n const modelRegistry = options.modelRegistry ?? new ModelRegistry(authStorage, modelsPath);\n\n const settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n const sessionManager = options.sessionManager ?? SessionManager.create(cwd);\n\n if (!resourceLoader) {\n resourceLoader = new DefaultResourceLoader({ cwd, agentDir, settingsManager });\n await resourceLoader.reload();\n time(\"resourceLoader.reload\");\n }\n\n // Check if session has existing data to restore\n const existingSession = sessionManager.buildSessionContext();\n const hasExistingSession = existingSession.messages.length > 0;\n const hasThinkingEntry = sessionManager.getBranch().some((entry) => entry.type === \"thinking_level_change\");\n\n let model = options.model;\n let modelFallbackMessage: string | undefined;\n\n // If session has data, try to restore model from it.\n //\n // Do NOT gate restoration on API key resolution here. Providers using\n // external CLIs (or temporarily expired OAuth credentials) may not return\n // a key at startup even though the model is still the correct user choice.\n // In those cases we should preserve the last used model and surface auth\n // errors only when a request is actually made.\n if (!model && hasExistingSession && existingSession.model) {\n const restoredModel = modelRegistry.find(existingSession.model.provider, existingSession.model.modelId);\n if (restoredModel) {\n model = restoredModel;\n }\n if (!model) {\n modelFallbackMessage = `Could not restore model ${existingSession.model.provider}/${existingSession.model.modelId}`;\n }\n }\n\n // If still no model, use findInitialModel (checks settings default, then provider defaults)\n if (!model) {\n const result = await findInitialModel({\n scopedModels: [],\n isContinuing: hasExistingSession,\n defaultProvider: settingsManager.getDefaultProvider(),\n defaultModelId: settingsManager.getDefaultModel(),\n defaultThinkingLevel: settingsManager.getDefaultThinkingLevel(),\n modelRegistry,\n });\n model = result.model;\n if (!model) {\n modelFallbackMessage = `No models available. Use /login or set an API key environment variable. See ${join(getDocsPath(), \"providers.md\")}. Then use /model to select a model.`;\n } else if (modelFallbackMessage) {\n modelFallbackMessage += `. Using ${model.provider}/${model.id}`;\n }\n }\n\n let thinkingLevel = options.thinkingLevel;\n\n // If session has data, restore thinking level from it\n if (thinkingLevel === undefined && hasExistingSession) {\n thinkingLevel = hasThinkingEntry\n ? (existingSession.thinkingLevel as ThinkingLevel)\n : (settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL);\n }\n\n // Fall back to settings default\n if (thinkingLevel === undefined) {\n thinkingLevel = settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL;\n }\n\n const preferAdaptiveByDefault = shouldPreferAdaptiveThinkingByDefault(model, settingsManager);\n if (preferAdaptiveByDefault) {\n thinkingLevel = \"adaptive\";\n }\n\n // Clamp to model capabilities\n if (!model || !model.reasoning) {\n thinkingLevel = \"off\";\n }\n\n const editMode = settingsManager.getEditMode();\n const toolProfile = settingsManager.getToolProfile();\n const balancedToolNames = editMode === \"hashline\"\n ? [\"hashline_read\", \"bash\", \"hashline_edit\", \"write\", \"lsp\", \"bg_shell\", \"tool_search\", \"tool_enable\", \"Skill\", \"subagent\", \"await_subagent\", \"ask_user_questions\"]\n : [\"read\", \"bash\", \"edit\", \"write\", \"lsp\", \"bg_shell\", \"tool_search\", \"tool_enable\", \"Skill\", \"subagent\", \"await_subagent\", \"ask_user_questions\"];\n const defaultActiveToolNames: string[] = toolProfile === \"full\"\n ? Object.keys(allTools)\n : balancedToolNames;\n const initialActiveToolNames: string[] = options.tools\n ? options.tools.map((t) => t.name).filter((n): n is string => typeof n === \"string\" && n in allTools)\n : defaultActiveToolNames;\n\n let agent: Agent;\n\n // Create convertToLlm wrapper that filters images if blockImages is enabled (defense-in-depth)\n const convertToLlmWithBlockImages = (messages: AgentMessage[]): Message[] => {\n const converted = convertToLlm(messages);\n // Check setting dynamically so mid-session changes take effect\n if (!settingsManager.getBlockImages()) {\n return converted;\n }\n // Filter out ImageContent from all messages, replacing with text placeholder\n return converted.map((msg) => {\n if (msg.role === \"user\" || msg.role === \"toolResult\") {\n const content = msg.content;\n if (Array.isArray(content)) {\n const hasImages = content.some((c) => c.type === \"image\");\n if (hasImages) {\n const filteredContent = content\n .map((c) =>\n c.type === \"image\" ? { type: \"text\" as const, text: \"Image reading is disabled.\" } : c,\n )\n .filter(\n (c, i, arr) =>\n // Dedupe consecutive \"Image reading is disabled.\" texts\n !(\n c.type === \"text\" &&\n c.text === \"Image reading is disabled.\" &&\n i > 0 &&\n arr[i - 1].type === \"text\" &&\n (arr[i - 1] as { type: \"text\"; text: string }).text === \"Image reading is disabled.\"\n ),\n );\n return { ...msg, content: filteredContent };\n }\n }\n }\n return msg;\n });\n };\n\n const extensionRunnerRef: { current?: ExtensionRunner } = {};\n\n agent = new Agent({\n initialState: {\n systemPrompt: \"\",\n model,\n thinkingLevel,\n tools: [],\n },\n convertToLlm: convertToLlmWithBlockImages,\n onPayload: async (payload, currentModel) => {\n const runner = extensionRunnerRef.current;\n if (!runner?.hasHandlers(\"before_provider_request\")) {\n return payload;\n }\n return runner.emitBeforeProviderRequest(payload, currentModel);\n },\n sessionId: sessionManager.getSessionId(),\n transformContext: async (messages) => {\n const runner = extensionRunnerRef.current;\n if (!runner) return messages;\n return runner.emitContext(messages);\n },\n steeringMode: settingsManager.getSteeringMode(),\n followUpMode: settingsManager.getFollowUpMode(),\n transport: settingsManager.getTransport(),\n thinkingBudgets: settingsManager.getThinkingBudgets(),\n maxRetryDelayMs: settingsManager.getRetrySettings().maxDelayMs,\n externalToolExecution: (m) => modelRegistry.getProviderAuthMode(m.provider) === \"externalCli\",\n getApiKey: async (provider) => {\n // Use the provider argument from the in-flight request;\n // agent.state.model may already be switched mid-turn.\n const resolvedProvider = provider || agent.state.model?.provider;\n if (!resolvedProvider) {\n throw new Error(\"No model selected\");\n }\n const authMode = modelRegistry.getProviderAuthMode(resolvedProvider);\n if (authMode === \"externalCli\" || authMode === \"none\") {\n return undefined;\n }\n\n // Retry key resolution with backoff to handle transient network failures\n // (e.g., OAuth token refresh failing due to brief connectivity loss).\n const maxAttempts = 3;\n const baseDelayMs = 2000;\n const sid = sessionManager.getSessionId();\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n const key = await modelRegistry.getApiKeyForProvider(resolvedProvider, sid);\n if (key) return key;\n\n // On the last attempt, fall through to error handling below\n if (attempt >= maxAttempts) break;\n\n // Only retry if credentials exist (network issue) — no point retrying\n // when there are genuinely no credentials configured.\n const hasAuth = modelRegistry.authStorage.hasAuth(resolvedProvider);\n const model = agent.state.model;\n const isOAuth = model && modelRegistry.isUsingOAuth(model);\n if (!hasAuth && !isOAuth) break;\n\n // Wait with exponential backoff before retrying\n await new Promise(resolve => setTimeout(resolve, baseDelayMs * attempt));\n }\n\n // All retries exhausted — throw descriptive error\n // Check if credentials exist but are temporarily backed off\n // (e.g., after a 429 quota exhaustion). Provide a specific error\n // so the retry handler knows this is transient, not a permanent\n // auth failure.\n const hasAuth = modelRegistry.authStorage.hasAuth(resolvedProvider);\n if (hasAuth) {\n throw new Error(\n `All credentials for \"${resolvedProvider}\" are temporarily backed off due to rate limiting. ` +\n `The request will be retried automatically when backoff expires.`,\n );\n }\n const model = agent.state.model;\n const isOAuth = model && modelRegistry.isUsingOAuth(model);\n if (isOAuth) {\n // If credentials exist but are all in a backoff window (quota / rate-limit),\n // surface a specific message instead of the misleading \"Authentication failed\".\n if (modelRegistry.authStorage.areAllCredentialsBackedOff(resolvedProvider)) {\n throw new Error(\n `Rate limit in effect for \"${resolvedProvider}\". ` +\n `Please wait before retrying or switch to a different model.`,\n );\n }\n throw new Error(\n `Authentication failed for \"${resolvedProvider}\". ` +\n `Credentials may have expired or network is unavailable. ` +\n `Run '/login ${resolvedProvider}' to re-authenticate.`,\n );\n }\n throw new Error(\n `No API key found for \"${resolvedProvider}\". ` +\n `Set an API key environment variable or run '/login ${resolvedProvider}'.`,\n );\n },\n });\n\n // Restore messages if session has existing data\n if (hasExistingSession) {\n agent.replaceMessages(existingSession.messages);\n if (!hasThinkingEntry) {\n sessionManager.appendThinkingLevelChange(thinkingLevel);\n }\n } else {\n // Save initial model and thinking level for new sessions so they can be restored on resume\n if (model) {\n sessionManager.appendModelChange(model.provider, model.id);\n }\n sessionManager.appendThinkingLevelChange(thinkingLevel);\n }\n\n const session = new AgentSession({\n agent,\n sessionManager,\n settingsManager,\n cwd,\n scopedModels: options.scopedModels,\n resourceLoader,\n customTools: options.customTools,\n modelRegistry,\n initialActiveToolNames,\n extensionRunnerRef,\n sandboxManager: new SandboxManager(settingsManager),\n });\n const extensionsResult = resourceLoader.getExtensions();\n\n return {\n session,\n extensionsResult,\n modelFallbackMessage,\n };\n}\n"]}
1
+ {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/core/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAyC,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,wBAAwB,EAA4B,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EACH,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EAChB,yBAAyB,EACzB,sBAAsB,EACtB,sB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;IAEH,gDAAgD;IAChD,IAAI,kBAAkB,EAAE,CAAC;QACrB,KAAK,CAAC,eAAe,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACpB,cAAc,CAAC,yBAAyB,CAAC,aAAa,CAAC,CAAC;QAC5D,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,2FAA2F;QAC3F,IAAI,KAAK,EAAE,CAAC;YACR,cAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC;QAC/D,CAAC;QACD,cAAc,CAAC,yBAAyB,CAAC,aAAa,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC;QAC7B,KAAK;QACL,cAAc;QACd,eAAe;QACf,GAAG;QACH,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,cAAc;QACd,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,aAAa;QACb,sBAAsB;QACtB,kBAAkB;QAClB,cAAc,EAAE,IAAI,cAAc,CAAC,eAAe,CAAC;KACtD,CAAC,CAAC;IACH,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,EAAE,CAAC;IAExD,OAAO;QACH,OAAO;QACP,gBAAgB;QAChB,oBAAoB;KACvB,CAAC;AACN,CAAC","sourcesContent":["import { join } from \"node:path\";\nimport { Agent, type AgentMessage, type ThinkingLevel } from \"@gsd/pi-agent-core\";\nimport { supportsAdaptiveThinking, type Message, type Model } from \"@gsd/pi-ai\";\nimport { getAgentDir, getDocsPath } from \"../config.js\";\nimport { AgentSession } from \"./agent-session.js\";\nimport { AuthStorage } from \"./auth-storage.js\";\nimport { DEFAULT_THINKING_LEVEL } from \"./defaults.js\";\nimport type { ExtensionRunner, LoadExtensionsResult, ToolDefinition } from \"./extensions/index.js\";\nimport { convertToLlm } from \"./messages.js\";\nimport { ModelRegistry } from \"./model-registry.js\";\nimport { findInitialModel } from \"./model-resolver.js\";\nimport type { ResourceLoader } from \"./resource-loader.js\";\nimport { DefaultResourceLoader } from \"./resource-loader.js\";\nimport { SessionManager } from \"./session-manager.js\";\nimport { SettingsManager } from \"./settings-manager.js\";\nimport { time } from \"./timings.js\";\nimport { SandboxManager } from \"./sandbox/index.js\";\nimport {\n allTools,\n bashTool,\n codingTools,\n createBashTool,\n createCodingTools,\n createEditTool,\n createFindTool,\n createGrepTool,\n createLsTool,\n createReadOnlyTools,\n createReadTool,\n createWriteTool,\n editTool,\n findTool,\n grepTool,\n hashlineCodingTools,\n hashlineEditTool,\n hashlineReadTool,\n createHashlineCodingTools,\n createHashlineEditTool,\n createHashlineReadTool,\n lsTool,\n readOnlyTools,\n readTool,\n type Tool,\n writeTool,\n} from \"./tools/index.js\";\n\nexport interface CreateAgentSessionOptions {\n /** Working directory for project-local discovery. Default: process.cwd() */\n cwd?: string;\n /** Global config directory. Default: ~/.pi/agent */\n agentDir?: string;\n\n /** Auth storage for credentials. Default: AuthStorage.create(agentDir/auth.json) */\n authStorage?: AuthStorage;\n /** Model registry. Default: new ModelRegistry(authStorage, agentDir/models.json) */\n modelRegistry?: ModelRegistry;\n\n /** Model to use. Default: from settings, else first available */\n model?: Model<any>;\n /** Thinking level. Default: from settings, else 'medium' (clamped to model capabilities) */\n thinkingLevel?: ThinkingLevel;\n /** Models available for cycling (Ctrl+P in interactive mode) */\n scopedModels?: Array<{ model: Model<any>; thinkingLevel?: ThinkingLevel }>;\n\n /** Built-in tools to use. Default: codingTools [read, bash, edit, write] */\n tools?: Tool[];\n /** Custom tools to register (in addition to built-in tools). */\n customTools?: ToolDefinition[];\n\n /** Resource loader. When omitted, DefaultResourceLoader is used. */\n resourceLoader?: ResourceLoader;\n\n /** Session manager. Default: SessionManager.create(cwd) */\n sessionManager?: SessionManager;\n\n /** Settings manager. Default: SettingsManager.create(cwd, agentDir) */\n settingsManager?: SettingsManager;\n}\n\n/** Result from createAgentSession */\nexport interface CreateAgentSessionResult {\n /** The created session */\n session: AgentSession;\n /** Extensions result (for UI context setup in interactive mode) */\n extensionsResult: LoadExtensionsResult;\n /** Warning if session was restored with a different model than saved */\n modelFallbackMessage?: string;\n}\n\n// Re-exports\n\nexport type {\n ExtensionAPI,\n ExtensionCommandContext,\n ExtensionContext,\n ExtensionFactory,\n SlashCommandInfo,\n SlashCommandLocation,\n SlashCommandSource,\n ToolDefinition,\n} from \"./extensions/index.js\";\nexport type { PromptTemplate } from \"./prompt-templates.js\";\nexport type { Skill } from \"./skills.js\";\nexport type { Tool } from \"./tools/index.js\";\n\nexport {\n // Pre-built tools (use process.cwd())\n readTool,\n bashTool,\n editTool,\n writeTool,\n grepTool,\n findTool,\n lsTool,\n codingTools,\n readOnlyTools,\n allTools as allBuiltInTools,\n // Tool factories (for custom cwd)\n createCodingTools,\n createReadOnlyTools,\n createReadTool,\n createBashTool,\n createEditTool,\n createWriteTool,\n createGrepTool,\n createFindTool,\n createLsTool,\n // Hashline edit mode\n hashlineCodingTools,\n hashlineEditTool,\n hashlineReadTool,\n createHashlineCodingTools,\n createHashlineEditTool,\n createHashlineReadTool,\n};\n\n// Helper Functions\n\nfunction getDefaultAgentDir(): string {\n return getAgentDir();\n}\n\nfunction shouldPreferAdaptiveThinkingByDefault(\n model: Model<any> | undefined,\n settingsManager: SettingsManager,\n): boolean {\n return !!model &&\n model.provider === \"anthropic\" &&\n model.reasoning === true &&\n settingsManager.getAnthropicAdaptiveByDefault() &&\n supportsAdaptiveThinking(model.id);\n}\n\n/**\n * Create an AgentSession with the specified options.\n *\n * @example\n * ```typescript\n * // Minimal - uses defaults\n * const { session } = await createAgentSession();\n *\n * // With explicit model\n * import { getModel } from '@gsd/pi-ai';\n * const { session } = await createAgentSession({\n * model: getModel('anthropic', 'claude-opus-4-5'),\n * thinkingLevel: 'high',\n * });\n *\n * // Continue previous session\n * const { session, modelFallbackMessage } = await createAgentSession({\n * continueSession: true,\n * });\n *\n * // Full control\n * const loader = new DefaultResourceLoader({\n * cwd: process.cwd(),\n * agentDir: getAgentDir(),\n * settingsManager: SettingsManager.create(),\n * });\n * await loader.reload();\n * const { session } = await createAgentSession({\n * model: myModel,\n * tools: [readTool, bashTool],\n * resourceLoader: loader,\n * sessionManager: SessionManager.inMemory(),\n * });\n * ```\n */\nexport async function createAgentSession(options: CreateAgentSessionOptions = {}): Promise<CreateAgentSessionResult> {\n const cwd = options.cwd ?? process.cwd();\n const agentDir = options.agentDir ?? getDefaultAgentDir();\n let resourceLoader = options.resourceLoader;\n\n // Use provided or create AuthStorage and ModelRegistry\n const authPath = options.agentDir ? join(agentDir, \"auth.json\") : undefined;\n const modelsPath = options.agentDir ? join(agentDir, \"models.json\") : undefined;\n const authStorage = options.authStorage ?? AuthStorage.create(authPath);\n const modelRegistry = options.modelRegistry ?? new ModelRegistry(authStorage, modelsPath);\n\n const settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n const sessionManager = options.sessionManager ?? SessionManager.create(cwd);\n\n if (!resourceLoader) {\n resourceLoader = new DefaultResourceLoader({ cwd, agentDir, settingsManager });\n await resourceLoader.reload();\n time(\"resourceLoader.reload\");\n }\n\n // Check if session has existing data to restore\n const existingSession = sessionManager.buildSessionContext();\n const hasExistingSession = existingSession.messages.length > 0;\n const hasThinkingEntry = sessionManager.getBranch().some((entry) => entry.type === \"thinking_level_change\");\n\n let model = options.model;\n let modelFallbackMessage: string | undefined;\n\n // If session has data, try to restore model from it.\n //\n // Do NOT gate restoration on API key resolution here. Providers using\n // external CLIs (or temporarily expired OAuth credentials) may not return\n // a key at startup even though the model is still the correct user choice.\n // In those cases we should preserve the last used model and surface auth\n // errors only when a request is actually made.\n if (!model && hasExistingSession && existingSession.model) {\n const restoredModel = modelRegistry.find(existingSession.model.provider, existingSession.model.modelId);\n if (restoredModel) {\n model = restoredModel;\n }\n if (!model) {\n modelFallbackMessage = `Could not restore model ${existingSession.model.provider}/${existingSession.model.modelId}`;\n }\n }\n\n // If still no model, use findInitialModel (checks settings default, then provider defaults)\n if (!model) {\n const result = await findInitialModel({\n scopedModels: [],\n isContinuing: hasExistingSession,\n defaultProvider: settingsManager.getDefaultProvider(),\n defaultModelId: settingsManager.getDefaultModel(),\n defaultThinkingLevel: settingsManager.getDefaultThinkingLevel(),\n modelRegistry,\n });\n model = result.model;\n if (!model) {\n modelFallbackMessage = `No models available. Use /login or set an API key environment variable. See ${join(getDocsPath(), \"providers.md\")}. Then use /model to select a model.`;\n } else if (modelFallbackMessage) {\n modelFallbackMessage += `. Using ${model.provider}/${model.id}`;\n }\n }\n\n let thinkingLevel = options.thinkingLevel;\n\n // If session has data, restore thinking level from it\n if (thinkingLevel === undefined && hasExistingSession) {\n thinkingLevel = hasThinkingEntry\n ? (existingSession.thinkingLevel as ThinkingLevel)\n : (settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL);\n }\n\n // Fall back to settings default\n if (thinkingLevel === undefined) {\n thinkingLevel = settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL;\n }\n\n const preferAdaptiveByDefault = shouldPreferAdaptiveThinkingByDefault(model, settingsManager);\n if (preferAdaptiveByDefault) {\n thinkingLevel = \"adaptive\";\n }\n\n // Clamp to model capabilities\n if (!model || !model.reasoning) {\n thinkingLevel = \"off\";\n }\n\n const editMode = settingsManager.getEditMode();\n const toolProfile = settingsManager.getToolProfile();\n const balancedToolNames = editMode === \"hashline\"\n ? [\"hashline_read\", \"bash\", \"hashline_edit\", \"write\", \"lsp\", \"bg_shell\", \"tool_search\", \"tool_enable\", \"Skill\", \"subagent\", \"await_subagent\", \"ask_user_questions\"]\n : [\"read\", \"bash\", \"edit\", \"write\", \"lsp\", \"bg_shell\", \"tool_search\", \"tool_enable\", \"Skill\", \"subagent\", \"await_subagent\", \"ask_user_questions\"];\n const defaultActiveToolNames: string[] = toolProfile === \"full\"\n ? []\n : balancedToolNames;\n const initialActiveToolNames: string[] = options.tools\n ? options.tools.map((t) => t.name).filter((n): n is string => typeof n === \"string\" && n in allTools)\n : defaultActiveToolNames;\n\n let agent: Agent;\n\n // Create convertToLlm wrapper that filters images if blockImages is enabled (defense-in-depth)\n const convertToLlmWithBlockImages = (messages: AgentMessage[]): Message[] => {\n const converted = convertToLlm(messages);\n // Check setting dynamically so mid-session changes take effect\n if (!settingsManager.getBlockImages()) {\n return converted;\n }\n // Filter out ImageContent from all messages, replacing with text placeholder\n return converted.map((msg) => {\n if (msg.role === \"user\" || msg.role === \"toolResult\") {\n const content = msg.content;\n if (Array.isArray(content)) {\n const hasImages = content.some((c) => c.type === \"image\");\n if (hasImages) {\n const filteredContent = content\n .map((c) =>\n c.type === \"image\" ? { type: \"text\" as const, text: \"Image reading is disabled.\" } : c,\n )\n .filter(\n (c, i, arr) =>\n // Dedupe consecutive \"Image reading is disabled.\" texts\n !(\n c.type === \"text\" &&\n c.text === \"Image reading is disabled.\" &&\n i > 0 &&\n arr[i - 1].type === \"text\" &&\n (arr[i - 1] as { type: \"text\"; text: string }).text === \"Image reading is disabled.\"\n ),\n );\n return { ...msg, content: filteredContent };\n }\n }\n }\n return msg;\n });\n };\n\n const extensionRunnerRef: { current?: ExtensionRunner } = {};\n\n agent = new Agent({\n initialState: {\n systemPrompt: \"\",\n model,\n thinkingLevel,\n tools: [],\n },\n convertToLlm: convertToLlmWithBlockImages,\n onPayload: async (payload, currentModel) => {\n const runner = extensionRunnerRef.current;\n if (!runner?.hasHandlers(\"before_provider_request\")) {\n return payload;\n }\n return runner.emitBeforeProviderRequest(payload, currentModel);\n },\n sessionId: sessionManager.getSessionId(),\n transformContext: async (messages) => {\n const runner = extensionRunnerRef.current;\n if (!runner) return messages;\n return runner.emitContext(messages);\n },\n steeringMode: settingsManager.getSteeringMode(),\n followUpMode: settingsManager.getFollowUpMode(),\n transport: settingsManager.getTransport(),\n thinkingBudgets: settingsManager.getThinkingBudgets(),\n maxRetryDelayMs: settingsManager.getRetrySettings().maxDelayMs,\n externalToolExecution: (m) => modelRegistry.getProviderAuthMode(m.provider) === \"externalCli\",\n getApiKey: async (provider) => {\n // Use the provider argument from the in-flight request;\n // agent.state.model may already be switched mid-turn.\n const resolvedProvider = provider || agent.state.model?.provider;\n if (!resolvedProvider) {\n throw new Error(\"No model selected\");\n }\n const authMode = modelRegistry.getProviderAuthMode(resolvedProvider);\n if (authMode === \"externalCli\" || authMode === \"none\") {\n return undefined;\n }\n\n // Retry key resolution with backoff to handle transient network failures\n // (e.g., OAuth token refresh failing due to brief connectivity loss).\n const maxAttempts = 3;\n const baseDelayMs = 2000;\n const sid = sessionManager.getSessionId();\n for (let attempt = 1; attempt <= maxAttempts; attempt++) {\n const key = await modelRegistry.getApiKeyForProvider(resolvedProvider, sid);\n if (key) return key;\n\n // On the last attempt, fall through to error handling below\n if (attempt >= maxAttempts) break;\n\n // Only retry if credentials exist (network issue) — no point retrying\n // when there are genuinely no credentials configured.\n const hasAuth = modelRegistry.authStorage.hasAuth(resolvedProvider);\n const model = agent.state.model;\n const isOAuth = model && modelRegistry.isUsingOAuth(model);\n if (!hasAuth && !isOAuth) break;\n\n // Wait with exponential backoff before retrying\n await new Promise(resolve => setTimeout(resolve, baseDelayMs * attempt));\n }\n\n // All retries exhausted — throw descriptive error\n // Check if credentials exist but are temporarily backed off\n // (e.g., after a 429 quota exhaustion). Provide a specific error\n // so the retry handler knows this is transient, not a permanent\n // auth failure.\n const hasAuth = modelRegistry.authStorage.hasAuth(resolvedProvider);\n if (hasAuth) {\n throw new Error(\n `All credentials for \"${resolvedProvider}\" are temporarily backed off due to rate limiting. ` +\n `The request will be retried automatically when backoff expires.`,\n );\n }\n const model = agent.state.model;\n const isOAuth = model && modelRegistry.isUsingOAuth(model);\n if (isOAuth) {\n // If credentials exist but are all in a backoff window (quota / rate-limit),\n // surface a specific message instead of the misleading \"Authentication failed\".\n if (modelRegistry.authStorage.areAllCredentialsBackedOff(resolvedProvider)) {\n throw new Error(\n `Rate limit in effect for \"${resolvedProvider}\". ` +\n `Please wait before retrying or switch to a different model.`,\n );\n }\n throw new Error(\n `Authentication failed for \"${resolvedProvider}\". ` +\n `Credentials may have expired or network is unavailable. ` +\n `Run '/login ${resolvedProvider}' to re-authenticate.`,\n );\n }\n throw new Error(\n `No API key found for \"${resolvedProvider}\". ` +\n `Set an API key environment variable or run '/login ${resolvedProvider}'.`,\n );\n },\n });\n\n // Restore messages if session has existing data\n if (hasExistingSession) {\n agent.replaceMessages(existingSession.messages);\n if (!hasThinkingEntry) {\n sessionManager.appendThinkingLevelChange(thinkingLevel);\n }\n } else {\n // Save initial model and thinking level for new sessions so they can be restored on resume\n if (model) {\n sessionManager.appendModelChange(model.provider, model.id);\n }\n sessionManager.appendThinkingLevelChange(thinkingLevel);\n }\n\n const session = new AgentSession({\n agent,\n sessionManager,\n settingsManager,\n cwd,\n scopedModels: options.scopedModels,\n resourceLoader,\n customTools: options.customTools,\n modelRegistry,\n initialActiveToolNames,\n extensionRunnerRef,\n sandboxManager: new SandboxManager(settingsManager),\n });\n const extensionsResult = resourceLoader.getExtensions();\n\n return {\n session,\n extensionsResult,\n modelFallbackMessage,\n };\n}\n"]}
@@ -57,6 +57,21 @@ describe("Skill tool", () => {
57
57
  const result = await tool.execute("call-1", { skill: "swift-testing" });
58
58
  assert.equal(result.content[0]?.type === "text" ? result.content[0].text : "", `<skill name="swift-testing" location="${skillPath}">\nReferences are relative to ${join(testDir, ".lsd", "skills", "swift-testing")}.\n\n# Swift Testing\nUse this skill.\n</skill>`);
59
59
  });
60
+ it("describes Skill as distinct from subagents", async () => {
61
+ const session = await createSession();
62
+ const tool = session.state.tools.find((entry) => entry.name === "Skill");
63
+ assert.ok(tool, "Skill tool should be registered");
64
+ assert.match(tool.description ?? "", /not for launching subagents like scout, worker, reviewer, or planner/i);
65
+ });
66
+ it("returns a helpful redirect when a known subagent name is passed to Skill", async () => {
67
+ const session = await createSession();
68
+ const tool = session.state.tools.find((entry) => entry.name === "Skill");
69
+ assert.ok(tool, "Skill tool should be registered");
70
+ const result = await tool.execute("call-subagent", { skill: "scout" });
71
+ const message = result.content[0]?.type === "text" ? result.content[0].text : "";
72
+ assert.match(message, /"scout" is an available subagent/i);
73
+ assert.match(message, /Use the subagent tool directly with \{ agent: "scout", task: "\.\.\." \}\./i);
74
+ });
60
75
  it("returns a helpful error for unknown skills", async () => {
61
76
  writeSkill(testDir, "swift-testing", "Use for Swift Testing assertions and verification patterns.");
62
77
  const session = await createSession();
@@ -1 +1 @@
1
- {"version":3,"file":"skill-tool.test.js","sourceRoot":"","sources":["../../src/core/skill-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,IAAI,OAAe,CAAC;AAEpB,SAAS,UAAU,CAClB,GAAW,EACX,IAAY,EACZ,WAAmB,EACnB,IAAI,GAAG,KAAK,IAAI,IAAI,EACpB,iBAAiB,GAAG,EAAE;IAEtB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IACnD,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AM,OAAO,GAAG,MAAM,aAAa,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAI,OAAwE,CAAC,mBAAmB,CAC7G,wBAAwB,CACxB,CAAC;QACF,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,wBAAwB,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uFAAuF,EAAE,KAAK,IAAI,EAAE;QACtG,UAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC;QACxE,MAAM,OAAO,GAAG,MAAM,aAAa,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAI,OAAwE,CAAC,mBAAmB,CAC7G,sBAAsB,CACtB,CAAC;QACF,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { mkdirSync, mkdtempSync, rmSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { afterEach, beforeEach, describe, it } from \"node:test\";\n\nimport { Agent } from \"@gsd/pi-agent-core\";\nimport { AuthStorage } from \"./auth-storage.js\";\nimport { AgentSession } from \"./agent-session.js\";\nimport { ModelRegistry } from \"./model-registry.js\";\nimport { DefaultResourceLoader } from \"./resource-loader.js\";\nimport { SessionManager } from \"./session-manager.js\";\nimport { SettingsManager } from \"./settings-manager.js\";\n\nlet testDir: string;\n\nfunction writeSkill(\n\tcwd: string,\n\tname: string,\n\tdescription: string,\n\tbody = `# ${name}\\n`,\n\tfrontmatterExtras = \"\",\n): string {\n\tconst skillDir = join(cwd, \".lsd\", \"skills\", name);\n\tmkdirSync(skillDir, { recursive: true });\n\tconst skillPath = join(skillDir, \"SKILL.md\");\n\twriteFileSync(\n\t\tskillPath,\n\t\t`---\\nname: ${name}\\ndescription: ${description}${frontmatterExtras ? `\\n${frontmatterExtras}` : \"\"}\\n---\\n\\n${body}`,\n\t);\n\treturn skillPath;\n}\n\ndescribe(\"Skill tool\", () => {\n\tbeforeEach(() => {\n\t\ttestDir = mkdtempSync(join(tmpdir(), \"skill-tool-test-\"));\n\t});\n\n\tafterEach(() => {\n\t\trmSync(testDir, { recursive: true, force: true });\n\t});\n\n\tasync function createSession() {\n\t\tconst agentDir = join(testDir, \"agent-home\");\n\t\tconst authStorage = AuthStorage.inMemory({});\n\t\tconst modelRegistry = new ModelRegistry(authStorage, join(agentDir, \"models.json\"));\n\t\tconst settingsManager = SettingsManager.inMemory();\n\t\tconst resourceLoader = new DefaultResourceLoader({\n\t\t\tcwd: testDir,\n\t\t\tagentDir,\n\t\t\tsettingsManager,\n\t\t\tadditionalSkillPaths: [join(testDir, \".lsd\", \"skills\")],\n\t\t\tnoExtensions: true,\n\t\t\tnoPromptTemplates: true,\n\t\t\tnoThemes: true,\n\t\t});\n\t\tawait resourceLoader.reload();\n\n\t\treturn new AgentSession({\n\t\t\tagent: new Agent(),\n\t\t\tsessionManager: SessionManager.inMemory(testDir),\n\t\t\tsettingsManager,\n\t\t\tcwd: testDir,\n\t\t\tresourceLoader,\n\t\t\tmodelRegistry,\n\t\t});\n\t}\n\n\tit(\"resolves a project-level skill to the exact skill block format\", async () => {\n\t\tconst skillPath = writeSkill(\n\t\t\ttestDir,\n\t\t\t\"swift-testing\",\n\t\t\t\"Use for Swift Testing assertions and verification patterns.\",\n\t\t\t\"# Swift Testing\\nUse this skill.\\n\",\n\t\t);\n\t\tconst session = await createSession();\n\n\t\tconst tool = session.state.tools.find((entry) => entry.name === \"Skill\");\n\t\tassert.ok(tool, \"Skill tool should be registered\");\n\n\t\tconst result = await tool.execute(\"call-1\", { skill: \"swift-testing\" });\n\t\tassert.equal(\n\t\t\tresult.content[0]?.type === \"text\" ? result.content[0].text : \"\",\n\t\t\t`<skill name=\"swift-testing\" location=\"${skillPath}\">\\nReferences are relative to ${join(testDir, \".lsd\", \"skills\", \"swift-testing\")}.\\n\\n# Swift Testing\\nUse this skill.\\n</skill>`,\n\t\t);\n\t});\n\n\tit(\"returns a helpful error for unknown skills\", async () => {\n\t\twriteSkill(testDir, \"swift-testing\", \"Use for Swift Testing assertions and verification patterns.\");\n\t\tconst session = await createSession();\n\t\tconst tool = session.state.tools.find((entry) => entry.name === \"Skill\");\n\t\tassert.ok(tool, \"Skill tool should be registered\");\n\n\t\tconst result = await tool.execute(\"call-2\", { skill: \"nonexistent\" });\n\t\tconst message = result.content[0]?.type === \"text\" ? result.content[0].text : \"\";\n\t\tassert.match(message, /^Skill \"nonexistent\" not found\\. Available skills: /);\n\t\tassert.match(message, /swift-testing/);\n\t});\n\n\tit(\"expands explicit /skill:name invocations\", async () => {\n\t\twriteSkill(\n\t\t\ttestDir,\n\t\t\t\"teams-plan\",\n\t\t\t\"Plan and build a feature.\",\n\t\t\t\"# Teams Plan\\nUse this skill.\\n\",\n\t\t\t\"user-invocable: true\",\n\t\t);\n\t\tconst session = await createSession();\n\t\tconst expanded = (session as unknown as { _expandSkillCommand: (text: string) => string })._expandSkillCommand(\n\t\t\t\"/skill:teams-plan build auth\",\n\t\t);\n\t\tassert.match(expanded, /<skill name=\"teams-plan\"/);\n\t\tassert.match(expanded, /build auth/);\n\t});\n\n\tit(\"does not expand bare /name aliases even when user-invocable is set\", async () => {\n\t\twriteSkill(\n\t\t\ttestDir,\n\t\t\t\"teams-plan\",\n\t\t\t\"Plan and build a feature.\",\n\t\t\t\"# Teams Plan\\nUse this skill.\\n\",\n\t\t\t\"user-invocable: true\",\n\t\t);\n\t\tconst session = await createSession();\n\t\tconst expanded = (session as unknown as { _expandSkillCommand: (text: string) => string })._expandSkillCommand(\n\t\t\t\"/teams-plan build auth\",\n\t\t);\n\t\tassert.equal(expanded, \"/teams-plan build auth\");\n\t});\n\n\tit(\"does not treat bare /name skill invocations as commands when no skill: prefix is used\", async () => {\n\t\twriteSkill(testDir, \"internal-skill\", \"Internal only.\", \"# Internal\\n\");\n\t\tconst session = await createSession();\n\t\tconst expanded = (session as unknown as { _expandSkillCommand: (text: string) => string })._expandSkillCommand(\n\t\t\t\"/internal-skill test\",\n\t\t);\n\t\tassert.equal(expanded, \"/internal-skill test\");\n\t});\n});\n"]}
1
+ {"version":3,"file":"skill-tool.test.js","sourceRoot":"","sources":["../../src/core/skill-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAEhE,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,IAAI,OAAe,CAAC;AAEpB,SAAS,UAAU,CAClB,GAAW,EACX,IAAY,EACZ,WAAmB,EACnB,IAAI,GAAG,KAAK,IAAI,IAAI,EACpB,iBAAiB,GAAG,EAAE;IAEtB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IACnD,SAAS,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,MAAM,SAAS,GAAG,IAAI,CA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AC,CAAC;IAClD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uFAAuF,EAAE,KAAK,IAAI,EAAE;QACtG,UAAU,CAAC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC;QACxE,MAAM,OAAO,GAAG,MAAM,aAAa,EAAE,CAAC;QACtC,MAAM,QAAQ,GAAI,OAAwE,CAAC,mBAAmB,CAC7G,sBAAsB,CACtB,CAAC;QACF,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import assert from \"node:assert/strict\";\nimport { mkdirSync, mkdtempSync, rmSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { afterEach, beforeEach, describe, it } from \"node:test\";\n\nimport { Agent } from \"@gsd/pi-agent-core\";\nimport { AuthStorage } from \"./auth-storage.js\";\nimport { AgentSession } from \"./agent-session.js\";\nimport { ModelRegistry } from \"./model-registry.js\";\nimport { DefaultResourceLoader } from \"./resource-loader.js\";\nimport { SessionManager } from \"./session-manager.js\";\nimport { SettingsManager } from \"./settings-manager.js\";\n\nlet testDir: string;\n\nfunction writeSkill(\n\tcwd: string,\n\tname: string,\n\tdescription: string,\n\tbody = `# ${name}\\n`,\n\tfrontmatterExtras = \"\",\n): string {\n\tconst skillDir = join(cwd, \".lsd\", \"skills\", name);\n\tmkdirSync(skillDir, { recursive: true });\n\tconst skillPath = join(skillDir, \"SKILL.md\");\n\twriteFileSync(\n\t\tskillPath,\n\t\t`---\\nname: ${name}\\ndescription: ${description}${frontmatterExtras ? `\\n${frontmatterExtras}` : \"\"}\\n---\\n\\n${body}`,\n\t);\n\treturn skillPath;\n}\n\ndescribe(\"Skill tool\", () => {\n\tbeforeEach(() => {\n\t\ttestDir = mkdtempSync(join(tmpdir(), \"skill-tool-test-\"));\n\t});\n\n\tafterEach(() => {\n\t\trmSync(testDir, { recursive: true, force: true });\n\t});\n\n\tasync function createSession() {\n\t\tconst agentDir = join(testDir, \"agent-home\");\n\t\tconst authStorage = AuthStorage.inMemory({});\n\t\tconst modelRegistry = new ModelRegistry(authStorage, join(agentDir, \"models.json\"));\n\t\tconst settingsManager = SettingsManager.inMemory();\n\t\tconst resourceLoader = new DefaultResourceLoader({\n\t\t\tcwd: testDir,\n\t\t\tagentDir,\n\t\t\tsettingsManager,\n\t\t\tadditionalSkillPaths: [join(testDir, \".lsd\", \"skills\")],\n\t\t\tnoExtensions: true,\n\t\t\tnoPromptTemplates: true,\n\t\t\tnoThemes: true,\n\t\t});\n\t\tawait resourceLoader.reload();\n\n\t\treturn new AgentSession({\n\t\t\tagent: new Agent(),\n\t\t\tsessionManager: SessionManager.inMemory(testDir),\n\t\t\tsettingsManager,\n\t\t\tcwd: testDir,\n\t\t\tresourceLoader,\n\t\t\tmodelRegistry,\n\t\t});\n\t}\n\n\tit(\"resolves a project-level skill to the exact skill block format\", async () => {\n\t\tconst skillPath = writeSkill(\n\t\t\ttestDir,\n\t\t\t\"swift-testing\",\n\t\t\t\"Use for Swift Testing assertions and verification patterns.\",\n\t\t\t\"# Swift Testing\\nUse this skill.\\n\",\n\t\t);\n\t\tconst session = await createSession();\n\n\t\tconst tool = session.state.tools.find((entry) => entry.name === \"Skill\");\n\t\tassert.ok(tool, \"Skill tool should be registered\");\n\n\t\tconst result = await tool.execute(\"call-1\", { skill: \"swift-testing\" });\n\t\tassert.equal(\n\t\t\tresult.content[0]?.type === \"text\" ? result.content[0].text : \"\",\n\t\t\t`<skill name=\"swift-testing\" location=\"${skillPath}\">\\nReferences are relative to ${join(testDir, \".lsd\", \"skills\", \"swift-testing\")}.\\n\\n# Swift Testing\\nUse this skill.\\n</skill>`,\n\t\t);\n\t});\n\n\tit(\"describes Skill as distinct from subagents\", async () => {\n\t\tconst session = await createSession();\n\t\tconst tool = session.state.tools.find((entry) => entry.name === \"Skill\");\n\t\tassert.ok(tool, \"Skill tool should be registered\");\n\t\tassert.match(tool.description ?? \"\", /not for launching subagents like scout, worker, reviewer, or planner/i);\n\t});\n\n\tit(\"returns a helpful redirect when a known subagent name is passed to Skill\", async () => {\n\t\tconst session = await createSession();\n\t\tconst tool = session.state.tools.find((entry) => entry.name === \"Skill\");\n\t\tassert.ok(tool, \"Skill tool should be registered\");\n\n\t\tconst result = await tool.execute(\"call-subagent\", { skill: \"scout\" });\n\t\tconst message = result.content[0]?.type === \"text\" ? result.content[0].text : \"\";\n\t\tassert.match(message, /\"scout\" is an available subagent/i);\n\t\tassert.match(message, /Use the subagent tool directly with \\{ agent: \"scout\", task: \"\\.\\.\\.\" \\}\\./i);\n\t});\n\n\tit(\"returns a helpful error for unknown skills\", async () => {\n\t\twriteSkill(testDir, \"swift-testing\", \"Use for Swift Testing assertions and verification patterns.\");\n\t\tconst session = await createSession();\n\t\tconst tool = session.state.tools.find((entry) => entry.name === \"Skill\");\n\t\tassert.ok(tool, \"Skill tool should be registered\");\n\n\t\tconst result = await tool.execute(\"call-2\", { skill: \"nonexistent\" });\n\t\tconst message = result.content[0]?.type === \"text\" ? result.content[0].text : \"\";\n\t\tassert.match(message, /^Skill \"nonexistent\" not found\\. Available skills: /);\n\t\tassert.match(message, /swift-testing/);\n\t});\n\n\tit(\"expands explicit /skill:name invocations\", async () => {\n\t\twriteSkill(\n\t\t\ttestDir,\n\t\t\t\"teams-plan\",\n\t\t\t\"Plan and build a feature.\",\n\t\t\t\"# Teams Plan\\nUse this skill.\\n\",\n\t\t\t\"user-invocable: true\",\n\t\t);\n\t\tconst session = await createSession();\n\t\tconst expanded = (session as unknown as { _expandSkillCommand: (text: string) => string })._expandSkillCommand(\n\t\t\t\"/skill:teams-plan build auth\",\n\t\t);\n\t\tassert.match(expanded, /<skill name=\"teams-plan\"/);\n\t\tassert.match(expanded, /build auth/);\n\t});\n\n\tit(\"does not expand bare /name aliases even when user-invocable is set\", async () => {\n\t\twriteSkill(\n\t\t\ttestDir,\n\t\t\t\"teams-plan\",\n\t\t\t\"Plan and build a feature.\",\n\t\t\t\"# Teams Plan\\nUse this skill.\\n\",\n\t\t\t\"user-invocable: true\",\n\t\t);\n\t\tconst session = await createSession();\n\t\tconst expanded = (session as unknown as { _expandSkillCommand: (text: string) => string })._expandSkillCommand(\n\t\t\t\"/teams-plan build auth\",\n\t\t);\n\t\tassert.equal(expanded, \"/teams-plan build auth\");\n\t});\n\n\tit(\"does not treat bare /name skill invocations as commands when no skill: prefix is used\", async () => {\n\t\twriteSkill(testDir, \"internal-skill\", \"Internal only.\", \"# Internal\\n\");\n\t\tconst session = await createSession();\n\t\tconst expanded = (session as unknown as { _expandSkillCommand: (text: string) => string })._expandSkillCommand(\n\t\t\t\"/internal-skill test\",\n\t\t);\n\t\tassert.equal(expanded, \"/internal-skill test\");\n\t});\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"skills.d.ts","sourceRoot":"","sources":["../../src/core/skills.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG3D;;GAEG;AACH,eAAO,MAAM,oBAAoB,QAA6C,CAAC;AAE/E;;GAEG;AACH,eAAO,MAAM,4BAA4B,QAAkB,CAAC;AAkE5D,MAAM,WAAW,gBAAgB;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,KAAK;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB,EAAE,OAAO,CAAC;IAChC,aAAa,EAAE,OAAO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M,GAAG,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,KAAK;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB,EAAE,OAAO,CAAC;IAChC,aAAa,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAChC,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,WAAW,EAAE,kBAAkB,EAAE,CAAC;CAClC;AAID,wBAAgB,eAAe,IAAI,KAAK,EAAE,CAEzC;AA+CD,MAAM,WAAW,wBAAwB;IACxC,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,gBAAgB,CAGrF;AAsID;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CA4B7D;AAWD,MAAM,WAAW,iBAAiB;IACjC,yEAAyE;IACzE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,qGAAqG;IACrG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,wDAAwD;IACxD,eAAe,CAAC,EAAE,OAAO,CAAC;CAC1B;AAeD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,gBAAgB,CAqH5E"}
@@ -240,6 +240,7 @@ export function formatSkillsForPrompt(skills) {
240
240
  const lines = [
241
241
  "\n\nThe following skills provide specialized instructions for specific tasks.",
242
242
  "Use the Skill tool with the exact skill name from <available_skills> when the task matches its description.",
243
+ "Use the Skill tool only for listed skills — not for launching subagents like scout, worker, reviewer, or planner.",
243
244
  "If the Skill tool reports an unknown skill, do not guess: use an exact name from <available_skills> or tell the user the skill is unavailable.",
244
245
  "When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.",
245
246
  "",
@@ -1 +1 @@
1
- {"version":3,"file":"skills.js","sourceRoot":"","sources":["../../src/core/skills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACnF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,eAAe,CAAC;AAE5D;;GAEG;AACH,MAAM,2BAA2B,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAEzE;;;GAGG;AACH,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAE9E,+BAA+B;AAC/B,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,sCAAsC;AACtC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAEpC,MAAM,iBAAiB,GAAG,CAAC,YA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S,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;gBACxE,CAAC;qBAAM,CAAC;oBACP,cAAc,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;gBAC5C,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,mCAAmC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;YAC5G,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,2BAA2B,CAAC;YACrF,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;QACvE,CAAC;IACF,CAAC;IAED,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAE7C,OAAO;QACN,MAAM,EAAE,CAAC,GAAG,YAAY,CAAC;QACzB,WAAW,EAAE,CAAC,GAAG,cAAc,EAAE,GAAG,oBAAoB,CAAC;KACzD,CAAC;AACH,CAAC","sourcesContent":["import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from \"fs\";\nimport ignore from \"ignore\";\nimport { homedir } from \"os\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"path\";\nimport { parseFrontmatter } from \"../utils/frontmatter.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport type { ResourceDiagnostic } from \"./diagnostics.js\";\nimport { CONFIG_DIR_NAME } from \"../config.js\";\n\n/**\n * Preferred global skills directory for LSD.\n */\nexport const ECOSYSTEM_SKILLS_DIR = join(homedir(), CONFIG_DIR_NAME, \"skills\");\n\n/**\n * Preferred project-level skills directory (`.lsd/skills/` relative to cwd).\n */\nexport const ECOSYSTEM_PROJECT_SKILLS_DIR = CONFIG_DIR_NAME;\n\n/**\n * Compatibility fallback: shared Agent Skills ecosystem directory.\n */\nconst COMPAT_ECOSYSTEM_SKILLS_DIR = join(homedir(), \".agents\", \"skills\");\n\n/**\n * Legacy skills directory (~/.lsd/agent/skills/ or ~/.pi/agent/skills/).\n * Read as a fallback so existing installs don't lose skills before migration runs.\n */\nconst LEGACY_SKILLS_DIR = join(homedir(), CONFIG_DIR_NAME, \"agent\", \"skills\");\n\n/** Max name length per spec */\nconst MAX_NAME_LENGTH = 64;\n\n/** Max description length per spec */\nconst MAX_DESCRIPTION_LENGTH = 1024;\n\nconst IGNORE_FILE_NAMES = [\".gitignore\", \".ignore\", \".fdignore\"];\n\ntype IgnoreMatcher = ReturnType<typeof ignore>;\n\nfunction prefixIgnorePattern(line: string, prefix: string): string | null {\n\tconst trimmed = line.trim();\n\tif (!trimmed) return null;\n\tif (trimmed.startsWith(\"#\") && !trimmed.startsWith(\"\\\\#\")) return null;\n\n\tlet pattern = line;\n\tlet negated = false;\n\n\tif (pattern.startsWith(\"!\")) {\n\t\tnegated = true;\n\t\tpattern = pattern.slice(1);\n\t} else if (pattern.startsWith(\"\\\\!\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\n\tif (pattern.startsWith(\"/\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\n\tconst prefixed = prefix ? `${prefix}${pattern}` : pattern;\n\treturn negated ? `!${prefixed}` : prefixed;\n}\n\nfunction addIgnoreRules(ig: IgnoreMatcher, dir: string, rootDir: string): void {\n\tconst relativeDir = relative(rootDir, dir);\n\tconst prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : \"\";\n\n\tfor (const filename of IGNORE_FILE_NAMES) {\n\t\tconst ignorePath = join(dir, filename);\n\t\tif (!existsSync(ignorePath)) continue;\n\t\ttry {\n\t\t\tconst content = readFileSync(ignorePath, \"utf-8\");\n\t\t\tconst patterns = content\n\t\t\t\t.split(/\\r?\\n/)\n\t\t\t\t.map((line) => prefixIgnorePattern(line, prefix))\n\t\t\t\t.filter((line): line is string => Boolean(line));\n\t\t\tif (patterns.length > 0) {\n\t\t\t\tig.add(patterns);\n\t\t\t}\n\t\t} catch {}\n\t}\n}\n\nexport interface SkillFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t\"disable-model-invocation\"?: boolean;\n\t\"user-invocable\"?: boolean;\n\t[key: string]: unknown;\n}\n\nexport interface Skill {\n\tname: string;\n\tdescription: string;\n\tfilePath: string;\n\tbaseDir: string;\n\tsource: string;\n\tdisableModelInvocation: boolean;\n\tuserInvocable: boolean;\n}\n\nexport interface LoadSkillsResult {\n\tskills: Skill[];\n\tdiagnostics: ResourceDiagnostic[];\n}\n\nlet loadedSkills: Skill[] = [];\n\nexport function getLoadedSkills(): Skill[] {\n\treturn [...loadedSkills];\n}\n\n/**\n * Validate skill name per Agent Skills spec.\n * Returns array of validation error messages (empty if valid).\n */\nfunction validateName(name: string, parentDirName: string): string[] {\n\tconst errors: string[] = [];\n\n\tif (name !== parentDirName) {\n\t\terrors.push(`name \"${name}\" does not match parent directory \"${parentDirName}\"`);\n\t}\n\n\tif (name.length > MAX_NAME_LENGTH) {\n\t\terrors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\t}\n\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(`name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)`);\n\t}\n\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) {\n\t\terrors.push(`name must not start or end with a hyphen`);\n\t}\n\n\tif (name.includes(\"--\")) {\n\t\terrors.push(`name must not contain consecutive hyphens`);\n\t}\n\n\treturn errors;\n}\n\n/**\n * Validate description per Agent Skills spec.\n */\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\n\treturn errors;\n}\n\nexport interface LoadSkillsFromDirOptions {\n\t/** Directory to scan for skills */\n\tdir: string;\n\t/** Source identifier for these skills */\n\tsource: string;\n}\n\n/**\n * Load skills from a directory.\n *\n * Discovery rules:\n * - direct .md children in the root\n * - recursive SKILL.md under subdirectories\n */\nexport function loadSkillsFromDir(options: LoadSkillsFromDirOptions): LoadSkillsResult {\n\tconst { dir, source } = options;\n\treturn loadSkillsFromDirInternal(dir, source, true);\n}\n\nfunction loadSkillsFromDirInternal(\n\tdir: string,\n\tsource: string,\n\tincludeRootFiles: boolean,\n\tignoreMatcher?: IgnoreMatcher,\n\trootDir?: string,\n): LoadSkillsResult {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\tif (!existsSync(dir)) {\n\t\treturn { skills, diagnostics };\n\t}\n\n\tconst root = rootDir ?? dir;\n\tconst ig = ignoreMatcher ?? ignore();\n\taddIgnoreRules(ig, dir, root);\n\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.name.startsWith(\".\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Skip node_modules to avoid scanning dependencies\n\t\t\tif (entry.name === \"node_modules\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst fullPath = join(dir, entry.name);\n\n\t\t\t// For symlinks, check if they point to a directory and follow them\n\t\t\tlet isDirectory = entry.isDirectory();\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisDirectory = stats.isDirectory();\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\t// Broken symlink, skip it\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst relPath = toPosixPath(relative(root, fullPath));\n\t\t\tconst ignorePath = isDirectory ? `${relPath}/` : relPath;\n\t\t\tif (ig.ignores(ignorePath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (isDirectory) {\n\t\t\t\tconst subResult = loadSkillsFromDirInternal(fullPath, source, false, ig, root);\n\t\t\t\tskills.push(...subResult.skills);\n\t\t\t\tdiagnostics.push(...subResult.diagnostics);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!isFile) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst isRootMd = includeRootFiles && entry.name.endsWith(\".md\");\n\t\t\tconst isSkillMd = !includeRootFiles && entry.name === \"SKILL.md\";\n\t\t\tif (!isRootMd && !isSkillMd) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst result = loadSkillFromFile(fullPath, source);\n\t\t\tif (result.skill) {\n\t\t\t\tskills.push(result.skill);\n\t\t\t}\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t}\n\t} catch {}\n\n\treturn { skills, diagnostics };\n}\n\nfunction loadSkillFromFile(\n\tfilePath: string,\n\tsource: string,\n): { skill: Skill | null; diagnostics: ResourceDiagnostic[] } {\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\ttry {\n\t\tconst rawContent = readFileSync(filePath, \"utf-8\");\n\t\tconst { frontmatter } = parseFrontmatter<SkillFrontmatter>(rawContent);\n\t\tconst skillDir = dirname(filePath);\n\t\tconst parentDirName = basename(skillDir);\n\n\t\t// Validate description\n\t\tconst descErrors = validateDescription(frontmatter.description);\n\t\tfor (const error of descErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\n\t\t// Use name from frontmatter, or fall back to parent directory name\n\t\tconst name = frontmatter.name || parentDirName;\n\n\t\t// Validate name\n\t\tconst nameErrors = validateName(name, parentDirName);\n\t\tfor (const error of nameErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\n\t\t// Still load the skill even with warnings (unless description is completely missing)\n\t\tif (!frontmatter.description || frontmatter.description.trim() === \"\") {\n\t\t\treturn { skill: null, diagnostics };\n\t\t}\n\n\t\treturn {\n\t\t\tskill: {\n\t\t\t\tname,\n\t\t\t\tdescription: frontmatter.description,\n\t\t\t\tfilePath,\n\t\t\t\tbaseDir: skillDir,\n\t\t\t\tsource,\n\t\t\t\tdisableModelInvocation: frontmatter[\"disable-model-invocation\"] === true,\n\t\t\t\tuserInvocable: frontmatter[\"user-invocable\"] === true,\n\t\t\t},\n\t\t\tdiagnostics,\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to parse skill file\";\n\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\treturn { skill: null, diagnostics };\n\t}\n}\n\n/**\n * Format skills for inclusion in a system prompt.\n * Uses XML format per Agent Skills standard.\n * See: https://agentskills.io/integrate-skills\n *\n * Skills with disableModelInvocation=true are excluded from the prompt\n * (they can only be invoked explicitly via /skill:name commands).\n */\nexport function formatSkillsForPrompt(skills: Skill[]): string {\n\tconst visibleSkills = skills.filter((s) => !s.disableModelInvocation);\n\n\tif (visibleSkills.length === 0) {\n\t\treturn \"\";\n\t}\n\n\tconst lines = [\n\t\t\"\\n\\nThe following skills provide specialized instructions for specific tasks.\",\n\t\t\"Use the Skill tool with the exact skill name from <available_skills> when the task matches its description.\",\n\t\t\"If the Skill tool reports an unknown skill, do not guess: use an exact name from <available_skills> or tell the user the skill is unavailable.\",\n\t\t\"When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.\",\n\t\t\"\",\n\t\t\"<available_skills>\",\n\t];\n\n\tfor (const skill of visibleSkills) {\n\t\tlines.push(\" <skill>\");\n\t\tlines.push(` <name>${escapeXml(skill.name)}</name>`);\n\t\tlines.push(` <description>${escapeXml(skill.description)}</description>`);\n\t\tlines.push(` <location>${escapeXml(skill.filePath)}</location>`);\n\t\tlines.push(\" </skill>\");\n\t}\n\n\tlines.push(\"</available_skills>\");\n\n\treturn lines.join(\"\\n\");\n}\n\nfunction escapeXml(str: string): string {\n\treturn str\n\t\t.replace(/&/g, \"&amp;\")\n\t\t.replace(/</g, \"&lt;\")\n\t\t.replace(/>/g, \"&gt;\")\n\t\t.replace(/\"/g, \"&quot;\")\n\t\t.replace(/'/g, \"&apos;\");\n}\n\nexport interface LoadSkillsOptions {\n\t/** Working directory for project-local skills. Default: process.cwd() */\n\tcwd?: string;\n\t/** @deprecated Retained for compatibility. Default skill discovery no longer depends on agentDir. */\n\tagentDir?: string;\n\t/** Explicit skill paths (files or directories) */\n\tskillPaths?: string[];\n\t/** Include default skills directories. Default: true */\n\tincludeDefaults?: boolean;\n}\n\nfunction normalizePath(input: string): string {\n\tconst trimmed = input.trim();\n\tif (trimmed === \"~\") return homedir();\n\tif (trimmed.startsWith(\"~/\")) return join(homedir(), trimmed.slice(2));\n\tif (trimmed.startsWith(\"~\")) return join(homedir(), trimmed.slice(1));\n\treturn trimmed;\n}\n\nfunction resolveSkillPath(p: string, cwd: string): string {\n\tconst normalized = normalizePath(p);\n\treturn isAbsolute(normalized) ? normalized : resolve(cwd, normalized);\n}\n\n/**\n * Load skills from all configured locations.\n * Returns skills and any validation diagnostics.\n */\nexport function loadSkills(options: LoadSkillsOptions = {}): LoadSkillsResult {\n\tconst { cwd = process.cwd(), skillPaths = [], includeDefaults = true } = options;\n\n\tconst skillMap = new Map<string, Skill>();\n\tconst realPathSet = new Set<string>();\n\tconst allDiagnostics: ResourceDiagnostic[] = [];\n\tconst collisionDiagnostics: ResourceDiagnostic[] = [];\n\n\tfunction addSkills(result: LoadSkillsResult) {\n\t\tallDiagnostics.push(...result.diagnostics);\n\t\tfor (const skill of result.skills) {\n\t\t\t// Resolve symlinks to detect duplicate files\n\t\t\tlet realPath: string;\n\t\t\ttry {\n\t\t\t\trealPath = realpathSync(skill.filePath);\n\t\t\t} catch {\n\t\t\t\trealPath = skill.filePath;\n\t\t\t}\n\n\t\t\t// Skip silently if we've already loaded this exact file (via symlink)\n\t\t\tif (realPathSet.has(realPath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst existing = skillMap.get(skill.name);\n\t\t\tif (existing) {\n\t\t\t\tcollisionDiagnostics.push({\n\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\tmessage: `name \"${skill.name}\" collision`,\n\t\t\t\t\tpath: skill.filePath,\n\t\t\t\t\tcollision: {\n\t\t\t\t\t\tresourceType: \"skill\",\n\t\t\t\t\t\tname: skill.name,\n\t\t\t\t\t\twinnerPath: existing.filePath,\n\t\t\t\t\t\tloserPath: skill.filePath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tskillMap.set(skill.name, skill);\n\t\t\t\trealPathSet.add(realPath);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (includeDefaults) {\n\t\t// Preferred project-local location for LSD repos.\n\t\t// Load this first so project skills shadow user/global skills with the same name.\n\t\taddSkills(loadSkillsFromDirInternal(resolve(cwd, ECOSYSTEM_PROJECT_SKILLS_DIR, \"skills\"), \"project\", true));\n\t\t// Primary global location for LSD.\n\t\taddSkills(loadSkillsFromDirInternal(ECOSYSTEM_SKILLS_DIR, \"user\", true));\n\t\t// Compatibility fallback: shared Agent Skills ecosystem directory.\n\t\tif (COMPAT_ECOSYSTEM_SKILLS_DIR !== ECOSYSTEM_SKILLS_DIR) {\n\t\t\taddSkills(loadSkillsFromDirInternal(COMPAT_ECOSYSTEM_SKILLS_DIR, \"user\", true));\n\t\t}\n\n\t\t// Legacy fallback: read skills from ~/.lsd/agent/skills/ so existing\n\t\t// installs keep working until migration moves them to ~/.lsd/skills/.\n\t\tconst legacyMigrated = existsSync(join(LEGACY_SKILLS_DIR, \".migrated-to-lsd-skills\"));\n\t\tif (LEGACY_SKILLS_DIR !== ECOSYSTEM_SKILLS_DIR && existsSync(LEGACY_SKILLS_DIR) && !legacyMigrated) {\n\t\t\taddSkills(loadSkillsFromDirInternal(LEGACY_SKILLS_DIR, \"user\", true));\n\t\t}\n\t}\n\n\tconst userSkillsDir = ECOSYSTEM_SKILLS_DIR;\n\tconst projectSkillsDir = resolve(cwd, ECOSYSTEM_PROJECT_SKILLS_DIR, \"skills\");\n\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\n\tconst getSource = (resolvedPath: string): \"user\" | \"project\" | \"path\" => {\n\t\tif (!includeDefaults) {\n\t\t\tif (isUnderPath(resolvedPath, userSkillsDir)) return \"user\";\n\t\t\tif (isUnderPath(resolvedPath, projectSkillsDir)) return \"project\";\n\t\t}\n\t\treturn \"path\";\n\t};\n\n\tfor (const rawPath of skillPaths) {\n\t\tconst resolvedPath = resolveSkillPath(rawPath, cwd);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path does not exist\", path: resolvedPath });\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tconst stats = statSync(resolvedPath);\n\t\t\tconst source = getSource(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\taddSkills(loadSkillsFromDirInternal(resolvedPath, source, true));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst result = loadSkillFromFile(resolvedPath, source);\n\t\t\t\tif (result.skill) {\n\t\t\t\t\taddSkills({ skills: [result.skill], diagnostics: result.diagnostics });\n\t\t\t\t} else {\n\t\t\t\t\tallDiagnostics.push(...result.diagnostics);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path is not a markdown file\", path: resolvedPath });\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to read skill path\";\n\t\t\tallDiagnostics.push({ type: \"warning\", message, path: resolvedPath });\n\t\t}\n\t}\n\n\tloadedSkills = Array.from(skillMap.values());\n\n\treturn {\n\t\tskills: [...loadedSkills],\n\t\tdiagnostics: [...allDiagnostics, ...collisionDiagnostics],\n\t};\n}\n"]}
1
+ {"version":3,"file":"skills.js","sourceRoot":"","sources":["../../src/core/skills.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AACnF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,eAAe,EAAE,QAAQ,CAAC,CAAC;AAE/E;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,eAAe,CAAC;AAE5D;;GAEG;AACH,MAAM,2BAA2B,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAEzE;;;GAGG;AACH,MAAM,iBAAiB,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAE9E,+BAA+B;AAC/B,MAAM,eAA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gBAC3D,MAAM,MAAM,GAAG,iBAAiB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;gBACvD,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;oBAClB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;gBACxE,CAAC;qBAAM,CAAC;oBACP,cAAc,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;gBAC5C,CAAC;YACF,CAAC;iBAAM,CAAC;gBACP,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,mCAAmC,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;YAC5G,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,2BAA2B,CAAC;YACrF,cAAc,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;QACvE,CAAC;IACF,CAAC;IAED,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAE7C,OAAO;QACN,MAAM,EAAE,CAAC,GAAG,YAAY,CAAC;QACzB,WAAW,EAAE,CAAC,GAAG,cAAc,EAAE,GAAG,oBAAoB,CAAC;KACzD,CAAC;AACH,CAAC","sourcesContent":["import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from \"fs\";\nimport ignore from \"ignore\";\nimport { homedir } from \"os\";\nimport { basename, dirname, isAbsolute, join, relative, resolve, sep } from \"path\";\nimport { parseFrontmatter } from \"../utils/frontmatter.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport type { ResourceDiagnostic } from \"./diagnostics.js\";\nimport { CONFIG_DIR_NAME } from \"../config.js\";\n\n/**\n * Preferred global skills directory for LSD.\n */\nexport const ECOSYSTEM_SKILLS_DIR = join(homedir(), CONFIG_DIR_NAME, \"skills\");\n\n/**\n * Preferred project-level skills directory (`.lsd/skills/` relative to cwd).\n */\nexport const ECOSYSTEM_PROJECT_SKILLS_DIR = CONFIG_DIR_NAME;\n\n/**\n * Compatibility fallback: shared Agent Skills ecosystem directory.\n */\nconst COMPAT_ECOSYSTEM_SKILLS_DIR = join(homedir(), \".agents\", \"skills\");\n\n/**\n * Legacy skills directory (~/.lsd/agent/skills/ or ~/.pi/agent/skills/).\n * Read as a fallback so existing installs don't lose skills before migration runs.\n */\nconst LEGACY_SKILLS_DIR = join(homedir(), CONFIG_DIR_NAME, \"agent\", \"skills\");\n\n/** Max name length per spec */\nconst MAX_NAME_LENGTH = 64;\n\n/** Max description length per spec */\nconst MAX_DESCRIPTION_LENGTH = 1024;\n\nconst IGNORE_FILE_NAMES = [\".gitignore\", \".ignore\", \".fdignore\"];\n\ntype IgnoreMatcher = ReturnType<typeof ignore>;\n\nfunction prefixIgnorePattern(line: string, prefix: string): string | null {\n\tconst trimmed = line.trim();\n\tif (!trimmed) return null;\n\tif (trimmed.startsWith(\"#\") && !trimmed.startsWith(\"\\\\#\")) return null;\n\n\tlet pattern = line;\n\tlet negated = false;\n\n\tif (pattern.startsWith(\"!\")) {\n\t\tnegated = true;\n\t\tpattern = pattern.slice(1);\n\t} else if (pattern.startsWith(\"\\\\!\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\n\tif (pattern.startsWith(\"/\")) {\n\t\tpattern = pattern.slice(1);\n\t}\n\n\tconst prefixed = prefix ? `${prefix}${pattern}` : pattern;\n\treturn negated ? `!${prefixed}` : prefixed;\n}\n\nfunction addIgnoreRules(ig: IgnoreMatcher, dir: string, rootDir: string): void {\n\tconst relativeDir = relative(rootDir, dir);\n\tconst prefix = relativeDir ? `${toPosixPath(relativeDir)}/` : \"\";\n\n\tfor (const filename of IGNORE_FILE_NAMES) {\n\t\tconst ignorePath = join(dir, filename);\n\t\tif (!existsSync(ignorePath)) continue;\n\t\ttry {\n\t\t\tconst content = readFileSync(ignorePath, \"utf-8\");\n\t\t\tconst patterns = content\n\t\t\t\t.split(/\\r?\\n/)\n\t\t\t\t.map((line) => prefixIgnorePattern(line, prefix))\n\t\t\t\t.filter((line): line is string => Boolean(line));\n\t\t\tif (patterns.length > 0) {\n\t\t\t\tig.add(patterns);\n\t\t\t}\n\t\t} catch {}\n\t}\n}\n\nexport interface SkillFrontmatter {\n\tname?: string;\n\tdescription?: string;\n\t\"disable-model-invocation\"?: boolean;\n\t\"user-invocable\"?: boolean;\n\t[key: string]: unknown;\n}\n\nexport interface Skill {\n\tname: string;\n\tdescription: string;\n\tfilePath: string;\n\tbaseDir: string;\n\tsource: string;\n\tdisableModelInvocation: boolean;\n\tuserInvocable: boolean;\n}\n\nexport interface LoadSkillsResult {\n\tskills: Skill[];\n\tdiagnostics: ResourceDiagnostic[];\n}\n\nlet loadedSkills: Skill[] = [];\n\nexport function getLoadedSkills(): Skill[] {\n\treturn [...loadedSkills];\n}\n\n/**\n * Validate skill name per Agent Skills spec.\n * Returns array of validation error messages (empty if valid).\n */\nfunction validateName(name: string, parentDirName: string): string[] {\n\tconst errors: string[] = [];\n\n\tif (name !== parentDirName) {\n\t\terrors.push(`name \"${name}\" does not match parent directory \"${parentDirName}\"`);\n\t}\n\n\tif (name.length > MAX_NAME_LENGTH) {\n\t\terrors.push(`name exceeds ${MAX_NAME_LENGTH} characters (${name.length})`);\n\t}\n\n\tif (!/^[a-z0-9-]+$/.test(name)) {\n\t\terrors.push(`name contains invalid characters (must be lowercase a-z, 0-9, hyphens only)`);\n\t}\n\n\tif (name.startsWith(\"-\") || name.endsWith(\"-\")) {\n\t\terrors.push(`name must not start or end with a hyphen`);\n\t}\n\n\tif (name.includes(\"--\")) {\n\t\terrors.push(`name must not contain consecutive hyphens`);\n\t}\n\n\treturn errors;\n}\n\n/**\n * Validate description per Agent Skills spec.\n */\nfunction validateDescription(description: string | undefined): string[] {\n\tconst errors: string[] = [];\n\n\tif (!description || description.trim() === \"\") {\n\t\terrors.push(\"description is required\");\n\t} else if (description.length > MAX_DESCRIPTION_LENGTH) {\n\t\terrors.push(`description exceeds ${MAX_DESCRIPTION_LENGTH} characters (${description.length})`);\n\t}\n\n\treturn errors;\n}\n\nexport interface LoadSkillsFromDirOptions {\n\t/** Directory to scan for skills */\n\tdir: string;\n\t/** Source identifier for these skills */\n\tsource: string;\n}\n\n/**\n * Load skills from a directory.\n *\n * Discovery rules:\n * - direct .md children in the root\n * - recursive SKILL.md under subdirectories\n */\nexport function loadSkillsFromDir(options: LoadSkillsFromDirOptions): LoadSkillsResult {\n\tconst { dir, source } = options;\n\treturn loadSkillsFromDirInternal(dir, source, true);\n}\n\nfunction loadSkillsFromDirInternal(\n\tdir: string,\n\tsource: string,\n\tincludeRootFiles: boolean,\n\tignoreMatcher?: IgnoreMatcher,\n\trootDir?: string,\n): LoadSkillsResult {\n\tconst skills: Skill[] = [];\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\tif (!existsSync(dir)) {\n\t\treturn { skills, diagnostics };\n\t}\n\n\tconst root = rootDir ?? dir;\n\tconst ig = ignoreMatcher ?? ignore();\n\taddIgnoreRules(ig, dir, root);\n\n\ttry {\n\t\tconst entries = readdirSync(dir, { withFileTypes: true });\n\n\t\tfor (const entry of entries) {\n\t\t\tif (entry.name.startsWith(\".\")) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Skip node_modules to avoid scanning dependencies\n\t\t\tif (entry.name === \"node_modules\") {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst fullPath = join(dir, entry.name);\n\n\t\t\t// For symlinks, check if they point to a directory and follow them\n\t\t\tlet isDirectory = entry.isDirectory();\n\t\t\tlet isFile = entry.isFile();\n\t\t\tif (entry.isSymbolicLink()) {\n\t\t\t\ttry {\n\t\t\t\t\tconst stats = statSync(fullPath);\n\t\t\t\t\tisDirectory = stats.isDirectory();\n\t\t\t\t\tisFile = stats.isFile();\n\t\t\t\t} catch {\n\t\t\t\t\t// Broken symlink, skip it\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst relPath = toPosixPath(relative(root, fullPath));\n\t\t\tconst ignorePath = isDirectory ? `${relPath}/` : relPath;\n\t\t\tif (ig.ignores(ignorePath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (isDirectory) {\n\t\t\t\tconst subResult = loadSkillsFromDirInternal(fullPath, source, false, ig, root);\n\t\t\t\tskills.push(...subResult.skills);\n\t\t\t\tdiagnostics.push(...subResult.diagnostics);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (!isFile) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst isRootMd = includeRootFiles && entry.name.endsWith(\".md\");\n\t\t\tconst isSkillMd = !includeRootFiles && entry.name === \"SKILL.md\";\n\t\t\tif (!isRootMd && !isSkillMd) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst result = loadSkillFromFile(fullPath, source);\n\t\t\tif (result.skill) {\n\t\t\t\tskills.push(result.skill);\n\t\t\t}\n\t\t\tdiagnostics.push(...result.diagnostics);\n\t\t}\n\t} catch {}\n\n\treturn { skills, diagnostics };\n}\n\nfunction loadSkillFromFile(\n\tfilePath: string,\n\tsource: string,\n): { skill: Skill | null; diagnostics: ResourceDiagnostic[] } {\n\tconst diagnostics: ResourceDiagnostic[] = [];\n\n\ttry {\n\t\tconst rawContent = readFileSync(filePath, \"utf-8\");\n\t\tconst { frontmatter } = parseFrontmatter<SkillFrontmatter>(rawContent);\n\t\tconst skillDir = dirname(filePath);\n\t\tconst parentDirName = basename(skillDir);\n\n\t\t// Validate description\n\t\tconst descErrors = validateDescription(frontmatter.description);\n\t\tfor (const error of descErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\n\t\t// Use name from frontmatter, or fall back to parent directory name\n\t\tconst name = frontmatter.name || parentDirName;\n\n\t\t// Validate name\n\t\tconst nameErrors = validateName(name, parentDirName);\n\t\tfor (const error of nameErrors) {\n\t\t\tdiagnostics.push({ type: \"warning\", message: error, path: filePath });\n\t\t}\n\n\t\t// Still load the skill even with warnings (unless description is completely missing)\n\t\tif (!frontmatter.description || frontmatter.description.trim() === \"\") {\n\t\t\treturn { skill: null, diagnostics };\n\t\t}\n\n\t\treturn {\n\t\t\tskill: {\n\t\t\t\tname,\n\t\t\t\tdescription: frontmatter.description,\n\t\t\t\tfilePath,\n\t\t\t\tbaseDir: skillDir,\n\t\t\t\tsource,\n\t\t\t\tdisableModelInvocation: frontmatter[\"disable-model-invocation\"] === true,\n\t\t\t\tuserInvocable: frontmatter[\"user-invocable\"] === true,\n\t\t\t},\n\t\t\tdiagnostics,\n\t\t};\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : \"failed to parse skill file\";\n\t\tdiagnostics.push({ type: \"warning\", message, path: filePath });\n\t\treturn { skill: null, diagnostics };\n\t}\n}\n\n/**\n * Format skills for inclusion in a system prompt.\n * Uses XML format per Agent Skills standard.\n * See: https://agentskills.io/integrate-skills\n *\n * Skills with disableModelInvocation=true are excluded from the prompt\n * (they can only be invoked explicitly via /skill:name commands).\n */\nexport function formatSkillsForPrompt(skills: Skill[]): string {\n\tconst visibleSkills = skills.filter((s) => !s.disableModelInvocation);\n\n\tif (visibleSkills.length === 0) {\n\t\treturn \"\";\n\t}\n\n\tconst lines = [\n\t\t\"\\n\\nThe following skills provide specialized instructions for specific tasks.\",\n\t\t\"Use the Skill tool with the exact skill name from <available_skills> when the task matches its description.\",\n\t\t\"Use the Skill tool only for listed skills — not for launching subagents like scout, worker, reviewer, or planner.\",\n\t\t\"If the Skill tool reports an unknown skill, do not guess: use an exact name from <available_skills> or tell the user the skill is unavailable.\",\n\t\t\"When a skill file references a relative path, resolve it against the skill directory (parent of SKILL.md / dirname of the path) and use that absolute path in tool commands.\",\n\t\t\"\",\n\t\t\"<available_skills>\",\n\t];\n\n\tfor (const skill of visibleSkills) {\n\t\tlines.push(\" <skill>\");\n\t\tlines.push(` <name>${escapeXml(skill.name)}</name>`);\n\t\tlines.push(` <description>${escapeXml(skill.description)}</description>`);\n\t\tlines.push(` <location>${escapeXml(skill.filePath)}</location>`);\n\t\tlines.push(\" </skill>\");\n\t}\n\n\tlines.push(\"</available_skills>\");\n\n\treturn lines.join(\"\\n\");\n}\n\nfunction escapeXml(str: string): string {\n\treturn str\n\t\t.replace(/&/g, \"&amp;\")\n\t\t.replace(/</g, \"&lt;\")\n\t\t.replace(/>/g, \"&gt;\")\n\t\t.replace(/\"/g, \"&quot;\")\n\t\t.replace(/'/g, \"&apos;\");\n}\n\nexport interface LoadSkillsOptions {\n\t/** Working directory for project-local skills. Default: process.cwd() */\n\tcwd?: string;\n\t/** @deprecated Retained for compatibility. Default skill discovery no longer depends on agentDir. */\n\tagentDir?: string;\n\t/** Explicit skill paths (files or directories) */\n\tskillPaths?: string[];\n\t/** Include default skills directories. Default: true */\n\tincludeDefaults?: boolean;\n}\n\nfunction normalizePath(input: string): string {\n\tconst trimmed = input.trim();\n\tif (trimmed === \"~\") return homedir();\n\tif (trimmed.startsWith(\"~/\")) return join(homedir(), trimmed.slice(2));\n\tif (trimmed.startsWith(\"~\")) return join(homedir(), trimmed.slice(1));\n\treturn trimmed;\n}\n\nfunction resolveSkillPath(p: string, cwd: string): string {\n\tconst normalized = normalizePath(p);\n\treturn isAbsolute(normalized) ? normalized : resolve(cwd, normalized);\n}\n\n/**\n * Load skills from all configured locations.\n * Returns skills and any validation diagnostics.\n */\nexport function loadSkills(options: LoadSkillsOptions = {}): LoadSkillsResult {\n\tconst { cwd = process.cwd(), skillPaths = [], includeDefaults = true } = options;\n\n\tconst skillMap = new Map<string, Skill>();\n\tconst realPathSet = new Set<string>();\n\tconst allDiagnostics: ResourceDiagnostic[] = [];\n\tconst collisionDiagnostics: ResourceDiagnostic[] = [];\n\n\tfunction addSkills(result: LoadSkillsResult) {\n\t\tallDiagnostics.push(...result.diagnostics);\n\t\tfor (const skill of result.skills) {\n\t\t\t// Resolve symlinks to detect duplicate files\n\t\t\tlet realPath: string;\n\t\t\ttry {\n\t\t\t\trealPath = realpathSync(skill.filePath);\n\t\t\t} catch {\n\t\t\t\trealPath = skill.filePath;\n\t\t\t}\n\n\t\t\t// Skip silently if we've already loaded this exact file (via symlink)\n\t\t\tif (realPathSet.has(realPath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst existing = skillMap.get(skill.name);\n\t\t\tif (existing) {\n\t\t\t\tcollisionDiagnostics.push({\n\t\t\t\t\ttype: \"collision\",\n\t\t\t\t\tmessage: `name \"${skill.name}\" collision`,\n\t\t\t\t\tpath: skill.filePath,\n\t\t\t\t\tcollision: {\n\t\t\t\t\t\tresourceType: \"skill\",\n\t\t\t\t\t\tname: skill.name,\n\t\t\t\t\t\twinnerPath: existing.filePath,\n\t\t\t\t\t\tloserPath: skill.filePath,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tskillMap.set(skill.name, skill);\n\t\t\t\trealPathSet.add(realPath);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (includeDefaults) {\n\t\t// Preferred project-local location for LSD repos.\n\t\t// Load this first so project skills shadow user/global skills with the same name.\n\t\taddSkills(loadSkillsFromDirInternal(resolve(cwd, ECOSYSTEM_PROJECT_SKILLS_DIR, \"skills\"), \"project\", true));\n\t\t// Primary global location for LSD.\n\t\taddSkills(loadSkillsFromDirInternal(ECOSYSTEM_SKILLS_DIR, \"user\", true));\n\t\t// Compatibility fallback: shared Agent Skills ecosystem directory.\n\t\tif (COMPAT_ECOSYSTEM_SKILLS_DIR !== ECOSYSTEM_SKILLS_DIR) {\n\t\t\taddSkills(loadSkillsFromDirInternal(COMPAT_ECOSYSTEM_SKILLS_DIR, \"user\", true));\n\t\t}\n\n\t\t// Legacy fallback: read skills from ~/.lsd/agent/skills/ so existing\n\t\t// installs keep working until migration moves them to ~/.lsd/skills/.\n\t\tconst legacyMigrated = existsSync(join(LEGACY_SKILLS_DIR, \".migrated-to-lsd-skills\"));\n\t\tif (LEGACY_SKILLS_DIR !== ECOSYSTEM_SKILLS_DIR && existsSync(LEGACY_SKILLS_DIR) && !legacyMigrated) {\n\t\t\taddSkills(loadSkillsFromDirInternal(LEGACY_SKILLS_DIR, \"user\", true));\n\t\t}\n\t}\n\n\tconst userSkillsDir = ECOSYSTEM_SKILLS_DIR;\n\tconst projectSkillsDir = resolve(cwd, ECOSYSTEM_PROJECT_SKILLS_DIR, \"skills\");\n\n\tconst isUnderPath = (target: string, root: string): boolean => {\n\t\tconst normalizedRoot = resolve(root);\n\t\tif (target === normalizedRoot) {\n\t\t\treturn true;\n\t\t}\n\t\tconst prefix = normalizedRoot.endsWith(sep) ? normalizedRoot : `${normalizedRoot}${sep}`;\n\t\treturn target.startsWith(prefix);\n\t};\n\n\tconst getSource = (resolvedPath: string): \"user\" | \"project\" | \"path\" => {\n\t\tif (!includeDefaults) {\n\t\t\tif (isUnderPath(resolvedPath, userSkillsDir)) return \"user\";\n\t\t\tif (isUnderPath(resolvedPath, projectSkillsDir)) return \"project\";\n\t\t}\n\t\treturn \"path\";\n\t};\n\n\tfor (const rawPath of skillPaths) {\n\t\tconst resolvedPath = resolveSkillPath(rawPath, cwd);\n\t\tif (!existsSync(resolvedPath)) {\n\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path does not exist\", path: resolvedPath });\n\t\t\tcontinue;\n\t\t}\n\n\t\ttry {\n\t\t\tconst stats = statSync(resolvedPath);\n\t\t\tconst source = getSource(resolvedPath);\n\t\t\tif (stats.isDirectory()) {\n\t\t\t\taddSkills(loadSkillsFromDirInternal(resolvedPath, source, true));\n\t\t\t} else if (stats.isFile() && resolvedPath.endsWith(\".md\")) {\n\t\t\t\tconst result = loadSkillFromFile(resolvedPath, source);\n\t\t\t\tif (result.skill) {\n\t\t\t\t\taddSkills({ skills: [result.skill], diagnostics: result.diagnostics });\n\t\t\t\t} else {\n\t\t\t\t\tallDiagnostics.push(...result.diagnostics);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tallDiagnostics.push({ type: \"warning\", message: \"skill path is not a markdown file\", path: resolvedPath });\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconst message = error instanceof Error ? error.message : \"failed to read skill path\";\n\t\t\tallDiagnostics.push({ type: \"warning\", message, path: resolvedPath });\n\t\t}\n\t}\n\n\tloadedSkills = Array.from(skillMap.values());\n\n\treturn {\n\t\tskills: [...loadedSkills],\n\t\tdiagnostics: [...allDiagnostics, ...collisionDiagnostics],\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAchE,MAAM,WAAW,wBAAwB;IACxC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,yBAAyB;IACzB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CAuNhF"}
1
+ {"version":3,"file":"system-prompt.d.ts","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAyB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAchE,MAAM,WAAW,wBAAwB;IACxC;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,qFAAqF;IACrF,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,uCAAuC;IACvC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACxD,yBAAyB;IACzB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;CACjB;AAED,kEAAkE;AAClE,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,GAAG,MAAM,CA0NhF"}
@@ -110,6 +110,7 @@ export function buildSystemPrompt(options = {}) {
110
110
  addGuideline("Recon planning policy: use 0 scouts for narrow known-file work, 1 scout for one broad unfamiliar subsystem, and 2-4 parallel scouts only when the work spans multiple loosely-coupled subsystems.");
111
111
  addGuideline("For broad or unfamiliar codebase exploration, delegate reconnaissance to the scout subagent before reading many files yourself. After scout returns, use lsp and targeted reads for the narrowed file set.");
112
112
  addGuideline("Call the subagent tool directly. For one scout use { agent, task }. For several scouts use parallel mode with { tasks: [{ agent, task }, ...] }.");
113
+ addGuideline("When the user names a subagent such as scout, worker, reviewer, or planner, invoke the subagent tool directly rather than the Skill tool or ad-hoc search.");
113
114
  addGuideline("Scout is for mapping and reconnaissance only — not for final review, audit, or ranked issue lists. Use it to identify relevant files, subsystems, and likely hotspots for later evaluation.");
114
115
  addGuideline("If reconnaissance spans multiple loosely-coupled areas, prefer multiple scout subagents in parallel, each covering one subsystem, instead of one model exploring everything itself.");
115
116
  addGuideline("For broad review or audit requests, use scout only as a prep step to map architecture and hotspots; the parent model or a reviewer should make the final judgments.");
@@ -1 +1 @@
1
- {"version":3,"file":"system-prompt.js","sourceRoot":"","sources":["../../src/core/system-prompt.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAc,MAAM,aAAa,CAAC;AAEhE,0CAA0C;AAC1C,MAAM,gBAAgB,GAA2B;IAChD,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,8CAA8C;IACpD,IAAI,EAAE,4DAA4D;IAClE,KAAK,EAAE,2BAA2B;IAClC,IAAI,EAAE,6IAA6I;IACnJ,IAAI,EAAE,kDAAkD;IACxD,EAAE,EAAE,yBAAyB;IAC7B,GAAG,EAAE,oHAAoH;CACzH,CAAC;AA0BF,kEAAkE;AAClE,MAAM,UAAU,iBAAiB,CAAC,UAAoC,EAAE;IACvE,MAAM,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,GAAG,EACH,YAAY,EAAE,oBAAoB,EAClC,MAAM,EAAE,cAAc,GACtB,GAAG,OAAO,CAAC;IACZ,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAEtD,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACv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,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,OAAO,IAAI,QAAQ,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,2CAA2C;IAC3C,MAAM,IAAI,4BAA4B,QAAQ,EAAE,CAAC;IACjD,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { existsSync } from \"node:fs\";\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore). For symbol definitions, references, type info, or callers in code, use lsp instead\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\tlsp: \"Code intelligence via Language Server Protocol (go-to-definition, references, diagnostics, hover, rename, symbols)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/**\n\t * Custom system prompt that replaces the default role header, tool list,\n\t * and guidelines entirely. You are responsible for providing your own\n\t * tool-usage guidance. Project context, skills, extension promptGuidelines,\n\t * date/cwd, and appendSystemPrompt are still applied on top.\n\t */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst resolvedCwd = toPosixPath(cwd ?? process.cwd());\n\n\tconst now = new Date();\n\tconst dateTime = now.toLocaleString(\"en-US\", {\n\t\tweekday: \"long\",\n\t\tyear: \"numeric\",\n\t\tmonth: \"long\",\n\t\tday: \"numeric\",\n\t\thour: \"2-digit\",\n\t\tminute: \"2-digit\",\n\t\tsecond: \"2-digit\",\n\t\ttimeZoneName: \"short\",\n\t});\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (if read or Skill tool is available)\n\t\tconst customPromptHasSkillAccess = !selectedTools || selectedTools.includes(\"read\") || selectedTools.includes(\"Skill\");\n\t\tif (customPromptHasSkillAccess && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Append promptGuidelines from extension-registered tools.\n\t\t// Without this, tools registered via pi.registerTool() with promptGuidelines\n\t\t// have their definitions reach the API but the model has no guidance on when\n\t\t// to use them (#1184).\n\t\tif (promptGuidelines && promptGuidelines.length > 0) {\n\t\t\tprompt += \"\\n\\n\";\n\t\t\tfor (const guideline of promptGuidelines) {\n\t\t\t\tprompt += guideline + \"\\n\";\n\t\t\t}\n\t\t}\n\n\t\t// Add date/time and working directory last\n\t\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\t// Build tools list based on selected tools.\n\t// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasRead = tools.includes(\"read\");\n\tconst hasLsp = tools.includes(\"lsp\");\n\n\t// Priority-ordered compact guidelines\n\taddGuideline(\"Be concise. Prefer short, direct answers over preamble.\");\n\taddGuideline(\"For conceptual, product, or UX questions, answer first; inspect code only if implementation detail is needed.\");\n\n\tconst hasSubagent = tools.includes(\"subagent\");\n\n\tif (hasLsp) {\n\t\taddGuideline(\n\t\t\t\"Code navigation in typed codebases: use lsp for symbols (definition, references, implementation, hover, diagnostics, rename, format). Use grep/find/ls for text patterns, filenames, and non-code files.\",\n\t\t);\n\t} else {\n\t\taddGuideline(\"Use grep/find/ls for code search and file exploration (faster than bash, respects .gitignore)\");\n\t}\n\n\tif (hasSubagent) {\n\t\taddGuideline(\n\t\t\t\"Recon planning policy: use 0 scouts for narrow known-file work, 1 scout for one broad unfamiliar subsystem, and 2-4 parallel scouts only when the work spans multiple loosely-coupled subsystems.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"For broad or unfamiliar codebase exploration, delegate reconnaissance to the scout subagent before reading many files yourself. After scout returns, use lsp and targeted reads for the narrowed file set.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Call the subagent tool directly. For one scout use { agent, task }. For several scouts use parallel mode with { tasks: [{ agent, task }, ...] }.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Scout is for mapping and reconnaissance only — not for final review, audit, or ranked issue lists. Use it to identify relevant files, subsystems, and likely hotspots for later evaluation.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"If reconnaissance spans multiple loosely-coupled areas, prefer multiple scout subagents in parallel, each covering one subsystem, instead of one model exploring everything itself.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"For broad review or audit requests, use scout only as a prep step to map architecture and hotspots; the parent model or a reviewer should make the final judgments.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Skip scout only when the task is clearly narrow, the relevant file is already known, or the user explicitly asked for direct inspection of a specific file.\",\n\t\t);\n\t}\n\n\tif (hasRead && hasEdit) {\n\t\taddGuideline(\"Read files before editing them. Never use cat or sed to inspect or modify files.\");\n\t}\n\n\tif (hasEdit) {\n\t\taddGuideline(\"edit requires exact text match; write is for new files or full rewrites.\");\n\t}\n\n\tif (hasWrite && !hasEdit) {\n\t\taddGuideline(\"write is for new files or full rewrites.\");\n\t}\n\n\tif (hasLsp && hasEdit) {\n\t\taddGuideline(\"Run lsp diagnostics after edits to catch type errors.\");\n\t}\n\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\"Output plain text directly when summarizing your work — do not cat or echo to display what you did.\");\n\t}\n\n\taddGuideline(\"Show file paths clearly when referencing files.\");\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tconst piDocsBlock = existsSync(readmePath)\n\t\t? `\\n\\nPi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When working on pi topics, read the docs and follow .md cross-references before implementing`\n\t\t: \"\";\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}${piDocsBlock}`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (if read or Skill tool is available)\n\tconst hasSkill = tools.includes(\"Skill\");\n\tif ((hasRead || hasSkill) && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time and working directory last\n\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\tprompt += `\\nCurrent working directory: ${resolv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A2C;IAC3C,MAAM,IAAI,4BAA4B,QAAQ,EAAE,CAAC;IACjD,MAAM,IAAI,gCAAgC,WAAW,EAAE,CAAC;IAExD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * System prompt construction and project context loading\n */\n\nimport { existsSync } from \"node:fs\";\nimport { getDocsPath, getExamplesPath, getReadmePath } from \"../config.js\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { formatSkillsForPrompt, type Skill } from \"./skills.js\";\n\n/** Tool descriptions for system prompt */\nconst toolDescriptions: Record<string, string> = {\n\tread: \"Read file contents\",\n\tbash: \"Execute bash commands (ls, grep, find, etc.)\",\n\tedit: \"Make surgical edits to files (find exact text and replace)\",\n\twrite: \"Create or overwrite files\",\n\tgrep: \"Search file contents for patterns (respects .gitignore). For symbol definitions, references, type info, or callers in code, use lsp instead\",\n\tfind: \"Find files by glob pattern (respects .gitignore)\",\n\tls: \"List directory contents\",\n\tlsp: \"Code intelligence via Language Server Protocol (go-to-definition, references, diagnostics, hover, rename, symbols)\",\n};\n\nexport interface BuildSystemPromptOptions {\n\t/**\n\t * Custom system prompt that replaces the default role header, tool list,\n\t * and guidelines entirely. You are responsible for providing your own\n\t * tool-usage guidance. Project context, skills, extension promptGuidelines,\n\t * date/cwd, and appendSystemPrompt are still applied on top.\n\t */\n\tcustomPrompt?: string;\n\t/** Tools to include in prompt. Default: [read, bash, edit, write] */\n\tselectedTools?: string[];\n\t/** Optional one-line tool snippets keyed by tool name. */\n\ttoolSnippets?: Record<string, string>;\n\t/** Additional guideline bullets appended to the default system prompt guidelines. */\n\tpromptGuidelines?: string[];\n\t/** Text to append to system prompt. */\n\tappendSystemPrompt?: string;\n\t/** Working directory. Default: process.cwd() */\n\tcwd?: string;\n\t/** Pre-loaded context files. */\n\tcontextFiles?: Array<{ path: string; content: string }>;\n\t/** Pre-loaded skills. */\n\tskills?: Skill[];\n}\n\n/** Build the system prompt with tools, guidelines, and context */\nexport function buildSystemPrompt(options: BuildSystemPromptOptions = {}): string {\n\tconst {\n\t\tcustomPrompt,\n\t\tselectedTools,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t\tappendSystemPrompt,\n\t\tcwd,\n\t\tcontextFiles: providedContextFiles,\n\t\tskills: providedSkills,\n\t} = options;\n\tconst resolvedCwd = toPosixPath(cwd ?? process.cwd());\n\n\tconst now = new Date();\n\tconst dateTime = now.toLocaleString(\"en-US\", {\n\t\tweekday: \"long\",\n\t\tyear: \"numeric\",\n\t\tmonth: \"long\",\n\t\tday: \"numeric\",\n\t\thour: \"2-digit\",\n\t\tminute: \"2-digit\",\n\t\tsecond: \"2-digit\",\n\t\ttimeZoneName: \"short\",\n\t});\n\n\tconst appendSection = appendSystemPrompt ? `\\n\\n${appendSystemPrompt}` : \"\";\n\n\tconst contextFiles = providedContextFiles ?? [];\n\tconst skills = providedSkills ?? [];\n\n\tif (customPrompt) {\n\t\tlet prompt = customPrompt;\n\n\t\tif (appendSection) {\n\t\t\tprompt += appendSection;\n\t\t}\n\n\t\t// Append project context files\n\t\tif (contextFiles.length > 0) {\n\t\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t\t}\n\t\t}\n\n\t\t// Append skills section (if read or Skill tool is available)\n\t\tconst customPromptHasSkillAccess = !selectedTools || selectedTools.includes(\"read\") || selectedTools.includes(\"Skill\");\n\t\tif (customPromptHasSkillAccess && skills.length > 0) {\n\t\t\tprompt += formatSkillsForPrompt(skills);\n\t\t}\n\n\t\t// Append promptGuidelines from extension-registered tools.\n\t\t// Without this, tools registered via pi.registerTool() with promptGuidelines\n\t\t// have their definitions reach the API but the model has no guidance on when\n\t\t// to use them (#1184).\n\t\tif (promptGuidelines && promptGuidelines.length > 0) {\n\t\t\tprompt += \"\\n\\n\";\n\t\t\tfor (const guideline of promptGuidelines) {\n\t\t\t\tprompt += guideline + \"\\n\";\n\t\t\t}\n\t\t}\n\n\t\t// Add date/time and working directory last\n\t\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\t\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\t\treturn prompt;\n\t}\n\n\t// Get absolute paths to documentation and examples\n\tconst readmePath = getReadmePath();\n\tconst docsPath = getDocsPath();\n\tconst examplesPath = getExamplesPath();\n\n\t// Build tools list based on selected tools.\n\t// Built-ins use toolDescriptions. Custom tools can provide one-line snippets.\n\tconst tools = selectedTools || [\"read\", \"bash\", \"edit\", \"write\"];\n\tconst toolsList =\n\t\ttools.length > 0\n\t\t\t? tools\n\t\t\t\t\t.map((name) => {\n\t\t\t\t\t\tconst snippet = toolSnippets?.[name] ?? toolDescriptions[name] ?? name;\n\t\t\t\t\t\treturn `- ${name}: ${snippet}`;\n\t\t\t\t\t})\n\t\t\t\t\t.join(\"\\n\")\n\t\t\t: \"(none)\";\n\n\t// Build guidelines based on which tools are actually available\n\tconst guidelinesList: string[] = [];\n\tconst guidelinesSet = new Set<string>();\n\tconst addGuideline = (guideline: string): void => {\n\t\tif (guidelinesSet.has(guideline)) {\n\t\t\treturn;\n\t\t}\n\t\tguidelinesSet.add(guideline);\n\t\tguidelinesList.push(guideline);\n\t};\n\n\tconst hasEdit = tools.includes(\"edit\");\n\tconst hasWrite = tools.includes(\"write\");\n\tconst hasRead = tools.includes(\"read\");\n\tconst hasLsp = tools.includes(\"lsp\");\n\n\t// Priority-ordered compact guidelines\n\taddGuideline(\"Be concise. Prefer short, direct answers over preamble.\");\n\taddGuideline(\"For conceptual, product, or UX questions, answer first; inspect code only if implementation detail is needed.\");\n\n\tconst hasSubagent = tools.includes(\"subagent\");\n\n\tif (hasLsp) {\n\t\taddGuideline(\n\t\t\t\"Code navigation in typed codebases: use lsp for symbols (definition, references, implementation, hover, diagnostics, rename, format). Use grep/find/ls for text patterns, filenames, and non-code files.\",\n\t\t);\n\t} else {\n\t\taddGuideline(\"Use grep/find/ls for code search and file exploration (faster than bash, respects .gitignore)\");\n\t}\n\n\tif (hasSubagent) {\n\t\taddGuideline(\n\t\t\t\"Recon planning policy: use 0 scouts for narrow known-file work, 1 scout for one broad unfamiliar subsystem, and 2-4 parallel scouts only when the work spans multiple loosely-coupled subsystems.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"For broad or unfamiliar codebase exploration, delegate reconnaissance to the scout subagent before reading many files yourself. After scout returns, use lsp and targeted reads for the narrowed file set.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Call the subagent tool directly. For one scout use { agent, task }. For several scouts use parallel mode with { tasks: [{ agent, task }, ...] }.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"When the user names a subagent such as scout, worker, reviewer, or planner, invoke the subagent tool directly rather than the Skill tool or ad-hoc search.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Scout is for mapping and reconnaissance only — not for final review, audit, or ranked issue lists. Use it to identify relevant files, subsystems, and likely hotspots for later evaluation.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"If reconnaissance spans multiple loosely-coupled areas, prefer multiple scout subagents in parallel, each covering one subsystem, instead of one model exploring everything itself.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"For broad review or audit requests, use scout only as a prep step to map architecture and hotspots; the parent model or a reviewer should make the final judgments.\",\n\t\t);\n\t\taddGuideline(\n\t\t\t\"Skip scout only when the task is clearly narrow, the relevant file is already known, or the user explicitly asked for direct inspection of a specific file.\",\n\t\t);\n\t}\n\n\tif (hasRead && hasEdit) {\n\t\taddGuideline(\"Read files before editing them. Never use cat or sed to inspect or modify files.\");\n\t}\n\n\tif (hasEdit) {\n\t\taddGuideline(\"edit requires exact text match; write is for new files or full rewrites.\");\n\t}\n\n\tif (hasWrite && !hasEdit) {\n\t\taddGuideline(\"write is for new files or full rewrites.\");\n\t}\n\n\tif (hasLsp && hasEdit) {\n\t\taddGuideline(\"Run lsp diagnostics after edits to catch type errors.\");\n\t}\n\n\tif (hasEdit || hasWrite) {\n\t\taddGuideline(\"Output plain text directly when summarizing your work — do not cat or echo to display what you did.\");\n\t}\n\n\taddGuideline(\"Show file paths clearly when referencing files.\");\n\n\tfor (const guideline of promptGuidelines ?? []) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\taddGuideline(normalized);\n\t\t}\n\t}\n\n\tconst guidelines = guidelinesList.map((g) => `- ${g}`).join(\"\\n\");\n\n\tconst piDocsBlock = existsSync(readmePath)\n\t\t? `\\n\\nPi documentation (read only when the user asks about pi itself, its SDK, extensions, themes, skills, or TUI):\n- Main documentation: ${readmePath}\n- Additional docs: ${docsPath}\n- Examples: ${examplesPath} (extensions, custom tools, SDK)\n- When working on pi topics, read the docs and follow .md cross-references before implementing`\n\t\t: \"\";\n\n\tlet prompt = `You are an expert coding assistant operating inside pi, a coding agent harness.\n\nAvailable tools:\n${toolsList}\n\nIn addition to the tools above, you may have access to other custom tools depending on the project.\n\nGuidelines:\n${guidelines}${piDocsBlock}`;\n\n\tif (appendSection) {\n\t\tprompt += appendSection;\n\t}\n\n\t// Append project context files\n\tif (contextFiles.length > 0) {\n\t\tprompt += \"\\n\\n# Project Context\\n\\n\";\n\t\tprompt += \"Project-specific instructions and guidelines:\\n\\n\";\n\t\tfor (const { path: filePath, content } of contextFiles) {\n\t\t\tprompt += `## ${filePath}\\n\\n${content}\\n\\n`;\n\t\t}\n\t}\n\n\t// Append skills section (if read or Skill tool is available)\n\tconst hasSkill = tools.includes(\"Skill\");\n\tif ((hasRead || hasSkill) && skills.length > 0) {\n\t\tprompt += formatSkillsForPrompt(skills);\n\t}\n\n\t// Add date/time and working directory last\n\tprompt += `\\nCurrent date and time: ${dateTime}`;\n\tprompt += `\\nCurrent working directory: ${resolvedCwd}`;\n\n\treturn prompt;\n}\n"]}
@@ -53,6 +53,7 @@ test("buildSystemPrompt: encourages scout-first reconnaissance when subagent is
53
53
  assert.match(prompt, /multiple scout subagents in parallel/i);
54
54
  assert.match(prompt, /broad review or audit requests, use scout only as a prep step/i);
55
55
  assert.match(prompt, /Skip scout only when the task is clearly narrow/i);
56
+ assert.match(prompt, /When the user names a subagent such as scout, worker, reviewer, or planner, invoke the subagent tool directly/i);
56
57
  });
57
58
  // ─── Regression: no backslash paths in LLM-visible text ────────────────────
58
59
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"path-display.test.js","sourceRoot":"","sources":["../../src/tests/path-display.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,+EAA+E;AAE/E,IAAI,CAAC,kEAAkE,EAAE,GAAG,EAAE;IAC7E,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,0BAA0B,CAAC,EAAE,uBAAuB,CAAC,CAAC;AAChF,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IAClD,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,6BAA6B,CAAC,EAAE,2BAA2B,CAAC,CAAC;AACvF,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mCAAmC,EAAE,GAAG,EAAE;IAC9C,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC,CAAC;AACvE,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mCAAmC,EAAE,GAAG,EAAE;IAC9C,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,wCAAwC,EAAE,GAAG,EAAE;IACnD,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,wBAAwB,CAAC,EAA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EAAE,+CAA+C,CAAC,CAAC;IACtE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,uCAAuC,CAAC,CAAC;IAC9D,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,gEAAgE,CAAC,CAAC;IACvF,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,kDAAkD,CAAC,CAAC;AAC1E,CAAC,CAAC,CAAC;AAEH,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,kBAAkB,CAAC;AAE/C,IAAI,CAAC,yEAAyE,EAAE,GAAG,EAAE;IACpF,8BAA8B;IAC9B,MAAM,MAAM,GAAG,iBAAiB,CAAC;QAChC,GAAG,EAAE,6CAA6C;KAClD,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IACxE,MAAM,CAAC,KAAK,CACX,UAAU,CAAC,MAAM,EAAE,CAAC,EACpB,oDAAoD,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC3E,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Cross-platform path display tests.\n *\n * Verifies that toPosixPath correctly normalizes Windows paths and that\n * the system prompt builder produces forward-slash paths for LLM consumption.\n */\n\nimport test from \"node:test\";\nimport assert from \"node:assert/strict\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { buildSystemPrompt } from \"../core/system-prompt.js\";\n\n// ─── toPosixPath ────────────────────────────────────────────────────────────\n\ntest(\"toPosixPath: converts Windows backslash paths to forward slashes\", () => {\n\tassert.equal(toPosixPath(\"C:\\\\Users\\\\name\\\\project\"), \"C:/Users/name/project\");\n});\n\ntest(\"toPosixPath: handles mixed separators\", () => {\n\tassert.equal(toPosixPath(\"C:\\\\Users/name\\\\project/src\"), \"C:/Users/name/project/src\");\n});\n\ntest(\"toPosixPath: no-op for Unix paths\", () => {\n\tassert.equal(toPosixPath(\"/home/user/project\"), \"/home/user/project\");\n});\n\ntest(\"toPosixPath: handles empty string\", () => {\n\tassert.equal(toPosixPath(\"\"), \"\");\n});\n\ntest(\"toPosixPath: handles Windows UNC paths\", () => {\n\tassert.equal(toPosixPath(\"\\\\\\\\server\\\\share\\\\dir\"), \"//server/share/dir\");\n});\n\ntest(\"toPosixPath: handles .gsd/worktrees path on Windows\", () => {\n\tassert.equal(\n\t\ttoPosixPath(\"C:\\\\Users\\\\name\\\\project\\\\.gsd\\\\worktrees\\\\M001\"),\n\t\t\"C:/Users/name/project/.gsd/worktrees/M001\",\n\t);\n});\n\n// ─── System prompt path normalization ───────────────────────────────────────\n\ntest(\"buildSystemPrompt: cwd uses forward slashes even with Windows input\", () => {\n\tconst prompt = buildSystemPrompt({\n\t\tcwd: \"C:\\\\Users\\\\name\\\\development\\\\app-name\",\n\t});\n\tassert.ok(\n\t\tprompt.includes(\"C:/Users/name/development/app-name\"),\n\t\t\"System prompt should contain forward-slash path\",\n\t);\n\tassert.ok(\n\t\t!prompt.includes(\"C:\\\\Users\\\\name\\\\development\\\\app-name\"),\n\t\t\"System prompt must NOT contain backslash path\",\n\t);\n});\n\ntest(\"buildSystemPrompt: Unix paths pass through unchanged\", () => {\n\tconst prompt = buildSystemPrompt({\n\t\tcwd: \"/home/user/project\",\n\t});\n\tassert.ok(prompt.includes(\"/home/user/project\"));\n});\n\ntest(\"buildSystemPrompt: encourages scout-first reconnaissance when subagent is available\", () => {\n\tconst prompt = buildSystemPrompt({\n\t\tcwd: \"/home/user/project\",\n\t\tselectedTools: [\"read\", \"lsp\", \"subagent\", \"edit\", \"write\"],\n\t});\n\tassert.match(prompt, /delegate reconnaissance to the scout subagent/i);\n\tassert.match(prompt, /0 scouts for narrow known-file work, 1 scout for one broad unfamiliar subsystem/i);\n\tassert.match(prompt, /For one scout use \\{ agent, task \\}/i);\n\tassert.match(prompt, /Scout is for mapping and reconnaissance only/i);\n\tassert.match(prompt, /multiple scout subagents in parallel/i);\n\tassert.match(prompt, /broad review or audit requests, use scout only as a prep step/i);\n\tassert.match(prompt, /Skip scout only when the task is clearly narrow/i);\n});\n\n// ─── Regression: no backslash paths in LLM-visible text ────────────────────\n\n/**\n * Pattern that matches Windows-style absolute paths with backslashes.\n * Catches: C:\\Users\\..., D:\\Projects\\..., \\\\server\\share\\...\n * Does not match: escaped chars in regex, JSON strings, etc.\n */\nconst WINDOWS_ABS_PATH_RE = /[A-Z]:\\\\[A-Za-z]/;\n\ntest(\"buildSystemPrompt: no Windows absolute paths with backslashes in output\", () => {\n\t// Simulate a Windows-like cwd\n\tconst prompt = buildSystemPrompt({\n\t\tcwd: \"D:\\\\Projects\\\\my-app\\\\.gsd\\\\worktrees\\\\M002\",\n\t});\n\tconst lines = prompt.split(\"\\n\");\n\tconst violations = lines.filter(line => WINDOWS_ABS_PATH_RE.test(line));\n\tassert.equal(\n\t\tviolations.length, 0,\n\t\t`System prompt contains Windows backslash paths:\\n${violations.join(\"\\n\")}`,\n\t);\n});\n"]}
1
+ {"version":3,"file":"path-display.test.js","sourceRoot":"","sources":["../../src/tests/path-display.test.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D,+EAA+E;AAE/E,IAAI,CAAC,kEAAkE,EAAE,GAAG,EAAE;IAC7E,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,0BAA0B,CAAC,EAAE,uBAAuB,CAAC,CAAC;AAChF,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,GAAG,EAAE;IAClD,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,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C,EACpB,oDAAoD,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAC3E,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Cross-platform path display tests.\n *\n * Verifies that toPosixPath correctly normalizes Windows paths and that\n * the system prompt builder produces forward-slash paths for LLM consumption.\n */\n\nimport test from \"node:test\";\nimport assert from \"node:assert/strict\";\nimport { toPosixPath } from \"../utils/path-display.js\";\nimport { buildSystemPrompt } from \"../core/system-prompt.js\";\n\n// ─── toPosixPath ────────────────────────────────────────────────────────────\n\ntest(\"toPosixPath: converts Windows backslash paths to forward slashes\", () => {\n\tassert.equal(toPosixPath(\"C:\\\\Users\\\\name\\\\project\"), \"C:/Users/name/project\");\n});\n\ntest(\"toPosixPath: handles mixed separators\", () => {\n\tassert.equal(toPosixPath(\"C:\\\\Users/name\\\\project/src\"), \"C:/Users/name/project/src\");\n});\n\ntest(\"toPosixPath: no-op for Unix paths\", () => {\n\tassert.equal(toPosixPath(\"/home/user/project\"), \"/home/user/project\");\n});\n\ntest(\"toPosixPath: handles empty string\", () => {\n\tassert.equal(toPosixPath(\"\"), \"\");\n});\n\ntest(\"toPosixPath: handles Windows UNC paths\", () => {\n\tassert.equal(toPosixPath(\"\\\\\\\\server\\\\share\\\\dir\"), \"//server/share/dir\");\n});\n\ntest(\"toPosixPath: handles .gsd/worktrees path on Windows\", () => {\n\tassert.equal(\n\t\ttoPosixPath(\"C:\\\\Users\\\\name\\\\project\\\\.gsd\\\\worktrees\\\\M001\"),\n\t\t\"C:/Users/name/project/.gsd/worktrees/M001\",\n\t);\n});\n\n// ─── System prompt path normalization ───────────────────────────────────────\n\ntest(\"buildSystemPrompt: cwd uses forward slashes even with Windows input\", () => {\n\tconst prompt = buildSystemPrompt({\n\t\tcwd: \"C:\\\\Users\\\\name\\\\development\\\\app-name\",\n\t});\n\tassert.ok(\n\t\tprompt.includes(\"C:/Users/name/development/app-name\"),\n\t\t\"System prompt should contain forward-slash path\",\n\t);\n\tassert.ok(\n\t\t!prompt.includes(\"C:\\\\Users\\\\name\\\\development\\\\app-name\"),\n\t\t\"System prompt must NOT contain backslash path\",\n\t);\n});\n\ntest(\"buildSystemPrompt: Unix paths pass through unchanged\", () => {\n\tconst prompt = buildSystemPrompt({\n\t\tcwd: \"/home/user/project\",\n\t});\n\tassert.ok(prompt.includes(\"/home/user/project\"));\n});\n\ntest(\"buildSystemPrompt: encourages scout-first reconnaissance when subagent is available\", () => {\n\tconst prompt = buildSystemPrompt({\n\t\tcwd: \"/home/user/project\",\n\t\tselectedTools: [\"read\", \"lsp\", \"subagent\", \"edit\", \"write\"],\n\t});\n\tassert.match(prompt, /delegate reconnaissance to the scout subagent/i);\n\tassert.match(prompt, /0 scouts for narrow known-file work, 1 scout for one broad unfamiliar subsystem/i);\n\tassert.match(prompt, /For one scout use \\{ agent, task \\}/i);\n\tassert.match(prompt, /Scout is for mapping and reconnaissance only/i);\n\tassert.match(prompt, /multiple scout subagents in parallel/i);\n\tassert.match(prompt, /broad review or audit requests, use scout only as a prep step/i);\n\tassert.match(prompt, /Skip scout only when the task is clearly narrow/i);\n\tassert.match(prompt, /When the user names a subagent such as scout, worker, reviewer, or planner, invoke the subagent tool directly/i);\n});\n\n// ─── Regression: no backslash paths in LLM-visible text ────────────────────\n\n/**\n * Pattern that matches Windows-style absolute paths with backslashes.\n * Catches: C:\\Users\\..., D:\\Projects\\..., \\\\server\\share\\...\n * Does not match: escaped chars in regex, JSON strings, etc.\n */\nconst WINDOWS_ABS_PATH_RE = /[A-Z]:\\\\[A-Za-z]/;\n\ntest(\"buildSystemPrompt: no Windows absolute paths with backslashes in output\", () => {\n\t// Simulate a Windows-like cwd\n\tconst prompt = buildSystemPrompt({\n\t\tcwd: \"D:\\\\Projects\\\\my-app\\\\.gsd\\\\worktrees\\\\M002\",\n\t});\n\tconst lines = prompt.split(\"\\n\");\n\tconst violations = lines.filter(line => WINDOWS_ABS_PATH_RE.test(line));\n\tassert.equal(\n\t\tviolations.length, 0,\n\t\t`System prompt contains Windows backslash paths:\\n${violations.join(\"\\n\")}`,\n\t);\n});\n"]}
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gsd/pi-coding-agent",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Coding agent CLI (vendored from pi-mono)",
5
5
  "type": "module",
6
6
  "piConfig": {