@caupulican/pi-adaptative 0.93.10 → 0.93.11

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 (55) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
  3. package/dist/core/autonomy/envelope-enforcement.js +2 -0
  4. package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
  5. package/dist/core/fast-mode.d.ts +22 -0
  6. package/dist/core/fast-mode.d.ts.map +1 -0
  7. package/dist/core/fast-mode.js +37 -0
  8. package/dist/core/fast-mode.js.map +1 -0
  9. package/dist/core/goals/natural-language-goal.d.ts +1 -1
  10. package/dist/core/goals/natural-language-goal.d.ts.map +1 -1
  11. package/dist/core/goals/natural-language-goal.js +1 -1
  12. package/dist/core/goals/natural-language-goal.js.map +1 -1
  13. package/dist/core/sdk.d.ts.map +1 -1
  14. package/dist/core/sdk.js +3 -1
  15. package/dist/core/sdk.js.map +1 -1
  16. package/dist/core/secrets/credential-exposure-guard.js +3 -3
  17. package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
  18. package/dist/core/secrets/credential-source-discovery.d.ts +23 -0
  19. package/dist/core/secrets/credential-source-discovery.d.ts.map +1 -0
  20. package/dist/core/secrets/credential-source-discovery.js +187 -0
  21. package/dist/core/secrets/credential-source-discovery.js.map +1 -0
  22. package/dist/core/settings-manager.d.ts +4 -0
  23. package/dist/core/settings-manager.d.ts.map +1 -1
  24. package/dist/core/settings-manager.js +12 -0
  25. package/dist/core/settings-manager.js.map +1 -1
  26. package/dist/core/slash-commands.d.ts.map +1 -1
  27. package/dist/core/slash-commands.js +1 -0
  28. package/dist/core/slash-commands.js.map +1 -1
  29. package/dist/core/tool-capability-policy.js +1 -1
  30. package/dist/core/tool-capability-policy.js.map +1 -1
  31. package/dist/core/tools/goal.js +7 -7
  32. package/dist/core/tools/goal.js.map +1 -1
  33. package/dist/core/tools/secret-store.d.ts +8 -3
  34. package/dist/core/tools/secret-store.d.ts.map +1 -1
  35. package/dist/core/tools/secret-store.js +37 -6
  36. package/dist/core/tools/secret-store.js.map +1 -1
  37. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  38. package/dist/modes/interactive/components/footer.js +12 -3
  39. package/dist/modes/interactive/components/footer.js.map +1 -1
  40. package/dist/modes/interactive/fast-mode-command.d.ts +7 -0
  41. package/dist/modes/interactive/fast-mode-command.d.ts.map +1 -0
  42. package/dist/modes/interactive/fast-mode-command.js +32 -0
  43. package/dist/modes/interactive/fast-mode-command.js.map +1 -0
  44. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  45. package/dist/modes/interactive/interactive-mode.js +7 -0
  46. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  47. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  48. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  49. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  50. package/examples/extensions/sandbox/package-lock.json +2 -2
  51. package/examples/extensions/sandbox/package.json +1 -1
  52. package/examples/extensions/with-deps/package-lock.json +2 -2
  53. package/examples/extensions/with-deps/package.json +1 -1
  54. package/npm-shrinkwrap.json +12 -12
  55. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [0.93.11] - 2026-08-20
2
+
3
+ ### Added
4
+
5
+ - Added bounded model-blind credential discovery for the current working tree and process environment, so agents can locate and organize supported local secrets without asking owners for source paths or variable names.
6
+ - Added provider-native `/fast` controls with an enabled-state footer badge: OpenAI Codex and Grok use priority/default processing independently from reasoning effort.
7
+
8
+ ### Changed
9
+
10
+ - Durable goal creation is now available at agent discretion during ordinary owner turns while exact token budgets remain owner-controlled; explicit chat goal phrasing still starts goals directly.
11
+
1
12
  ## [0.93.10] - 2026-08-19
2
13
 
3
14
  ### Fixed
@@ -1 +1 @@
1
- {"version":3,"file":"envelope-enforcement.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/envelope-enforcement.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAezD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CAiB9D;AAED,wFAAwF;AACxF,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CAuBpF;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAoCxG;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACzC;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,kBAAkB,EACrE,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,kBAAkB,EAC5B,GAAG,EAAE,MAAM,GACT,CAAC,CA8BH"}
1
+ {"version":3,"file":"envelope-enforcement.d.ts","sourceRoot":"","sources":["../../../src/core/autonomy/envelope-enforcement.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAezD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CAiB9D;AAED,wFAAwF;AACxF,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,CAwBpF;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAoCxG;AAED,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;CACzC;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,kBAAkB,EACrE,IAAI,EAAE,CAAC,EACP,QAAQ,EAAE,kBAAkB,EAC5B,GAAG,EAAE,MAAM,GACT,CAAC,CA8BH"}
@@ -47,6 +47,8 @@ export function extractToolPathArguments(toolName, params) {
47
47
  paths.push(sourcePath.trim());
48
48
  }
49
49
  }
50
+ if (record.action === "discover" && paths.length === 0)
51
+ paths.push(".");
50
52
  }
51
53
  if (paths.length === 0 &&
52
54
  (normalizedToolName === "find" ||
@@ -1 +1 @@
1
- {"version":3,"file":"envelope-enforcement.js","sourceRoot":"","sources":["../../../src/core/autonomy/envelope-enforcement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;;;;;GAOG;AAEH,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAU,CAAC;AAC3G,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAU,CAAC;AAE5D,MAAM,UAAU,oBAAoB,CAAC,MAAe;IACnD,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACrD,MAAM,MAAM,GAAG,MAAiC,CAAC;IACjD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,OAAO,KAAK,KAAK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CACR;oCACC,IAAI,EAAE,MAAM;oCACZ,IAAI,EAAE,0BAA0B,OAAO,yBAAyB,QAAQ,CAAC,EAAE,sCAAsC;iCACjH;6BACD;4BACD,OAAO,EAAE;gCACR,OAAO,EAAE,sBAAsB;gCAC/B,IAAI,EAAE,IAAI,CAAC,IAAI;gCACf,IAAI,EAAE,OAAO;gCACb,UAAU,EAAE,QAAQ,CAAC,EAAE;6BACvB;4BACD,OAAO,EAAE,IAAI;yBACb,CAAC;oBACH,CAAC;gBACF,CAAC;YACF,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QAC9B,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { resolve } from \"node:path\";\nimport { resolveToolCallPathAccess } from \"../tool-capability-policy.ts\";\nimport type { CapabilityEnvelope } from \"./contracts.ts\";\nimport { isPathWithinScope, safeRealpathSync } from \"./path-scope.ts\";\n\n/**\n * Tool-level envelope enforcement (G2 prerequisite for code-writing workers): the capability\n * envelope's `allowedPaths`/`deniedPaths` were previously VALIDATION-ONLY — recorded on the\n * envelope but never checked when a tool actually ran. This module wraps tools so path-bearing\n * arguments are checked AT EXECUTION TIME, structurally refusing out-of-scope paths the same way\n * a failed script can never look like success: the refusal is an isError result with a stable\n * outcome code, never a silent no-op.\n */\n\nconst PATH_ARGUMENT_KEYS = [\"path\", \"file_path\", \"filePath\", \"cwd\", \"directory\", \"dir\", \"target\"] as const;\nconst PATH_LIST_ARGUMENT_KEYS = [\"paths\", \"files\"] as const;\n\nexport function extractPathArguments(params: unknown): string[] {\n\tif (!params || typeof params !== \"object\") return [];\n\tconst record = params as Record<string, unknown>;\n\tconst found: string[] = [];\n\tfor (const key of PATH_ARGUMENT_KEYS) {\n\t\tconst value = record[key];\n\t\tif (typeof value === \"string\" && value.trim()) found.push(value.trim());\n\t}\n\tfor (const key of PATH_LIST_ARGUMENT_KEYS) {\n\t\tconst value = record[key];\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const entry of value) {\n\t\t\t\tif (typeof entry === \"string\" && entry.trim()) found.push(entry.trim());\n\t\t\t}\n\t\t}\n\t}\n\treturn found;\n}\n\n/** Tool-aware path projection shared by every envelope/gateway enforcement boundary. */\nexport function extractToolPathArguments(toolName: string, params: unknown): string[] {\n\tconst normalizedToolName = toolName.toLowerCase();\n\tconst paths = extractPathArguments(params);\n\tif (normalizedToolName === \"secret_store\" && params && typeof params === \"object\") {\n\t\tconst record = params as Record<string, unknown>;\n\t\tif (record.action === \"migrate\" && Array.isArray(record.sources)) {\n\t\t\tfor (const source of record.sources) {\n\t\t\t\tif (!source || typeof source !== \"object\" || !(\"path\" in source)) continue;\n\t\t\t\tconst sourcePath = source.path;\n\t\t\t\tif (typeof sourcePath === \"string\" && sourcePath.trim()) paths.push(sourcePath.trim());\n\t\t\t}\n\t\t}\n\t}\n\tif (\n\t\tpaths.length === 0 &&\n\t\t(normalizedToolName === \"find\" ||\n\t\t\tnormalizedToolName === \"grep\" ||\n\t\t\tnormalizedToolName === \"ls\" ||\n\t\t\tnormalizedToolName === \"pipeline\")\n\t) {\n\t\tpaths.push(\".\");\n\t}\n\treturn paths;\n}\n\n/**\n * Deny wins over allow; an empty/absent allow list means \"no positive scope restriction\"\n * (only denies apply) — mirroring the resource-profile filter semantics.\n *\n * Both the target and every scope root are resolved through the real filesystem\n * (symlinks expanded in the existing prefix) before comparison: a pre-existing symlink\n * under an allowed root cannot smuggle a write outside the scope, and a shortcut into a\n * denied subtree is still denied. An unresolvable target fails closed.\n */\nexport function isPathWithinEnvelope(envelope: CapabilityEnvelope, rawPath: string, cwd: string): boolean {\n\tconst lexicalTarget = resolve(cwd, rawPath);\n\tconst allowed = envelope.allowedPaths ?? [];\n\tif (allowed.length > 0) {\n\t\tconst couldBeAllowed = allowed.some((root) => {\n\t\t\tconst lexicalRoot = resolve(cwd, root);\n\t\t\tif (isPathWithinScope(lexicalTarget, lexicalRoot)) return true;\n\t\t\ttry {\n\t\t\t\treturn isPathWithinScope(lexicalTarget, safeRealpathSync(lexicalRoot));\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\t\tif (!couldBeAllowed) return false;\n\t}\n\tlet target: string;\n\ttry {\n\t\ttarget = safeRealpathSync(lexicalTarget);\n\t} catch {\n\t\treturn false;\n\t}\n\tfor (const denied of envelope.deniedPaths ?? []) {\n\t\ttry {\n\t\t\tif (isPathWithinScope(target, safeRealpathSync(resolve(cwd, denied)))) return false;\n\t\t} catch {\n\t\t\t// Mirror checkPathScope: an unresolvable deny root cannot match anything.\n\t\t}\n\t}\n\tif (allowed.length === 0) return true;\n\treturn allowed.some((root) => {\n\t\ttry {\n\t\t\treturn isPathWithinScope(target, safeRealpathSync(resolve(cwd, root)));\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t});\n}\n\nexport interface EnvelopeScopedTool {\n\tname: string;\n\texecute: (...args: unknown[]) => unknown;\n}\n\n/**\n * Wrap a tool so path-bearing arguments are scope-checked when it RUNS, consulting canonical\n * tool capability policy so only tools whose policy declares path-scope access\n * (resolveToolCallPathAccess !== \"none\") are checked against envelope boundaries. The wrapped tool is\n * shape-identical; params are conventionally the second execute argument (toolCallId, params, …).\n */\nexport function wrapToolWithEnvelopeScope<T extends EnvelopeScopedTool>(\n\ttool: T,\n\tenvelope: CapabilityEnvelope,\n\tcwd: string,\n): T {\n\treturn {\n\t\t...tool,\n\t\texecute: (...args: unknown[]) => {\n\t\t\tconst params = args[1];\n\t\t\tconst pathAccess = resolveToolCallPathAccess(envelope.capabilities, tool.name, params);\n\t\t\tif (pathAccess !== \"none\") {\n\t\t\t\tfor (const rawPath of extractToolPathArguments(tool.name, params)) {\n\t\t\t\t\tif (!isPathWithinEnvelope(envelope, rawPath, cwd)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\ttext: `envelope_path_denied: \"${rawPath}\" is outside envelope ${envelope.id}'s path scope. The tool was NOT run.`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\toutcome: \"envelope_path_denied\",\n\t\t\t\t\t\t\t\ttool: tool.name,\n\t\t\t\t\t\t\t\tpath: rawPath,\n\t\t\t\t\t\t\t\tenvelopeId: envelope.id,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tisError: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tool.execute(...args);\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"envelope-enforcement.js","sourceRoot":"","sources":["../../../src/core/autonomy/envelope-enforcement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;;;;;;GAOG;AAEH,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAU,CAAC;AAC3G,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,OAAO,CAAU,CAAC;AAE5D,MAAM,UAAU,oBAAoB,CAAC,MAAe;IACnD,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACrD,MAAM,MAAM,GAAG,MAAiC,CAAC;IACjD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CA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,CAAC,oBAAoB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC;wBACnD,OAAO;4BACN,OAAO,EAAE;gCACR;oCACC,IAAI,EAAE,MAAM;oCACZ,IAAI,EAAE,0BAA0B,OAAO,yBAAyB,QAAQ,CAAC,EAAE,sCAAsC;iCACjH;6BACD;4BACD,OAAO,EAAE;gCACR,OAAO,EAAE,sBAAsB;gCAC/B,IAAI,EAAE,IAAI,CAAC,IAAI;gCACf,IAAI,EAAE,OAAO;gCACb,UAAU,EAAE,QAAQ,CAAC,EAAE;6BACvB;4BACD,OAAO,EAAE,IAAI;yBACb,CAAC;oBACH,CAAC;gBACF,CAAC;YACF,CAAC;YACD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QAC9B,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { resolve } from \"node:path\";\nimport { resolveToolCallPathAccess } from \"../tool-capability-policy.ts\";\nimport type { CapabilityEnvelope } from \"./contracts.ts\";\nimport { isPathWithinScope, safeRealpathSync } from \"./path-scope.ts\";\n\n/**\n * Tool-level envelope enforcement (G2 prerequisite for code-writing workers): the capability\n * envelope's `allowedPaths`/`deniedPaths` were previously VALIDATION-ONLY — recorded on the\n * envelope but never checked when a tool actually ran. This module wraps tools so path-bearing\n * arguments are checked AT EXECUTION TIME, structurally refusing out-of-scope paths the same way\n * a failed script can never look like success: the refusal is an isError result with a stable\n * outcome code, never a silent no-op.\n */\n\nconst PATH_ARGUMENT_KEYS = [\"path\", \"file_path\", \"filePath\", \"cwd\", \"directory\", \"dir\", \"target\"] as const;\nconst PATH_LIST_ARGUMENT_KEYS = [\"paths\", \"files\"] as const;\n\nexport function extractPathArguments(params: unknown): string[] {\n\tif (!params || typeof params !== \"object\") return [];\n\tconst record = params as Record<string, unknown>;\n\tconst found: string[] = [];\n\tfor (const key of PATH_ARGUMENT_KEYS) {\n\t\tconst value = record[key];\n\t\tif (typeof value === \"string\" && value.trim()) found.push(value.trim());\n\t}\n\tfor (const key of PATH_LIST_ARGUMENT_KEYS) {\n\t\tconst value = record[key];\n\t\tif (Array.isArray(value)) {\n\t\t\tfor (const entry of value) {\n\t\t\t\tif (typeof entry === \"string\" && entry.trim()) found.push(entry.trim());\n\t\t\t}\n\t\t}\n\t}\n\treturn found;\n}\n\n/** Tool-aware path projection shared by every envelope/gateway enforcement boundary. */\nexport function extractToolPathArguments(toolName: string, params: unknown): string[] {\n\tconst normalizedToolName = toolName.toLowerCase();\n\tconst paths = extractPathArguments(params);\n\tif (normalizedToolName === \"secret_store\" && params && typeof params === \"object\") {\n\t\tconst record = params as Record<string, unknown>;\n\t\tif (record.action === \"migrate\" && Array.isArray(record.sources)) {\n\t\t\tfor (const source of record.sources) {\n\t\t\t\tif (!source || typeof source !== \"object\" || !(\"path\" in source)) continue;\n\t\t\t\tconst sourcePath = source.path;\n\t\t\t\tif (typeof sourcePath === \"string\" && sourcePath.trim()) paths.push(sourcePath.trim());\n\t\t\t}\n\t\t}\n\t\tif (record.action === \"discover\" && paths.length === 0) paths.push(\".\");\n\t}\n\tif (\n\t\tpaths.length === 0 &&\n\t\t(normalizedToolName === \"find\" ||\n\t\t\tnormalizedToolName === \"grep\" ||\n\t\t\tnormalizedToolName === \"ls\" ||\n\t\t\tnormalizedToolName === \"pipeline\")\n\t) {\n\t\tpaths.push(\".\");\n\t}\n\treturn paths;\n}\n\n/**\n * Deny wins over allow; an empty/absent allow list means \"no positive scope restriction\"\n * (only denies apply) — mirroring the resource-profile filter semantics.\n *\n * Both the target and every scope root are resolved through the real filesystem\n * (symlinks expanded in the existing prefix) before comparison: a pre-existing symlink\n * under an allowed root cannot smuggle a write outside the scope, and a shortcut into a\n * denied subtree is still denied. An unresolvable target fails closed.\n */\nexport function isPathWithinEnvelope(envelope: CapabilityEnvelope, rawPath: string, cwd: string): boolean {\n\tconst lexicalTarget = resolve(cwd, rawPath);\n\tconst allowed = envelope.allowedPaths ?? [];\n\tif (allowed.length > 0) {\n\t\tconst couldBeAllowed = allowed.some((root) => {\n\t\t\tconst lexicalRoot = resolve(cwd, root);\n\t\t\tif (isPathWithinScope(lexicalTarget, lexicalRoot)) return true;\n\t\t\ttry {\n\t\t\t\treturn isPathWithinScope(lexicalTarget, safeRealpathSync(lexicalRoot));\n\t\t\t} catch {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t});\n\t\tif (!couldBeAllowed) return false;\n\t}\n\tlet target: string;\n\ttry {\n\t\ttarget = safeRealpathSync(lexicalTarget);\n\t} catch {\n\t\treturn false;\n\t}\n\tfor (const denied of envelope.deniedPaths ?? []) {\n\t\ttry {\n\t\t\tif (isPathWithinScope(target, safeRealpathSync(resolve(cwd, denied)))) return false;\n\t\t} catch {\n\t\t\t// Mirror checkPathScope: an unresolvable deny root cannot match anything.\n\t\t}\n\t}\n\tif (allowed.length === 0) return true;\n\treturn allowed.some((root) => {\n\t\ttry {\n\t\t\treturn isPathWithinScope(target, safeRealpathSync(resolve(cwd, root)));\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t});\n}\n\nexport interface EnvelopeScopedTool {\n\tname: string;\n\texecute: (...args: unknown[]) => unknown;\n}\n\n/**\n * Wrap a tool so path-bearing arguments are scope-checked when it RUNS, consulting canonical\n * tool capability policy so only tools whose policy declares path-scope access\n * (resolveToolCallPathAccess !== \"none\") are checked against envelope boundaries. The wrapped tool is\n * shape-identical; params are conventionally the second execute argument (toolCallId, params, …).\n */\nexport function wrapToolWithEnvelopeScope<T extends EnvelopeScopedTool>(\n\ttool: T,\n\tenvelope: CapabilityEnvelope,\n\tcwd: string,\n): T {\n\treturn {\n\t\t...tool,\n\t\texecute: (...args: unknown[]) => {\n\t\t\tconst params = args[1];\n\t\t\tconst pathAccess = resolveToolCallPathAccess(envelope.capabilities, tool.name, params);\n\t\t\tif (pathAccess !== \"none\") {\n\t\t\t\tfor (const rawPath of extractToolPathArguments(tool.name, params)) {\n\t\t\t\t\tif (!isPathWithinEnvelope(envelope, rawPath, cwd)) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tcontent: [\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\t\t\ttext: `envelope_path_denied: \"${rawPath}\" is outside envelope ${envelope.id}'s path scope. The tool was NOT run.`,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\toutcome: \"envelope_path_denied\",\n\t\t\t\t\t\t\t\ttool: tool.name,\n\t\t\t\t\t\t\t\tpath: rawPath,\n\t\t\t\t\t\t\t\tenvelopeId: envelope.id,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tisError: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn tool.execute(...args);\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import type { Api, Model, ServiceTier } from "@caupulican/pi-ai";
2
+ export type FastModeKind = "service-tier";
3
+ interface FastModeSettings {
4
+ getFastModeEnabled(provider: string): boolean | undefined;
5
+ setFastModeEnabled(provider: string, enabled: boolean): void;
6
+ }
7
+ export interface FastModeSession {
8
+ readonly model: Model<Api> | undefined;
9
+ readonly settingsManager: FastModeSettings;
10
+ }
11
+ export interface FastModeStatus {
12
+ available: boolean;
13
+ changed: boolean;
14
+ enabled: boolean;
15
+ kind?: FastModeKind;
16
+ }
17
+ export declare function getFastModeStatus(session: FastModeSession): FastModeStatus;
18
+ export declare function setFastMode(session: FastModeSession, enabled: boolean): FastModeStatus;
19
+ export declare function toggleFastMode(session: FastModeSession): FastModeStatus;
20
+ export declare function resolveFastModeServiceTier(model: Model<Api>, preference: boolean | undefined): ServiceTier | undefined;
21
+ export {};
22
+ //# sourceMappingURL=fast-mode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fast-mode.d.ts","sourceRoot":"","sources":["../../src/core/fast-mode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEjE,MAAM,MAAM,YAAY,GAAG,cAAc,CAAC;AAE1C,UAAU,gBAAgB;IACzB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IAC1D,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CAC7D;AAED,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CAAC;CAC3C;AAED,MAAM,WAAW,cAAc;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,YAAY,CAAC;CACpB;AAMD,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAU1E;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,GAAG,cAAc,CAatF;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc,CAGvE;AAED,wBAAgB,0BAA0B,CACzC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,UAAU,EAAE,OAAO,GAAG,SAAS,GAC7B,WAAW,GAAG,SAAS,CAGzB"}
@@ -0,0 +1,37 @@
1
+ function supportsFastMode(model) {
2
+ return model?.provider === "openai-codex" || (model?.provider === "xai" && model.api === "openai-responses");
3
+ }
4
+ export function getFastModeStatus(session) {
5
+ if (!supportsFastMode(session.model) || !session.model) {
6
+ return { available: false, changed: false, enabled: false };
7
+ }
8
+ return {
9
+ available: true,
10
+ changed: false,
11
+ enabled: session.settingsManager.getFastModeEnabled(session.model.provider) ?? false,
12
+ kind: "service-tier",
13
+ };
14
+ }
15
+ export function setFastMode(session, enabled) {
16
+ if (!supportsFastMode(session.model) || !session.model) {
17
+ return { available: false, changed: false, enabled: false };
18
+ }
19
+ const previousPreference = session.settingsManager.getFastModeEnabled(session.model.provider);
20
+ session.settingsManager.setFastModeEnabled(session.model.provider, enabled);
21
+ return {
22
+ available: true,
23
+ changed: previousPreference !== enabled,
24
+ enabled,
25
+ kind: "service-tier",
26
+ };
27
+ }
28
+ export function toggleFastMode(session) {
29
+ const status = getFastModeStatus(session);
30
+ return status.available ? setFastMode(session, !status.enabled) : status;
31
+ }
32
+ export function resolveFastModeServiceTier(model, preference) {
33
+ if (!supportsFastMode(model) || preference === undefined)
34
+ return undefined;
35
+ return preference ? "priority" : "default";
36
+ }
37
+ //# sourceMappingURL=fast-mode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fast-mode.js","sourceRoot":"","sources":["../../src/core/fast-mode.ts"],"names":[],"mappings":"AAqBA,SAAS,gBAAgB,CAAC,KAA6B;IACtD,OAAO,KAAK,EAAE,QAAQ,KAAK,cAAc,IAAI,CAAC,KAAK,EAAE,QAAQ,KAAK,KAAK,IAAI,KAAK,CAAC,GAAG,KAAK,kBAAkB,CAAC,CAAC;AAC9G,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,OAAwB;IACzD,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACxD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC7D,CAAC;IACD,OAAO;QACN,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,KAAK;QACpF,IAAI,EAAE,cAAc;KACpB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,OAAwB,EAAE,OAAgB;IACrE,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACxD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC7D,CAAC;IAED,MAAM,kBAAkB,GAAG,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC9F,OAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC5E,OAAO;QACN,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,kBAAkB,KAAK,OAAO;QACvC,OAAO;QACP,IAAI,EAAE,cAAc;KACpB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,OAAwB;IACtD,MAAM,MAAM,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,0BAA0B,CACzC,KAAiB,EACjB,UAA+B;IAE/B,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC3E,OAAO,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5C,CAAC","sourcesContent":["import type { Api, Model, ServiceTier } from \"@caupulican/pi-ai\";\n\nexport type FastModeKind = \"service-tier\";\n\ninterface FastModeSettings {\n\tgetFastModeEnabled(provider: string): boolean | undefined;\n\tsetFastModeEnabled(provider: string, enabled: boolean): void;\n}\n\nexport interface FastModeSession {\n\treadonly model: Model<Api> | undefined;\n\treadonly settingsManager: FastModeSettings;\n}\n\nexport interface FastModeStatus {\n\tavailable: boolean;\n\tchanged: boolean;\n\tenabled: boolean;\n\tkind?: FastModeKind;\n}\n\nfunction supportsFastMode(model: Model<Api> | undefined): boolean {\n\treturn model?.provider === \"openai-codex\" || (model?.provider === \"xai\" && model.api === \"openai-responses\");\n}\n\nexport function getFastModeStatus(session: FastModeSession): FastModeStatus {\n\tif (!supportsFastMode(session.model) || !session.model) {\n\t\treturn { available: false, changed: false, enabled: false };\n\t}\n\treturn {\n\t\tavailable: true,\n\t\tchanged: false,\n\t\tenabled: session.settingsManager.getFastModeEnabled(session.model.provider) ?? false,\n\t\tkind: \"service-tier\",\n\t};\n}\n\nexport function setFastMode(session: FastModeSession, enabled: boolean): FastModeStatus {\n\tif (!supportsFastMode(session.model) || !session.model) {\n\t\treturn { available: false, changed: false, enabled: false };\n\t}\n\n\tconst previousPreference = session.settingsManager.getFastModeEnabled(session.model.provider);\n\tsession.settingsManager.setFastModeEnabled(session.model.provider, enabled);\n\treturn {\n\t\tavailable: true,\n\t\tchanged: previousPreference !== enabled,\n\t\tenabled,\n\t\tkind: \"service-tier\",\n\t};\n}\n\nexport function toggleFastMode(session: FastModeSession): FastModeStatus {\n\tconst status = getFastModeStatus(session);\n\treturn status.available ? setFastMode(session, !status.enabled) : status;\n}\n\nexport function resolveFastModeServiceTier(\n\tmodel: Model<Api>,\n\tpreference: boolean | undefined,\n): ServiceTier | undefined {\n\tif (!supportsFastMode(model) || preference === undefined) return undefined;\n\treturn preference ? \"priority\" : \"default\";\n}\n"]}
@@ -29,6 +29,6 @@ export declare function priorUserPromptText(messages: readonly {
29
29
  content?: unknown;
30
30
  }[], currentText: string): string | undefined;
31
31
  export declare function parseExplicitChatGoal(text: string, priorUserText?: string): ExplicitChatGoal | undefined;
32
- /** Exact owner authority for model-facing goal creation; ordinary work and meta-discussion fail closed. */
32
+ /** Exact owner authority for model-supplied token budgets; ordinary work carries no budget authority. */
33
33
  export declare function parseExplicitGoalStartAuthority(text: string): ExplicitGoalStartAuthority | undefined;
34
34
  //# sourceMappingURL=natural-language-goal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"natural-language-goal.d.ts","sourceRoot":"","sources":["../../../src/core/goals/natural-language-goal.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,0BAA0B;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAkCD;;2CAE2C;AAC3C,qBAAa,yBAA0B,SAAQ,KAAK;IACnD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAsED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACxC,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACxC,MAAM,GAAG,SAAS,CAMpB;AAyED,gFAAgF;AAChF,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,EACxD,WAAW,EAAE,MAAM,GACjB,MAAM,GAAG,SAAS,CAUpB;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CA4BxG;AAED,2GAA2G;AAC3G,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,GAAG,0BAA0B,GAAG,SAAS,CAMpG"}
1
+ {"version":3,"file":"natural-language-goal.d.ts","sourceRoot":"","sources":["../../../src/core/goals/natural-language-goal.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,0BAA0B;IAC1C,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAkCD;;2CAE2C;AAC3C,qBAAa,yBAA0B,SAAQ,KAAK;IACnD,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAsED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACxC,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACxC,MAAM,GAAG,SAAS,CAMpB;AAyED,gFAAgF;AAChF,wBAAgB,mBAAmB,CAClC,QAAQ,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,EAAE,EACxD,WAAW,EAAE,MAAM,GACjB,MAAM,GAAG,SAAS,CAUpB;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CA4BxG;AAED,yGAAyG;AACzG,wBAAgB,+BAA+B,CAAC,IAAI,EAAE,MAAM,GAAG,0BAA0B,GAAG,SAAS,CAMpG"}
@@ -237,7 +237,7 @@ export function parseExplicitChatGoal(text, priorUserText) {
237
237
  return undefined;
238
238
  return { objective, ...(tokenBudget !== undefined ? { tokenBudget } : {}) };
239
239
  }
240
- /** Exact owner authority for model-facing goal creation; ordinary work and meta-discussion fail closed. */
240
+ /** Exact owner authority for model-supplied token budgets; ordinary work carries no budget authority. */
241
241
  export function parseExplicitGoalStartAuthority(text) {
242
242
  const goal = parseExplicitChatGoal(text);
243
243
  if (goal)
@@ -1 +1 @@
1
- {"version":3,"file":"natural-language-goal.js","sourceRoot":"","sources":["../../../src/core/goals/natural-language-goal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBA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AAM,WAAW,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAAC;IACpD,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import { MAX_GOAL_OBJECTIVE_LENGTH } from \"./goal-state.ts\";\n\nexport interface ExplicitChatGoal {\n\tobjective: string;\n\ttokenBudget?: number;\n}\n\nexport interface ExplicitGoalStartAuthority {\n\ttokenBudget?: number;\n}\n\nconst EXPLICIT_GOAL_PATTERNS = [\n\t/^\\s*set\\s+(?:this\\s+as\\s+)?a\\s+(?:persistent\\s+)?goal\\s*(?::|to\\s+)\\s*(.+)$/is,\n\t/^\\s*my\\s+persistent\\s+goal\\s+is\\s+to\\s+(.+)$/is,\n\t/^\\s*(?:the|our)\\s+(?:persistent\\s+)?goal\\s+is\\s+to\\s+(.+)$/is,\n\t/^\\s*treat\\s+this\\s+as\\s+my\\s+(?:persistent\\s+)?goal\\s*:\\s*(.+)$/is,\n\t/^\\s*i\\s+want\\s+this\\s+as\\s+(?:my\\s+)?(?:persistent\\s+)?goal\\s*:\\s*(.+)$/is,\n\t/^\\s*keep\\s+working\\s+until\\s+this\\s+is\\s+(?:complete|done)\\s*:\\s*(.+)$/is,\n\t/^\\s*instead of .+,\\s*i want to (.+)$/is,\n\t/^\\s*i want to ((?:refactor|rewrite|rebuild|redesign)\\b.+)$/is,\n] as const;\n\nconst STANDALONE_GOAL_AUTHORITY_PATTERNS = [\n\t// After \"goal\" require end, whitespace, or punctuation — not a hyphen — so\n\t// \"this is a goal, use it\" authorizes while \"this is a goal-oriented design\" does not.\n\t/^\\s*(?:this|that)\\s+is\\s+(?:now\\s+)?a\\s+(?:persistent\\s+)?goal(?=[\\s,.:;!?]|$)/is,\n\t/^\\s*(?:this|the|that)\\s+task\\s+is\\s+(?:now\\s+)?a\\s+(?:persistent\\s+)?goal(?=[\\s,.:;!?]|$)/is,\n\t/^\\s*(?:make|treat)\\s+this\\s+(?:as\\s+)?(?:my\\s+|a\\s+)?(?:persistent\\s+)?goal(?=[\\s,.:;!?]|$)/is,\n\t/^\\s*(?:make|treat)\\s+this\\s+task\\s+(?:as\\s+)?(?:my\\s+|a\\s+)?(?:persistent\\s+)?goal(?=[\\s,.:;!?]|$)/is,\n] as const;\n\nconst STANDALONE_GOAL_FILLER = /^(?:use it|please|now|ok|okay|thanks|go|do it)(?:[.!?])?$/i;\n\nconst STANDALONE_GOAL_PROCESS_PHRASES = [\n\t/\\bby the way\\b/gi,\n\t/\\bi(?:'m| am) handing (?:(?:this|it) )?over(?: to you)?\\b/gi,\n\t/\\bhand(?:ing)? (?:(?:this|it) )?over(?: to you)?\\b/gi,\n\t/\\buse max(?:imum)? \\d+ sub[-\\s]?agents?\\b/gi,\n\t/\\byou are (?:the )?(?:orchestrator|reviewer|team lead)(?:(?:\\s+and|\\s*,)\\s*(?:also\\s+)?(?:the\\s+)?(?:orchestrator|reviewer|team lead))*\\b/gi,\n\t/\\bhelp you deliver\\b/gi,\n\t/\\b(?:orchestrator|reviewer|team lead)\\b/gi,\n] as const;\n\n/** Raised when text unambiguously states a token-budget directive but the amount cannot be resolved\n * to an exact positive integer. Callers must let this propagate as a loud, explicit failure instead\n * of falling back to an unbounded goal. */\nexport class GoalTokenBudgetParseError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"GoalTokenBudgetParseError\";\n\t}\n}\n\nconst TOKEN_UNIT_MULTIPLIERS: Record<string, number> = {\n\tk: 1_000,\n\tthousand: 1_000,\n\tm: 1_000_000,\n\tmillion: 1_000_000,\n};\n\n/**\n * Resolve a matched numeral into a plain integer, disambiguating a thousands separator from a\n * decimal point. Comma is never a decimal point in this grammar, so any comma-grouped digits\n * (e.g. \"5,000\") are treated as a separator. A dot is genuinely ambiguous (\"1.5\" vs \"1.000.000\"),\n * so it is only treated as a separator when the exactly-3-digit group repeats (e.g. \"1.000.000\");\n * a single dot group falls back to a literal decimal (e.g. \"1.5\", or \"1.000\" read as 1).\n */\nfunction normalizeTokenNumeral(raw: string): number | undefined {\n\t// The caller's capture regex allows \",\" \"_\" \".\" to continue a numeral (they can be internal\n\t// separators), so it greedily swallows a trailing one that is NOT followed by more digits — e.g.\n\t// the sentence-ending \".\" after a dot-grouped \"1.000.000.\" A separator is only ever meaningful\n\t// between digits, so a trailing one is always incidental punctuation; drop it before classifying.\n\tconst compact = raw.replace(/_/g, \"\").replace(/[,.]+$/, \"\");\n\tif (/^[0-9]+$/.test(compact)) return Number(compact);\n\tif (/^[0-9]{1,3}(,[0-9]{3})+\\.[0-9]+$/.test(compact)) return Number(compact.replace(/,/g, \"\"));\n\tif (/^[0-9]{1,3}(,[0-9]{3})+$/.test(compact)) return Number(compact.replace(/,/g, \"\"));\n\tif (/^[0-9]{1,3}(\\.[0-9]{3}){2,}$/.test(compact)) return Number(compact.replace(/\\./g, \"\"));\n\tif (/^[0-9]+\\.[0-9]+$/.test(compact)) return Number(compact);\n\treturn undefined;\n}\n\nfunction parsePositiveTokenCount(raw: string, unit: string | undefined): number | undefined {\n\tconst value = normalizeTokenNumeral(raw);\n\tif (value === undefined) return undefined;\n\tconst multiplier = unit ? (TOKEN_UNIT_MULTIPLIERS[unit.toLowerCase()] ?? 1) : 1;\n\tconst tokens = value * multiplier;\n\treturn Number.isSafeInteger(tokens) && tokens > 0 ? tokens : undefined;\n}\n\nconst TOKEN_BUDGET_PATTERNS = [\n\t/\\btoken\\s+budget\\s*(?:of|is|:|=)?\\s*([0-9][0-9,_.]*)(?:\\s*(thousand|million|k|m)\\b)?/i,\n\t/\\b([0-9][0-9,_.]*)(?:\\s*(thousand|million|k|m)\\b)?\\s*(?:token|tokens)\\s+budget\\b/i,\n\t/\\bbudget\\s*(?:of|is|:|=)?\\s*([0-9][0-9,_.]*)(?:\\s*(thousand|million|k|m)\\b)?\\s*(?:token|tokens)\\b/i,\n] as const;\n\n/**\n * Scan `text` for one explicit token-budget directive. When `trailingOnly` is set, a match only\n * counts if it runs to the end of `text` (ignoring closing punctuation/whitespace) — used to scan\n * inside a captured goal objective, where a budget-shaped phrase embedded mid-sentence usually\n * describes the task's subject matter (e.g. a constant being edited in code), not the agent's own\n * execution ceiling, whereas a trailing clause (\"... with a 40k token budget.\") is a real directive.\n */\nfunction scanTokenBudget(text: string, options: { trailingOnly: boolean }): number | undefined {\n\tfor (const pattern of TOKEN_BUDGET_PATTERNS) {\n\t\tconst match = pattern.exec(text);\n\t\tif (!match) continue;\n\t\tif (options.trailingOnly) {\n\t\t\tconst tail = text.slice(match.index + match[0].length);\n\t\t\tif (!/^[.!?]?\\s*$/.test(tail)) continue;\n\t\t}\n\t\tconst tokens = parsePositiveTokenCount(match[1], match[2]);\n\t\tif (tokens === undefined) {\n\t\t\tthrow new GoalTokenBudgetParseError(\n\t\t\t\t`Token budget phrase \"${match[0].trim()}\" could not be parsed into an exact token ceiling.`,\n\t\t\t);\n\t\t}\n\t\treturn tokens;\n\t}\n\treturn undefined;\n}\n\n/**\n * Parse an explicit token-budget directive from `text`. When `objective` locates a captured goal\n * objective within `text`, a budget-shaped phrase found INSIDE it only counts when it is the\n * trailing clause of the objective; text outside the objective (the prefix/suffix around it) is\n * scanned without that restriction. This keeps a genuine directive (\"... with a 40k token budget.\")\n * working while refusing to adopt a number that is merely part of the task's own subject matter\n * (\"raise the model token budget of 4096 ... to 8192\").\n */\nexport function parseRequestedTokenBudget(\n\ttext: string,\n\tobjective?: { start: number; end: number },\n): number | undefined {\n\tif (!objective) return scanTokenBudget(text, { trailingOnly: false });\n\tconst outside = `${text.slice(0, objective.start)} ${text.slice(objective.end)}`;\n\tconst outsideBudget = scanTokenBudget(outside, { trailingOnly: false });\n\tif (outsideBudget !== undefined) return outsideBudget;\n\treturn scanTokenBudget(text.slice(objective.start, objective.end), { trailingOnly: true });\n}\n\n/**\n * Recognize only explicit persistence language. Ordinary multi-step work and discussion ABOUT goal\n * mechanics deliberately return undefined; those must not silently expand into autonomous work.\n */\nfunction standaloneGoalRemainder(text: string): string | undefined {\n\tfor (const pattern of STANDALONE_GOAL_AUTHORITY_PATTERNS) {\n\t\tconst match = pattern.exec(text);\n\t\tif (!match) continue;\n\t\treturn text\n\t\t\t.slice(match.index + match[0].length)\n\t\t\t.replace(/^[\\s,.:;!?-]+/, \"\")\n\t\t\t.replace(/^(?:and|then|so)\\s+/i, \"\")\n\t\t\t.trim();\n\t}\n\treturn undefined;\n}\n\nfunction remainderWithoutBudgetPhrase(remainder: string): string {\n\tlet next = remainder;\n\tfor (const pattern of TOKEN_BUDGET_PATTERNS) {\n\t\tnext = next.replace(pattern, \" \");\n\t}\n\treturn next\n\t\t.replace(/\\b(?:with|of|is|a|the|:|=)\\b/gi, \" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n}\n\nfunction remainderWithoutProcessPhrases(remainder: string): string {\n\tlet next = remainder;\n\tfor (const pattern of STANDALONE_GOAL_PROCESS_PHRASES) {\n\t\tnext = next.replace(pattern, \" \");\n\t}\n\treturn next\n\t\t.replace(/\\b(?:with|of|is|a|the|to|and|also|you|i|i'm|:|=)\\b/gi, \" \")\n\t\t.replace(/[.,:;!?]/g, \" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n}\n\nfunction isClassificationRemainder(remainder: string): boolean {\n\tif (!remainder || STANDALONE_GOAL_FILLER.test(remainder)) return true;\n\tconst leftover = remainderWithoutProcessPhrases(remainder);\n\tif (!leftover || STANDALONE_GOAL_FILLER.test(leftover)) return true;\n\ttry {\n\t\tif (parseRequestedTokenBudget(remainder) === undefined) return false;\n\t} catch {\n\t\treturn false;\n\t}\n\tconst afterBudget = remainderWithoutBudgetPhrase(leftover);\n\treturn afterBudget.length === 0 || STANDALONE_GOAL_FILLER.test(afterBudget);\n}\n\nfunction userMessageText(content: unknown): string {\n\tif (typeof content === \"string\") return content.trim();\n\tif (!Array.isArray(content)) return \"\";\n\treturn content\n\t\t.filter(\n\t\t\t(block): block is { type: \"text\"; text: string } =>\n\t\t\t\ttypeof block === \"object\" &&\n\t\t\t\tblock !== null &&\n\t\t\t\t\"type\" in block &&\n\t\t\t\tblock.type === \"text\" &&\n\t\t\t\t\"text\" in block &&\n\t\t\t\ttypeof block.text === \"string\",\n\t\t)\n\t\t.map((block) => block.text)\n\t\t.join(\"\")\n\t\t.trim();\n}\n\n/** Latest owner prompt that is not the current classification phrase itself. */\nexport function priorUserPromptText(\n\tmessages: readonly { role: string; content?: unknown }[],\n\tcurrentText: string,\n): string | undefined {\n\tconst current = currentText.trim();\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst message = messages[index];\n\t\tif (message.role !== \"user\") continue;\n\t\tconst text = userMessageText(message.content);\n\t\tif (!text || text === current) continue;\n\t\treturn text;\n\t}\n\treturn undefined;\n}\n\nexport function parseExplicitChatGoal(text: string, priorUserText?: string): ExplicitChatGoal | undefined {\n\tfor (const pattern of EXPLICIT_GOAL_PATTERNS) {\n\t\tconst match = pattern.exec(text);\n\t\tconst rawObjective = match?.[1];\n\t\tconst objective = rawObjective?.trim();\n\t\tif (!match || !objective || objective.length > MAX_GOAL_OBJECTIVE_LENGTH) continue;\n\t\t// rawObjective is always a suffix of match[0] (every pattern ends in `(.+)$`), so its start\n\t\t// offset in `text` is match[0]'s length minus its own length.\n\t\tconst objectiveSpan = {\n\t\t\tstart: match.index + (match[0].length - (rawObjective?.length ?? 0)),\n\t\t\tend: match.index + match[0].length,\n\t\t};\n\t\tconst tokenBudget = parseRequestedTokenBudget(text, objectiveSpan);\n\t\treturn { objective, ...(tokenBudget !== undefined ? { tokenBudget } : {}) };\n\t}\n\tconst remainder = standaloneGoalRemainder(text);\n\tif (remainder === undefined) return undefined;\n\tconst tokenBudget = parseRequestedTokenBudget(text);\n\tconst inline = remainder && !isClassificationRemainder(remainder) ? remainder : undefined;\n\tconst prior = priorUserText?.trim();\n\tconst objective =\n\t\tinline && inline.length <= MAX_GOAL_OBJECTIVE_LENGTH\n\t\t\t? inline\n\t\t\t: prior && prior !== text.trim() && prior.length <= MAX_GOAL_OBJECTIVE_LENGTH\n\t\t\t\t? prior\n\t\t\t\t: undefined;\n\tif (!objective) return undefined;\n\treturn { objective, ...(tokenBudget !== undefined ? { tokenBudget } : {}) };\n}\n\n/** Exact owner authority for model-facing goal creation; ordinary work and meta-discussion fail closed. */\nexport function parseExplicitGoalStartAuthority(text: string): ExplicitGoalStartAuthority | undefined {\n\tconst goal = parseExplicitChatGoal(text);\n\tif (goal) return goal.tokenBudget === undefined ? {} : { tokenBudget: goal.tokenBudget };\n\tif (!STANDALONE_GOAL_AUTHORITY_PATTERNS.some((pattern) => pattern.test(text))) return undefined;\n\tconst tokenBudget = parseRequestedTokenBudget(text);\n\treturn tokenBudget === undefined ? {} : { tokenBudget };\n}\n"]}
1
+ {"version":3,"file":"natural-language-goal.js","sourceRoot":"","sources":["../../../src/core/goals/natural-language-goal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAW5D,MAAM,sBAAsB,GAAG;IAC9B,+EAA+E;IAC/E,gDAAgD;IAChD,8DAA8D;IAC9D,mEAAmE;IACnE,2EAA2E;IAC3E,0EAA0E;IAC1E,wCAAwC;IACxC,8DAA8D;CACrD,CAAC;AAEX,MAAM,kCAAkC,GAAG;IAC1C,2EAA2E;IAC3E,uFAAuF;IACvF,kFAAkF;IAClF,6FAA6F;IAC7F,+FAA+F;IAC/F,sGAAsG;CAC7F,CAAC;AAEX,MAAM,sBAAsB,GAAG,4DAA4D,CAAC;AAE5F,MAAM,+BAA+B,GAAG;IACvC,kBAAkB;IAClB,6DAA6D;IAC7D,sDAAsD;IACtD,6CAA6C;IAC7C,6IAA6I;IAC7I,wBAAwB;IACxB,2CAA2C;CAClC,CAAC;AAEX;;2CAE2C;AAC3C,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IACnD,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG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,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IACjC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC7E,CAAC;AAED,yGAAyG;AACzG,MAAM,UAAU,+BAA+B,CAAC,IAAY;IAC3D,MAAM,IAAI,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACzC,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC;IACzF,IAAI,CAAC,kCAAkC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IAChG,MAAM,WAAW,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAAC;IACpD,OAAO,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC;AACzD,CAAC","sourcesContent":["import { MAX_GOAL_OBJECTIVE_LENGTH } from \"./goal-state.ts\";\n\nexport interface ExplicitChatGoal {\n\tobjective: string;\n\ttokenBudget?: number;\n}\n\nexport interface ExplicitGoalStartAuthority {\n\ttokenBudget?: number;\n}\n\nconst EXPLICIT_GOAL_PATTERNS = [\n\t/^\\s*set\\s+(?:this\\s+as\\s+)?a\\s+(?:persistent\\s+)?goal\\s*(?::|to\\s+)\\s*(.+)$/is,\n\t/^\\s*my\\s+persistent\\s+goal\\s+is\\s+to\\s+(.+)$/is,\n\t/^\\s*(?:the|our)\\s+(?:persistent\\s+)?goal\\s+is\\s+to\\s+(.+)$/is,\n\t/^\\s*treat\\s+this\\s+as\\s+my\\s+(?:persistent\\s+)?goal\\s*:\\s*(.+)$/is,\n\t/^\\s*i\\s+want\\s+this\\s+as\\s+(?:my\\s+)?(?:persistent\\s+)?goal\\s*:\\s*(.+)$/is,\n\t/^\\s*keep\\s+working\\s+until\\s+this\\s+is\\s+(?:complete|done)\\s*:\\s*(.+)$/is,\n\t/^\\s*instead of .+,\\s*i want to (.+)$/is,\n\t/^\\s*i want to ((?:refactor|rewrite|rebuild|redesign)\\b.+)$/is,\n] as const;\n\nconst STANDALONE_GOAL_AUTHORITY_PATTERNS = [\n\t// After \"goal\" require end, whitespace, or punctuation — not a hyphen — so\n\t// \"this is a goal, use it\" authorizes while \"this is a goal-oriented design\" does not.\n\t/^\\s*(?:this|that)\\s+is\\s+(?:now\\s+)?a\\s+(?:persistent\\s+)?goal(?=[\\s,.:;!?]|$)/is,\n\t/^\\s*(?:this|the|that)\\s+task\\s+is\\s+(?:now\\s+)?a\\s+(?:persistent\\s+)?goal(?=[\\s,.:;!?]|$)/is,\n\t/^\\s*(?:make|treat)\\s+this\\s+(?:as\\s+)?(?:my\\s+|a\\s+)?(?:persistent\\s+)?goal(?=[\\s,.:;!?]|$)/is,\n\t/^\\s*(?:make|treat)\\s+this\\s+task\\s+(?:as\\s+)?(?:my\\s+|a\\s+)?(?:persistent\\s+)?goal(?=[\\s,.:;!?]|$)/is,\n] as const;\n\nconst STANDALONE_GOAL_FILLER = /^(?:use it|please|now|ok|okay|thanks|go|do it)(?:[.!?])?$/i;\n\nconst STANDALONE_GOAL_PROCESS_PHRASES = [\n\t/\\bby the way\\b/gi,\n\t/\\bi(?:'m| am) handing (?:(?:this|it) )?over(?: to you)?\\b/gi,\n\t/\\bhand(?:ing)? (?:(?:this|it) )?over(?: to you)?\\b/gi,\n\t/\\buse max(?:imum)? \\d+ sub[-\\s]?agents?\\b/gi,\n\t/\\byou are (?:the )?(?:orchestrator|reviewer|team lead)(?:(?:\\s+and|\\s*,)\\s*(?:also\\s+)?(?:the\\s+)?(?:orchestrator|reviewer|team lead))*\\b/gi,\n\t/\\bhelp you deliver\\b/gi,\n\t/\\b(?:orchestrator|reviewer|team lead)\\b/gi,\n] as const;\n\n/** Raised when text unambiguously states a token-budget directive but the amount cannot be resolved\n * to an exact positive integer. Callers must let this propagate as a loud, explicit failure instead\n * of falling back to an unbounded goal. */\nexport class GoalTokenBudgetParseError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"GoalTokenBudgetParseError\";\n\t}\n}\n\nconst TOKEN_UNIT_MULTIPLIERS: Record<string, number> = {\n\tk: 1_000,\n\tthousand: 1_000,\n\tm: 1_000_000,\n\tmillion: 1_000_000,\n};\n\n/**\n * Resolve a matched numeral into a plain integer, disambiguating a thousands separator from a\n * decimal point. Comma is never a decimal point in this grammar, so any comma-grouped digits\n * (e.g. \"5,000\") are treated as a separator. A dot is genuinely ambiguous (\"1.5\" vs \"1.000.000\"),\n * so it is only treated as a separator when the exactly-3-digit group repeats (e.g. \"1.000.000\");\n * a single dot group falls back to a literal decimal (e.g. \"1.5\", or \"1.000\" read as 1).\n */\nfunction normalizeTokenNumeral(raw: string): number | undefined {\n\t// The caller's capture regex allows \",\" \"_\" \".\" to continue a numeral (they can be internal\n\t// separators), so it greedily swallows a trailing one that is NOT followed by more digits — e.g.\n\t// the sentence-ending \".\" after a dot-grouped \"1.000.000.\" A separator is only ever meaningful\n\t// between digits, so a trailing one is always incidental punctuation; drop it before classifying.\n\tconst compact = raw.replace(/_/g, \"\").replace(/[,.]+$/, \"\");\n\tif (/^[0-9]+$/.test(compact)) return Number(compact);\n\tif (/^[0-9]{1,3}(,[0-9]{3})+\\.[0-9]+$/.test(compact)) return Number(compact.replace(/,/g, \"\"));\n\tif (/^[0-9]{1,3}(,[0-9]{3})+$/.test(compact)) return Number(compact.replace(/,/g, \"\"));\n\tif (/^[0-9]{1,3}(\\.[0-9]{3}){2,}$/.test(compact)) return Number(compact.replace(/\\./g, \"\"));\n\tif (/^[0-9]+\\.[0-9]+$/.test(compact)) return Number(compact);\n\treturn undefined;\n}\n\nfunction parsePositiveTokenCount(raw: string, unit: string | undefined): number | undefined {\n\tconst value = normalizeTokenNumeral(raw);\n\tif (value === undefined) return undefined;\n\tconst multiplier = unit ? (TOKEN_UNIT_MULTIPLIERS[unit.toLowerCase()] ?? 1) : 1;\n\tconst tokens = value * multiplier;\n\treturn Number.isSafeInteger(tokens) && tokens > 0 ? tokens : undefined;\n}\n\nconst TOKEN_BUDGET_PATTERNS = [\n\t/\\btoken\\s+budget\\s*(?:of|is|:|=)?\\s*([0-9][0-9,_.]*)(?:\\s*(thousand|million|k|m)\\b)?/i,\n\t/\\b([0-9][0-9,_.]*)(?:\\s*(thousand|million|k|m)\\b)?\\s*(?:token|tokens)\\s+budget\\b/i,\n\t/\\bbudget\\s*(?:of|is|:|=)?\\s*([0-9][0-9,_.]*)(?:\\s*(thousand|million|k|m)\\b)?\\s*(?:token|tokens)\\b/i,\n] as const;\n\n/**\n * Scan `text` for one explicit token-budget directive. When `trailingOnly` is set, a match only\n * counts if it runs to the end of `text` (ignoring closing punctuation/whitespace) — used to scan\n * inside a captured goal objective, where a budget-shaped phrase embedded mid-sentence usually\n * describes the task's subject matter (e.g. a constant being edited in code), not the agent's own\n * execution ceiling, whereas a trailing clause (\"... with a 40k token budget.\") is a real directive.\n */\nfunction scanTokenBudget(text: string, options: { trailingOnly: boolean }): number | undefined {\n\tfor (const pattern of TOKEN_BUDGET_PATTERNS) {\n\t\tconst match = pattern.exec(text);\n\t\tif (!match) continue;\n\t\tif (options.trailingOnly) {\n\t\t\tconst tail = text.slice(match.index + match[0].length);\n\t\t\tif (!/^[.!?]?\\s*$/.test(tail)) continue;\n\t\t}\n\t\tconst tokens = parsePositiveTokenCount(match[1], match[2]);\n\t\tif (tokens === undefined) {\n\t\t\tthrow new GoalTokenBudgetParseError(\n\t\t\t\t`Token budget phrase \"${match[0].trim()}\" could not be parsed into an exact token ceiling.`,\n\t\t\t);\n\t\t}\n\t\treturn tokens;\n\t}\n\treturn undefined;\n}\n\n/**\n * Parse an explicit token-budget directive from `text`. When `objective` locates a captured goal\n * objective within `text`, a budget-shaped phrase found INSIDE it only counts when it is the\n * trailing clause of the objective; text outside the objective (the prefix/suffix around it) is\n * scanned without that restriction. This keeps a genuine directive (\"... with a 40k token budget.\")\n * working while refusing to adopt a number that is merely part of the task's own subject matter\n * (\"raise the model token budget of 4096 ... to 8192\").\n */\nexport function parseRequestedTokenBudget(\n\ttext: string,\n\tobjective?: { start: number; end: number },\n): number | undefined {\n\tif (!objective) return scanTokenBudget(text, { trailingOnly: false });\n\tconst outside = `${text.slice(0, objective.start)} ${text.slice(objective.end)}`;\n\tconst outsideBudget = scanTokenBudget(outside, { trailingOnly: false });\n\tif (outsideBudget !== undefined) return outsideBudget;\n\treturn scanTokenBudget(text.slice(objective.start, objective.end), { trailingOnly: true });\n}\n\n/**\n * Recognize only explicit persistence language. Ordinary multi-step work and discussion ABOUT goal\n * mechanics deliberately return undefined; those must not silently expand into autonomous work.\n */\nfunction standaloneGoalRemainder(text: string): string | undefined {\n\tfor (const pattern of STANDALONE_GOAL_AUTHORITY_PATTERNS) {\n\t\tconst match = pattern.exec(text);\n\t\tif (!match) continue;\n\t\treturn text\n\t\t\t.slice(match.index + match[0].length)\n\t\t\t.replace(/^[\\s,.:;!?-]+/, \"\")\n\t\t\t.replace(/^(?:and|then|so)\\s+/i, \"\")\n\t\t\t.trim();\n\t}\n\treturn undefined;\n}\n\nfunction remainderWithoutBudgetPhrase(remainder: string): string {\n\tlet next = remainder;\n\tfor (const pattern of TOKEN_BUDGET_PATTERNS) {\n\t\tnext = next.replace(pattern, \" \");\n\t}\n\treturn next\n\t\t.replace(/\\b(?:with|of|is|a|the|:|=)\\b/gi, \" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n}\n\nfunction remainderWithoutProcessPhrases(remainder: string): string {\n\tlet next = remainder;\n\tfor (const pattern of STANDALONE_GOAL_PROCESS_PHRASES) {\n\t\tnext = next.replace(pattern, \" \");\n\t}\n\treturn next\n\t\t.replace(/\\b(?:with|of|is|a|the|to|and|also|you|i|i'm|:|=)\\b/gi, \" \")\n\t\t.replace(/[.,:;!?]/g, \" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n}\n\nfunction isClassificationRemainder(remainder: string): boolean {\n\tif (!remainder || STANDALONE_GOAL_FILLER.test(remainder)) return true;\n\tconst leftover = remainderWithoutProcessPhrases(remainder);\n\tif (!leftover || STANDALONE_GOAL_FILLER.test(leftover)) return true;\n\ttry {\n\t\tif (parseRequestedTokenBudget(remainder) === undefined) return false;\n\t} catch {\n\t\treturn false;\n\t}\n\tconst afterBudget = remainderWithoutBudgetPhrase(leftover);\n\treturn afterBudget.length === 0 || STANDALONE_GOAL_FILLER.test(afterBudget);\n}\n\nfunction userMessageText(content: unknown): string {\n\tif (typeof content === \"string\") return content.trim();\n\tif (!Array.isArray(content)) return \"\";\n\treturn content\n\t\t.filter(\n\t\t\t(block): block is { type: \"text\"; text: string } =>\n\t\t\t\ttypeof block === \"object\" &&\n\t\t\t\tblock !== null &&\n\t\t\t\t\"type\" in block &&\n\t\t\t\tblock.type === \"text\" &&\n\t\t\t\t\"text\" in block &&\n\t\t\t\ttypeof block.text === \"string\",\n\t\t)\n\t\t.map((block) => block.text)\n\t\t.join(\"\")\n\t\t.trim();\n}\n\n/** Latest owner prompt that is not the current classification phrase itself. */\nexport function priorUserPromptText(\n\tmessages: readonly { role: string; content?: unknown }[],\n\tcurrentText: string,\n): string | undefined {\n\tconst current = currentText.trim();\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst message = messages[index];\n\t\tif (message.role !== \"user\") continue;\n\t\tconst text = userMessageText(message.content);\n\t\tif (!text || text === current) continue;\n\t\treturn text;\n\t}\n\treturn undefined;\n}\n\nexport function parseExplicitChatGoal(text: string, priorUserText?: string): ExplicitChatGoal | undefined {\n\tfor (const pattern of EXPLICIT_GOAL_PATTERNS) {\n\t\tconst match = pattern.exec(text);\n\t\tconst rawObjective = match?.[1];\n\t\tconst objective = rawObjective?.trim();\n\t\tif (!match || !objective || objective.length > MAX_GOAL_OBJECTIVE_LENGTH) continue;\n\t\t// rawObjective is always a suffix of match[0] (every pattern ends in `(.+)$`), so its start\n\t\t// offset in `text` is match[0]'s length minus its own length.\n\t\tconst objectiveSpan = {\n\t\t\tstart: match.index + (match[0].length - (rawObjective?.length ?? 0)),\n\t\t\tend: match.index + match[0].length,\n\t\t};\n\t\tconst tokenBudget = parseRequestedTokenBudget(text, objectiveSpan);\n\t\treturn { objective, ...(tokenBudget !== undefined ? { tokenBudget } : {}) };\n\t}\n\tconst remainder = standaloneGoalRemainder(text);\n\tif (remainder === undefined) return undefined;\n\tconst tokenBudget = parseRequestedTokenBudget(text);\n\tconst inline = remainder && !isClassificationRemainder(remainder) ? remainder : undefined;\n\tconst prior = priorUserText?.trim();\n\tconst objective =\n\t\tinline && inline.length <= MAX_GOAL_OBJECTIVE_LENGTH\n\t\t\t? inline\n\t\t\t: prior && prior !== text.trim() && prior.length <= MAX_GOAL_OBJECTIVE_LENGTH\n\t\t\t\t? prior\n\t\t\t\t: undefined;\n\tif (!objective) return undefined;\n\treturn { objective, ...(tokenBudget !== undefined ? { tokenBudget } : {}) };\n}\n\n/** Exact owner authority for model-supplied token budgets; ordinary work carries no budget authority. */\nexport function parseExplicitGoalStartAuthority(text: string): ExplicitGoalStartAuthority | undefined {\n\tconst goal = parseExplicitChatGoal(text);\n\tif (goal) return goal.tokenBudget === undefined ? {} : { tokenBudget: goal.tokenBudget };\n\tif (!STANDALONE_GOAL_AUTHORITY_PATTERNS.some((pattern) => pattern.test(text))) return undefined;\n\tconst tokenBudget = parseRequestedTokenBudget(text);\n\treturn tokenBudget === undefined ? {} : { tokenBudget };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/core/sdk.ts"],"names":[],"mappings":"AAEA,OAAO,EAAwB,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACzF,OAAO,KAAK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EACf,cAAc,EACd,cAAc,EACd,YAAY,GACZ,CAAC;AA8CF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,GAAE,yBAA8B,GAAG,OAAO,CAAC,wBAAwB,CAAC,CA0WnH"}
package/dist/core/sdk.js CHANGED
@@ -11,6 +11,7 @@ import { AuthStorage } from "./auth-storage.js";
11
11
  import { BEDROCK_PROVIDER_ID, bindSavedBedrockScope, getActiveBedrockScope, isUnscopedBedrockProxy, } from "./bedrock-scope.js";
12
12
  import { recoverBedrockSsoAuthentication } from "./bedrock-sso-login.js";
13
13
  import { DEFAULT_ACTIVE_TOOL_NAMES } from "./default-tool-surface.js";
14
+ import { resolveFastModeServiceTier } from "./fast-mode.js";
14
15
  import { isInstallTelemetryEnabled } from "./install-telemetry.js";
15
16
  import { ModelRegistry } from "./model-registry.js";
16
17
  import { findInitialModel, resolveProfileModelSettings } from "./model-resolver.js";
@@ -303,9 +304,10 @@ export async function createAgentSession(options = {}) {
303
304
  const timeoutMs = options?.timeoutMs ?? providerRetrySettings.timeoutMs ?? effectiveTimeoutMs;
304
305
  const websocketConnectTimeoutMs = options?.websocketConnectTimeoutMs ?? settingsManager.getWebSocketConnectTimeoutMs();
305
306
  const attributionHeaders = getAttributionHeaders(model, settingsManager, options?.sessionId);
307
+ const fastModeServiceTier = resolveFastModeServiceTier(model, settingsManager.getFastModeEnabled(model.provider));
306
308
  const providerOptions = {
307
309
  ...options,
308
- serviceTier: options?.serviceTier === undefined ? defaultServiceTier : options.serviceTier,
310
+ serviceTier: options?.serviceTier === undefined ? (fastModeServiceTier ?? defaultServiceTier) : options.serviceTier,
309
311
  ...(bedrockScope ? { region: bedrockScope.region, profile: bedrockScope.profile } : {}),
310
312
  interactionMode: forceBackgroundRequests ? "background" : (options?.interactionMode ?? "user"),
311
313
  onInteractiveAuthRecovery: options?.onInteractiveAuthRecovery ?? recoverBedrockSsoAuthentication,
@@ -1 +1 @@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C;QAChB,wFAAwF;QACxF,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,iCAAiC,CAAC,EAAE,CAAC;YAC1E,MAAM,OAAO,CAAC,cAAc,EAAE,CAAC;YAC/B,MAAM,KAAK,CAAC;QACb,CAAC;IACF,CAAC;IACD,gGAAgG;IAChG,kGAAkG;IAClG,MAAM,OAAO,CAAC,gBAAgB,EAAE,CAAC;IACjC,MAAM,gBAAgB,GAAG,cAAc,CAAC,aAAa,EAAE,CAAC;IAExD,OAAO;QACN,OAAO;QACP,gBAAgB;QAChB,oBAAoB;KACpB,CAAC;AACH,CAAC","sourcesContent":["import { Agent } from \"@caupulican/pi-agent-core/agent\";\nimport { convertToLlm } from \"@caupulican/pi-agent-core/messages\";\nimport { getDefaultSessionDir, SessionManager } from \"@caupulican/pi-agent-core/session\";\nimport type { AgentMessage, ThinkingLevel } from \"@caupulican/pi-agent-core/types\";\nimport {\n\ttype Api,\n\ttype Message,\n\ttype Model,\n\tresolveModelThinkingLevel,\n\ttype ServiceTier,\n\tstreamSimple,\n} from \"@caupulican/pi-ai\";\nimport { getAgentDir } from \"../config.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport { configFile } from \"./agent-paths.ts\";\nimport { AgentSession } from \"./agent-session.ts\";\nimport { formatNoModelsAvailableMessage } from \"./auth-guidance.ts\";\nimport { AuthStorage } from \"./auth-storage.ts\";\nimport {\n\tBEDROCK_PROVIDER_ID,\n\tbindSavedBedrockScope,\n\tgetActiveBedrockScope,\n\tisUnscopedBedrockProxy,\n} from \"./bedrock-scope.ts\";\nimport { recoverBedrockSsoAuthentication } from \"./bedrock-sso-login.ts\";\nimport { DEFAULT_ACTIVE_TOOL_NAMES } from \"./default-tool-surface.ts\";\nimport type { ExtensionRunner, LoadExtensionsResult, SessionStartEvent, ToolDefinition } from \"./extensions/index.ts\";\nimport { isInstallTelemetryEnabled } from \"./install-telemetry.ts\";\nimport { ModelRegistry } from \"./model-registry.ts\";\nimport { findInitialModel, resolveProfileModelSettings } from \"./model-resolver.ts\";\nimport type { OrchestrationProfile } from \"./orchestration/contracts.ts\";\nimport { resolveConfiguredOrchestrationModel } from \"./orchestration/model-binding.ts\";\nimport { validateOrchestrationProfile } from \"./orchestration/profile-registry.ts\";\nimport type { ResourceLoader } from \"./resource-loader.ts\";\nimport { DefaultResourceLoader } from \"./resource-loader.ts\";\nimport { parseResourceProfileInput } from \"./resource-profile-blocks.ts\";\nimport { isWorkerSession } from \"./session-role.ts\";\nimport type {\n\tProfileDefinitionInput,\n\tResourceProfileFilterSettings,\n\tResourceProfileSettings,\n} from \"./settings-manager.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\nimport { time } from \"./timings.ts\";\nimport {\n\tcreateBashTool,\n\tcreateCodingTools,\n\tcreateEditTool,\n\tcreateFindTool,\n\tcreateGrepTool,\n\tcreateLsTool,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateWriteTool,\n\twithFileMutationQueue,\n} from \"./tools/index.ts\";\n\nexport interface CreateAgentSessionOptions {\n\t/** Working directory for project-local discovery. Default: process.cwd() */\n\tcwd?: string;\n\t/** Global config directory. Default: ~/.pi/agent */\n\tagentDir?: string;\n\n\t/** Auth storage for credentials. Default: AuthStorage.create(agentDir/auth.json) */\n\tauthStorage?: AuthStorage;\n\t/** Model registry. Default: ModelRegistry.create(authStorage, agentDir/models.json) */\n\tmodelRegistry?: ModelRegistry;\n\n\t/** Model to use. Default: from settings, else first available */\n\tmodel?: Model<Api>;\n\t/** Thinking level. Default: from settings, then the model's declared default, else 'medium'. */\n\tthinkingLevel?: ThinkingLevel;\n\t/** Default provider processing tier for this session. Per-request options take precedence. */\n\tserviceTier?: ServiceTier;\n\t/**\n\t * Whether `model` came from an explicit CLI/SDK flag (vs. profile/settings resolution).\n\t * When false (default), the active profile's model is re-applied on reload so live profile\n\t * edits take effect; when true, the explicit launch-time model is preserved across reloads.\n\t */\n\tisExplicitModel?: boolean;\n\t/** Whether `thinkingLevel` came from an explicit flag (see isExplicitModel). */\n\tisExplicitThinking?: boolean;\n\t/** True when this session is a spawned subagent/child — gates durable memory writes. */\n\tisChildSession?: boolean;\n\t/** Models available for cycling (Ctrl+P in interactive mode) */\n\tscopedModels?: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>;\n\n\t/**\n\t * Optional default tool suppression mode when no explicit allowlist is provided.\n\t *\n\t * - \"all\": start with no tools enabled\n\t * - \"builtin\": disable the default built-in tools (read, bash, python, edit, write,\n\t * goal, delegate, and run_toolkit_script)\n\t * but keep extension/custom tools enabled\n\t */\n\tnoTools?: \"all\" | \"builtin\";\n\t/**\n\t * Optional allowlist of tool names.\n\t *\n\t * When omitted, pi enables the shared default built-in tool surface and leaves extension/custom\n\t * tools enabled unless `noTools` changes that default.\n\t * When provided, only the listed tool names are enabled.\n\t */\n\ttools?: string[];\n\t/** Optional denylist of tool names to disable. Applies after `tools` when both are provided. */\n\texcludeTools?: string[];\n\t/** Optional resource-profile allow/block filters for tool names. */\n\ttoolProfileFilter?: ResourceProfileFilterSettings;\n\t/** Optional one-shot resource filters or complete situation profiles. Never persisted to disk. */\n\tresourceProfileDefinitions?: Record<string, ResourceProfileSettings | ProfileDefinitionInput>;\n\t/** Optional one-shot profile definitions as JSON or <resource-profile> tag text. Never persisted to disk. */\n\tresourceProfileJson?: string | string[];\n\t/** Optional runtime profile selection. Never persisted to disk. */\n\tresourceProfiles?: string[];\n\t/** Immutable owner-authored orchestration policy for this session. */\n\torchestrationProfile?: OrchestrationProfile;\n\t/** Custom tools to register (in addition to built-in tools). */\n\tcustomTools?: ToolDefinition[];\n\n\t/** Resource loader. When omitted, DefaultResourceLoader is used. */\n\tresourceLoader?: ResourceLoader;\n\n\t/** Session manager. Default: SessionManager.create(cwd, agentDir, getDefaultSessionDir(cwd, agentDir)) */\n\tsessionManager?: SessionManager;\n\n\t/** Settings manager. Default: SettingsManager.create(cwd, agentDir) */\n\tsettingsManager?: SettingsManager;\n\t/** Session start event metadata for extension runtime startup. */\n\tsessionStartEvent?: SessionStartEvent;\n}\n\n/** Result from createAgentSession */\nexport interface CreateAgentSessionResult {\n\t/** The created session */\n\tsession: AgentSession;\n\t/** Extensions result (for UI context setup in interactive mode) */\n\textensionsResult: LoadExtensionsResult;\n\t/** Warning if session was restored with a different model than saved */\n\tmodelFallbackMessage?: string;\n}\n\n// Re-exports\n\nexport * from \"./agent-session-runtime.ts\";\nexport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n\tExtensionFactory,\n\tSlashCommandInfo,\n\tSlashCommandSource,\n\tToolDefinition,\n} from \"./extensions/index.ts\";\nexport type { PromptTemplate } from \"./prompt-templates.ts\";\nexport type { Skill } from \"./skills.ts\";\nexport type { Tool } from \"./tools/index.ts\";\n\nexport {\n\twithFileMutationQueue,\n\t// Tool factories (for custom cwd)\n\tcreateCodingTools,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateBashTool,\n\tcreateEditTool,\n\tcreateWriteTool,\n\tcreateGrepTool,\n\tcreateFindTool,\n\tcreateLsTool,\n};\n\n// Helper Functions\n\nfunction getDefaultAgentDir(): string {\n\treturn getAgentDir();\n}\n\nfunction getAttributionHeaders(\n\tmodel: Model<Api>,\n\tsettingsManager: SettingsManager,\n\tsessionId?: string,\n): Record<string, string> | undefined {\n\tif (\n\t\tsessionId &&\n\t\t(model.provider === \"opencode\" || model.provider === \"opencode-go\" || model.baseUrl.includes(\"opencode.ai\"))\n\t) {\n\t\treturn { \"x-opencode-session\": sessionId, \"x-opencode-client\": \"pi\" };\n\t}\n\n\tif (!isInstallTelemetryEnabled(settingsManager)) {\n\t\treturn undefined;\n\t}\n\n\tif (model.provider === \"openrouter\" || model.baseUrl.includes(\"openrouter.ai\")) {\n\t\treturn {\n\t\t\t\"HTTP-Referer\": \"https://pi.dev\",\n\t\t\t\"X-OpenRouter-Title\": \"pi\",\n\t\t\t\"X-OpenRouter-Categories\": \"cli-agent\",\n\t\t};\n\t}\n\n\tif (\n\t\tmodel.provider === \"cloudflare-workers-ai\" ||\n\t\tmodel.provider === \"cloudflare-ai-gateway\" ||\n\t\tmodel.baseUrl.includes(\"api.cloudflare.com\") ||\n\t\tmodel.baseUrl.includes(\"gateway.ai.cloudflare.com\")\n\t) {\n\t\treturn {\n\t\t\t\"User-Agent\": \"pi-coding-agent\",\n\t\t};\n\t}\n\n\treturn undefined;\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 '@caupulican/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: [\"read\", \"bash\"],\n * resourceLoader: loader,\n * sessionManager: SessionManager.inMemory(),\n * });\n * ```\n */\nexport async function createAgentSession(options: CreateAgentSessionOptions = {}): Promise<CreateAgentSessionResult> {\n\tconst cwd = resolvePath(options.cwd ?? options.sessionManager?.getCwd() ?? process.cwd());\n\tconst agentDir = options.agentDir ? resolvePath(options.agentDir) : getDefaultAgentDir();\n\tlet resourceLoader = options.resourceLoader;\n\n\t// Use provided or create AuthStorage and ModelRegistry\n\tconst authPath = options.agentDir ? configFile(agentDir, \"auth.json\") : undefined;\n\tconst modelsPath = options.agentDir ? configFile(agentDir, \"models.json\") : undefined;\n\tconst authStorage = options.authStorage ?? AuthStorage.create(authPath);\n\tconst modelRegistry = options.modelRegistry ?? ModelRegistry.create(authStorage, modelsPath);\n\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tbindSavedBedrockScope(settingsManager, modelRegistry);\n\tconst isChildSession = options.isChildSession ?? process.env.PI_CHILD_SESSION === \"1\";\n\tconst forceBackgroundRequests = isChildSession || isWorkerSession();\n\tconst defaultServiceTier = options.serviceTier;\n\tconst orchestrationProfile = options.orchestrationProfile;\n\tif (orchestrationProfile) {\n\t\tvalidateOrchestrationProfile(orchestrationProfile);\n\t\tconst conflictingOptions = [\n\t\t\t...(options.model ? [\"model\"] : []),\n\t\t\t...(options.thinkingLevel !== undefined ? [\"thinkingLevel\"] : []),\n\t\t\t...(options.scopedModels !== undefined ? [\"scopedModels\"] : []),\n\t\t\t...(options.tools !== undefined ? [\"tools\"] : []),\n\t\t\t...(options.noTools !== undefined ? [\"noTools\"] : []),\n\t\t\t...(options.excludeTools !== undefined ? [\"excludeTools\"] : []),\n\t\t\t...(options.toolProfileFilter !== undefined ? [\"toolProfileFilter\"] : []),\n\t\t\t...(options.resourceProfiles !== undefined ? [\"resourceProfiles\"] : []),\n\t\t];\n\t\tif (conflictingOptions.length > 0) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Orchestration profile '${orchestrationProfile.profileId}' owns model, thinking, tools, and resources; remove conflicting SDK options: ${conflictingOptions.join(\", \")}.`,\n\t\t\t);\n\t\t}\n\t\tsettingsManager.setRuntimeResourceProfiles([...orchestrationProfile.resourceProfileNames]);\n\t}\n\tconst needsProfileReload =\n\t\toptions.resourceProfileDefinitions !== undefined ||\n\t\toptions.resourceProfileJson !== undefined ||\n\t\toptions.resourceProfiles !== undefined ||\n\t\torchestrationProfile !== undefined;\n\tif (options.resourceProfileDefinitions) {\n\t\tsettingsManager.addInlineResourceProfileDefinitions(options.resourceProfileDefinitions);\n\t}\n\tif (options.resourceProfileJson) {\n\t\tconst inputs = Array.isArray(options.resourceProfileJson)\n\t\t\t? options.resourceProfileJson\n\t\t\t: [options.resourceProfileJson];\n\t\tfor (const input of inputs) {\n\t\t\tsettingsManager.addInlineResourceProfileDefinitions(parseResourceProfileInput(input).profiles);\n\t\t}\n\t}\n\tif (!orchestrationProfile && options.resourceProfiles !== undefined) {\n\t\tsettingsManager.setRuntimeResourceProfiles(options.resourceProfiles);\n\t}\n\tconst sessionManager =\n\t\toptions.sessionManager ?? SessionManager.create(cwd, agentDir, getDefaultSessionDir(cwd, agentDir));\n\n\tif (!resourceLoader) {\n\t\tresourceLoader = new DefaultResourceLoader({ cwd, agentDir, settingsManager });\n\t\tawait resourceLoader.reload();\n\t\ttime(\"resourceLoader.reload\");\n\t} else if (needsProfileReload) {\n\t\tawait resourceLoader.reload();\n\t\ttime(\"resourceLoader.reload\");\n\t}\n\n\t// Check if session has existing data to restore\n\tconst existingSession = sessionManager.buildSessionContext();\n\tconst hasExistingSession = existingSession.messages.length > 0;\n\tconst hasThinkingEntry = sessionManager.getBranch().some((entry) => entry.type === \"thinking_level_change\");\n\n\tconst orchestrationModel = orchestrationProfile\n\t\t? resolveConfiguredOrchestrationModel(orchestrationProfile, modelRegistry)\n\t\t: undefined;\n\tif (orchestrationProfile && !orchestrationModel) {\n\t\tthrow new TypeError(\n\t\t\t`Orchestration profile '${orchestrationProfile.profileId}' has no configured, authenticated model that supports its exact thinking level.`,\n\t\t);\n\t}\n\tlet model = orchestrationModel?.model ?? options.model;\n\tlet modelFallbackMessage: string | undefined;\n\n\tlet thinkingLevel = orchestrationModel?.binding.thinkingLevel ?? options.thinkingLevel;\n\n\tconst activeProfileNames = settingsManager.getActiveResourceProfileNames();\n\tif (!orchestrationProfile && activeProfileNames.length > 0) {\n\t\tconst profileSettings = resolveProfileModelSettings({\n\t\t\tactiveProfileNames,\n\t\t\tregistry: settingsManager.getProfileRegistry(),\n\t\t\tmodelRegistry,\n\t\t\tcwd,\n\t\t});\n\t\tif (profileSettings.error) {\n\t\t\tmodelFallbackMessage = `Profile model resolution error: ${profileSettings.error}`;\n\t\t}\n\t\tif (!model && profileSettings.model) {\n\t\t\tmodel = profileSettings.model;\n\t\t}\n\t\tif (thinkingLevel === undefined && profileSettings.thinkingLevel) {\n\t\t\tthinkingLevel = profileSettings.thinkingLevel;\n\t\t}\n\t}\n\n\t// If session has data, try to restore model from it\n\tif (!model && hasExistingSession && existingSession.model) {\n\t\tconst restoredModel = modelRegistry.find(existingSession.model.provider, existingSession.model.modelId);\n\t\tif (restoredModel && modelRegistry.hasConfiguredAuth(restoredModel)) {\n\t\t\tmodel = restoredModel;\n\t\t}\n\t\tif (!model) {\n\t\t\tmodelFallbackMessage = `Could not restore model ${existingSession.model.provider}/${existingSession.model.modelId}`;\n\t\t}\n\t}\n\n\t// If still no model, use findInitialModel (checks settings default, then provider defaults)\n\tif (!model) {\n\t\tconst result = await findInitialModel({\n\t\t\tscopedModels: [],\n\t\t\tisContinuing: hasExistingSession,\n\t\t\tdefaultProvider: settingsManager.getDefaultProvider(),\n\t\t\tdefaultModelId: settingsManager.getDefaultModel(),\n\t\t\tdefaultThinkingLevel: settingsManager.getDefaultThinkingLevel(),\n\t\t\tmodelRegistry,\n\t\t});\n\t\tmodel = result.model;\n\t\tif (thinkingLevel === undefined && !(hasExistingSession && hasThinkingEntry)) {\n\t\t\tthinkingLevel = result.thinkingLevel;\n\t\t}\n\t\tif (!model) {\n\t\t\tmodelFallbackMessage = formatNoModelsAvailableMessage();\n\t\t} else if (modelFallbackMessage) {\n\t\t\tmodelFallbackMessage += `. Using ${model.provider}/${model.id}`;\n\t\t}\n\t}\n\n\t// If session has data, restore thinking level from it\n\tif (thinkingLevel === undefined && hasExistingSession) {\n\t\tthinkingLevel = hasThinkingEntry\n\t\t\t? (existingSession.thinkingLevel as ThinkingLevel)\n\t\t\t: settingsManager.getDefaultThinkingLevel();\n\t}\n\n\t// Resolve preference, model metadata, harness fallback, and capability clamping through the\n\t// same contract used by CLI startup and isolated lanes.\n\tif (!model) {\n\t\tthinkingLevel = \"off\";\n\t} else {\n\t\tthinkingLevel = resolveModelThinkingLevel(\n\t\t\tmodel,\n\t\t\tthinkingLevel ?? settingsManager.getDefaultThinkingLevel(),\n\t\t) as ThinkingLevel;\n\t}\n\n\tconst defaultActiveToolNames = [\n\t\t...DEFAULT_ACTIVE_TOOL_NAMES,\n\t\t...(settingsManager.getScoutSettings().enabled ? [\"context_scout\"] : []),\n\t];\n\tconst toolProfileFilter = orchestrationProfile\n\t\t? settingsManager.getResourceProfileFilter(\"tools\")\n\t\t: (options.toolProfileFilter ?? settingsManager.getResourceProfileFilter(\"tools\"));\n\tconst allowedToolNames = orchestrationProfile\n\t\t? [...orchestrationProfile.toolNames]\n\t\t: (options.tools ?? (options.noTools === \"all\" ? [] : undefined));\n\tconst excludedToolNames = orchestrationProfile ? undefined : options.excludeTools;\n\tconst excludedToolNameSet = excludedToolNames ? new Set(excludedToolNames) : undefined;\n\tconst initialActiveToolNames: string[] = (\n\t\torchestrationProfile\n\t\t\t? [...orchestrationProfile.toolNames]\n\t\t\t: options.tools\n\t\t\t\t? [...options.tools]\n\t\t\t\t: options.noTools\n\t\t\t\t\t? []\n\t\t\t\t\t: defaultActiveToolNames\n\t).filter((name) => !excludedToolNameSet?.has(name));\n\n\tlet agent: Agent;\n\n\t// Create convertToLlm wrapper that filters images if blockImages is enabled (defense-in-depth)\n\tconst convertToLlmWithBlockImages = (messages: AgentMessage[]): Message[] => {\n\t\tconst converted = convertToLlm(messages);\n\t\t// Check setting dynamically so mid-session changes take effect\n\t\tif (!settingsManager.getBlockImages()) {\n\t\t\treturn converted;\n\t\t}\n\t\t// Filter out ImageContent from all messages, replacing with text placeholder\n\t\treturn converted.map((msg) => {\n\t\t\tif (msg.role === \"user\" || msg.role === \"toolResult\") {\n\t\t\t\tconst content = msg.content;\n\t\t\t\tif (Array.isArray(content)) {\n\t\t\t\t\tconst hasImages = content.some((c) => c.type === \"image\");\n\t\t\t\t\tif (hasImages) {\n\t\t\t\t\t\tconst filteredContent = content\n\t\t\t\t\t\t\t.map((c) =>\n\t\t\t\t\t\t\t\tc.type === \"image\" ? { type: \"text\" as const, text: \"Image reading is disabled.\" } : c,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t(c, i, arr) =>\n\t\t\t\t\t\t\t\t\t// Dedupe consecutive \"Image reading is disabled.\" texts\n\t\t\t\t\t\t\t\t\t!(\n\t\t\t\t\t\t\t\t\t\tc.type === \"text\" &&\n\t\t\t\t\t\t\t\t\t\tc.text === \"Image reading is disabled.\" &&\n\t\t\t\t\t\t\t\t\t\ti > 0 &&\n\t\t\t\t\t\t\t\t\t\tarr[i - 1].type === \"text\" &&\n\t\t\t\t\t\t\t\t\t\t(arr[i - 1] as { type: \"text\"; text: string }).text === \"Image reading is disabled.\"\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\treturn { ...msg, content: filteredContent };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn msg;\n\t\t});\n\t};\n\n\tconst extensionRunnerRef: { current?: ExtensionRunner } = {};\n\n\tagent = new Agent({\n\t\tinitialState: {\n\t\t\tsystemPrompt: \"\",\n\t\t\tmodel,\n\t\t\tthinkingLevel,\n\t\t\ttools: [],\n\t\t},\n\t\tconvertToLlm: convertToLlmWithBlockImages,\n\t\tstreamFn: async (model, context, options) => {\n\t\t\tconst bedrockScope =\n\t\t\t\tmodel.provider === BEDROCK_PROVIDER_ID ? getActiveBedrockScope(settingsManager) : undefined;\n\t\t\tif (model.provider === BEDROCK_PROVIDER_ID && !bedrockScope && !isUnscopedBedrockProxy()) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Amazon Bedrock requires a verified profile/region scope. Run /login amazon-bedrock before using this model.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst auth = await modelRegistry.getApiKeyAndHeaders(model);\n\t\t\tif (!auth.ok) {\n\t\t\t\tthrow new Error(auth.error);\n\t\t\t}\n\t\t\tconst providerRetrySettings = settingsManager.getProviderRetrySettings();\n\t\t\tconst httpIdleTimeoutMs = settingsManager.getHttpIdleTimeoutMs();\n\t\t\t// SDKs treat timeout=0 as 0ms (immediate timeout), not \"no timeout\".\n\t\t\t// Use max int32 to effectively disable the timeout.\n\t\t\tconst effectiveTimeoutMs = httpIdleTimeoutMs === 0 ? 2147483647 : httpIdleTimeoutMs;\n\t\t\tconst timeoutMs = options?.timeoutMs ?? providerRetrySettings.timeoutMs ?? effectiveTimeoutMs;\n\t\t\tconst websocketConnectTimeoutMs =\n\t\t\t\toptions?.websocketConnectTimeoutMs ?? settingsManager.getWebSocketConnectTimeoutMs();\n\t\t\tconst attributionHeaders = getAttributionHeaders(model, settingsManager, options?.sessionId);\n\t\t\tconst providerOptions = {\n\t\t\t\t...options,\n\t\t\t\tserviceTier: options?.serviceTier === undefined ? defaultServiceTier : options.serviceTier,\n\t\t\t\t...(bedrockScope ? { region: bedrockScope.region, profile: bedrockScope.profile } : {}),\n\t\t\t\tinteractionMode: forceBackgroundRequests ? \"background\" : (options?.interactionMode ?? \"user\"),\n\t\t\t\tonInteractiveAuthRecovery: options?.onInteractiveAuthRecovery ?? recoverBedrockSsoAuthentication,\n\t\t\t\tapiKey: auth.apiKey,\n\t\t\t\tonAuthRejection:\n\t\t\t\t\tauth.apiKey && model.provider === \"openai-codex\"\n\t\t\t\t\t\t? async () => modelRegistry.recoverRejectedOAuthApiKey(model.provider, auth.apiKey as string)\n\t\t\t\t\t\t: options?.onAuthRejection,\n\t\t\t\ttimeoutMs,\n\t\t\t\twebsocketConnectTimeoutMs,\n\t\t\t\tmaxRetries: options?.maxRetries ?? providerRetrySettings.maxRetries,\n\t\t\t\tmaxRetryDelayMs: options?.maxRetryDelayMs ?? providerRetrySettings.maxRetryDelayMs,\n\t\t\t\theaders:\n\t\t\t\t\tattributionHeaders || auth.headers || options?.headers\n\t\t\t\t\t\t? { ...attributionHeaders, ...auth.headers, ...options?.headers }\n\t\t\t\t\t\t: undefined,\n\t\t\t};\n\t\t\treturn streamSimple(model, context, providerOptions);\n\t\t},\n\t\tonPayload: async (payload, _model) => {\n\t\t\tconst runner = extensionRunnerRef.current;\n\t\t\tif (!runner?.hasHandlers(\"before_provider_request\")) {\n\t\t\t\treturn payload;\n\t\t\t}\n\t\t\treturn runner.emitBeforeProviderRequest(payload);\n\t\t},\n\t\tonResponse: async (response, _model) => {\n\t\t\tconst runner = extensionRunnerRef.current;\n\t\t\tif (!runner?.hasHandlers(\"after_provider_response\")) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait runner.emit({\n\t\t\t\ttype: \"after_provider_response\",\n\t\t\t\tstatus: response.status,\n\t\t\t\theaders: response.headers,\n\t\t\t});\n\t\t},\n\t\tsessionId: sessionManager.getSessionId(),\n\t\tsteeringMode: settingsManager.getSteeringMode(),\n\t\tfollowUpMode: settingsManager.getFollowUpMode(),\n\t\ttransport: settingsManager.getTransport(),\n\t\tthinkingBudgets: settingsManager.getThinkingBudgets(),\n\t\tmaxRetryDelayMs: settingsManager.getProviderRetrySettings().maxRetryDelayMs,\n\t});\n\n\t// Restore messages if session has existing data\n\tif (hasExistingSession) {\n\t\tagent.state.messages = existingSession.messages;\n\t\tif (!hasThinkingEntry) {\n\t\t\tsessionManager.appendThinkingLevelChange(thinkingLevel);\n\t\t}\n\t} else {\n\t\t// Save initial model and thinking level for new sessions so they can be restored on resume\n\t\tif (model) {\n\t\t\tsessionManager.appendModelChange(model.provider, model.id);\n\t\t}\n\t\tsessionManager.appendThinkingLevelChange(thinkingLevel);\n\t}\n\n\tconst session = new AgentSession({\n\t\tagent,\n\t\tsessionManager,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tagentDir,\n\t\tscopedModels: orchestrationModel\n\t\t\t? [{ model: orchestrationModel.model, thinkingLevel: orchestrationModel.binding.thinkingLevel }]\n\t\t\t: options.scopedModels,\n\t\tresourceLoader,\n\t\tcustomTools: options.customTools,\n\t\tmodelRegistry,\n\t\tinitialActiveToolNames,\n\t\tallowedToolNames,\n\t\texcludedToolNames,\n\t\textensionRunnerRef,\n\t\ttoolProfileFilter,\n\t\tisExplicitModel: orchestrationProfile ? true : (options.isExplicitModel ?? options.model != null),\n\t\tisExplicitThinking: orchestrationProfile\n\t\t\t? true\n\t\t\t: (options.isExplicitThinking ?? options.thinkingLevel !== undefined),\n\t\tisChildSession,\n\t\torchestrationProfile,\n\t\tsessionStartEvent: options.sessionStartEvent,\n\t});\n\ttry {\n\t\t// The initial runtime has now bound providers from profile-granted extensions. Re-resolve the\n\t\t// profile model against that authoritative registry generation, then resync model capability.\n\t\tawait session.reapplyActiveProfileModelSettings();\n\t\tif (modelFallbackMessage?.startsWith(\"Profile model resolution error:\")) {\n\t\t\tmodelFallbackMessage = undefined;\n\t\t}\n\t} catch (error) {\n\t\t// Preserve the established non-fatal fallback for a genuinely unresolved profile model.\n\t\tif (!modelFallbackMessage?.startsWith(\"Profile model resolution error:\")) {\n\t\t\tawait session.disposeAndWait();\n\t\t\tthrow error;\n\t\t}\n\t}\n\t// File-store memory tools exist only after providers initialize. Do this here so an SDK session\n\t// that never calls bindExtensions still has the requested `memory` tool when the grant allows it.\n\tawait session.initializeMemory();\n\tconst extensionsResult = resourceLoader.getExtensions();\n\n\treturn {\n\t\tsession,\n\t\textensionsResult,\n\t\tmodelFallbackMessage,\n\t};\n}\n"]}
1
+ {"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/core/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AAEzF,OAAO,EAIN,yBAAyB,EAEzB,YAAY,GACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,8BAA8B,EAAE,M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,oBAAoB;KACpB,CAAC;AACH,CAAC","sourcesContent":["import { Agent } from \"@caupulican/pi-agent-core/agent\";\nimport { convertToLlm } from \"@caupulican/pi-agent-core/messages\";\nimport { getDefaultSessionDir, SessionManager } from \"@caupulican/pi-agent-core/session\";\nimport type { AgentMessage, ThinkingLevel } from \"@caupulican/pi-agent-core/types\";\nimport {\n\ttype Api,\n\ttype Message,\n\ttype Model,\n\tresolveModelThinkingLevel,\n\ttype ServiceTier,\n\tstreamSimple,\n} from \"@caupulican/pi-ai\";\nimport { getAgentDir } from \"../config.ts\";\nimport { resolvePath } from \"../utils/paths.ts\";\nimport { configFile } from \"./agent-paths.ts\";\nimport { AgentSession } from \"./agent-session.ts\";\nimport { formatNoModelsAvailableMessage } from \"./auth-guidance.ts\";\nimport { AuthStorage } from \"./auth-storage.ts\";\nimport {\n\tBEDROCK_PROVIDER_ID,\n\tbindSavedBedrockScope,\n\tgetActiveBedrockScope,\n\tisUnscopedBedrockProxy,\n} from \"./bedrock-scope.ts\";\nimport { recoverBedrockSsoAuthentication } from \"./bedrock-sso-login.ts\";\nimport { DEFAULT_ACTIVE_TOOL_NAMES } from \"./default-tool-surface.ts\";\nimport type { ExtensionRunner, LoadExtensionsResult, SessionStartEvent, ToolDefinition } from \"./extensions/index.ts\";\nimport { resolveFastModeServiceTier } from \"./fast-mode.ts\";\nimport { isInstallTelemetryEnabled } from \"./install-telemetry.ts\";\nimport { ModelRegistry } from \"./model-registry.ts\";\nimport { findInitialModel, resolveProfileModelSettings } from \"./model-resolver.ts\";\nimport type { OrchestrationProfile } from \"./orchestration/contracts.ts\";\nimport { resolveConfiguredOrchestrationModel } from \"./orchestration/model-binding.ts\";\nimport { validateOrchestrationProfile } from \"./orchestration/profile-registry.ts\";\nimport type { ResourceLoader } from \"./resource-loader.ts\";\nimport { DefaultResourceLoader } from \"./resource-loader.ts\";\nimport { parseResourceProfileInput } from \"./resource-profile-blocks.ts\";\nimport { isWorkerSession } from \"./session-role.ts\";\nimport type {\n\tProfileDefinitionInput,\n\tResourceProfileFilterSettings,\n\tResourceProfileSettings,\n} from \"./settings-manager.ts\";\nimport { SettingsManager } from \"./settings-manager.ts\";\nimport { time } from \"./timings.ts\";\nimport {\n\tcreateBashTool,\n\tcreateCodingTools,\n\tcreateEditTool,\n\tcreateFindTool,\n\tcreateGrepTool,\n\tcreateLsTool,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateWriteTool,\n\twithFileMutationQueue,\n} from \"./tools/index.ts\";\n\nexport interface CreateAgentSessionOptions {\n\t/** Working directory for project-local discovery. Default: process.cwd() */\n\tcwd?: string;\n\t/** Global config directory. Default: ~/.pi/agent */\n\tagentDir?: string;\n\n\t/** Auth storage for credentials. Default: AuthStorage.create(agentDir/auth.json) */\n\tauthStorage?: AuthStorage;\n\t/** Model registry. Default: ModelRegistry.create(authStorage, agentDir/models.json) */\n\tmodelRegistry?: ModelRegistry;\n\n\t/** Model to use. Default: from settings, else first available */\n\tmodel?: Model<Api>;\n\t/** Thinking level. Default: from settings, then the model's declared default, else 'medium'. */\n\tthinkingLevel?: ThinkingLevel;\n\t/** Default provider processing tier for this session. Per-request options take precedence. */\n\tserviceTier?: ServiceTier;\n\t/**\n\t * Whether `model` came from an explicit CLI/SDK flag (vs. profile/settings resolution).\n\t * When false (default), the active profile's model is re-applied on reload so live profile\n\t * edits take effect; when true, the explicit launch-time model is preserved across reloads.\n\t */\n\tisExplicitModel?: boolean;\n\t/** Whether `thinkingLevel` came from an explicit flag (see isExplicitModel). */\n\tisExplicitThinking?: boolean;\n\t/** True when this session is a spawned subagent/child — gates durable memory writes. */\n\tisChildSession?: boolean;\n\t/** Models available for cycling (Ctrl+P in interactive mode) */\n\tscopedModels?: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>;\n\n\t/**\n\t * Optional default tool suppression mode when no explicit allowlist is provided.\n\t *\n\t * - \"all\": start with no tools enabled\n\t * - \"builtin\": disable the default built-in tools (read, bash, python, edit, write,\n\t * goal, delegate, and run_toolkit_script)\n\t * but keep extension/custom tools enabled\n\t */\n\tnoTools?: \"all\" | \"builtin\";\n\t/**\n\t * Optional allowlist of tool names.\n\t *\n\t * When omitted, pi enables the shared default built-in tool surface and leaves extension/custom\n\t * tools enabled unless `noTools` changes that default.\n\t * When provided, only the listed tool names are enabled.\n\t */\n\ttools?: string[];\n\t/** Optional denylist of tool names to disable. Applies after `tools` when both are provided. */\n\texcludeTools?: string[];\n\t/** Optional resource-profile allow/block filters for tool names. */\n\ttoolProfileFilter?: ResourceProfileFilterSettings;\n\t/** Optional one-shot resource filters or complete situation profiles. Never persisted to disk. */\n\tresourceProfileDefinitions?: Record<string, ResourceProfileSettings | ProfileDefinitionInput>;\n\t/** Optional one-shot profile definitions as JSON or <resource-profile> tag text. Never persisted to disk. */\n\tresourceProfileJson?: string | string[];\n\t/** Optional runtime profile selection. Never persisted to disk. */\n\tresourceProfiles?: string[];\n\t/** Immutable owner-authored orchestration policy for this session. */\n\torchestrationProfile?: OrchestrationProfile;\n\t/** Custom tools to register (in addition to built-in tools). */\n\tcustomTools?: ToolDefinition[];\n\n\t/** Resource loader. When omitted, DefaultResourceLoader is used. */\n\tresourceLoader?: ResourceLoader;\n\n\t/** Session manager. Default: SessionManager.create(cwd, agentDir, getDefaultSessionDir(cwd, agentDir)) */\n\tsessionManager?: SessionManager;\n\n\t/** Settings manager. Default: SettingsManager.create(cwd, agentDir) */\n\tsettingsManager?: SettingsManager;\n\t/** Session start event metadata for extension runtime startup. */\n\tsessionStartEvent?: SessionStartEvent;\n}\n\n/** Result from createAgentSession */\nexport interface CreateAgentSessionResult {\n\t/** The created session */\n\tsession: AgentSession;\n\t/** Extensions result (for UI context setup in interactive mode) */\n\textensionsResult: LoadExtensionsResult;\n\t/** Warning if session was restored with a different model than saved */\n\tmodelFallbackMessage?: string;\n}\n\n// Re-exports\n\nexport * from \"./agent-session-runtime.ts\";\nexport type {\n\tExtensionAPI,\n\tExtensionCommandContext,\n\tExtensionContext,\n\tExtensionFactory,\n\tSlashCommandInfo,\n\tSlashCommandSource,\n\tToolDefinition,\n} from \"./extensions/index.ts\";\nexport type { PromptTemplate } from \"./prompt-templates.ts\";\nexport type { Skill } from \"./skills.ts\";\nexport type { Tool } from \"./tools/index.ts\";\n\nexport {\n\twithFileMutationQueue,\n\t// Tool factories (for custom cwd)\n\tcreateCodingTools,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateBashTool,\n\tcreateEditTool,\n\tcreateWriteTool,\n\tcreateGrepTool,\n\tcreateFindTool,\n\tcreateLsTool,\n};\n\n// Helper Functions\n\nfunction getDefaultAgentDir(): string {\n\treturn getAgentDir();\n}\n\nfunction getAttributionHeaders(\n\tmodel: Model<Api>,\n\tsettingsManager: SettingsManager,\n\tsessionId?: string,\n): Record<string, string> | undefined {\n\tif (\n\t\tsessionId &&\n\t\t(model.provider === \"opencode\" || model.provider === \"opencode-go\" || model.baseUrl.includes(\"opencode.ai\"))\n\t) {\n\t\treturn { \"x-opencode-session\": sessionId, \"x-opencode-client\": \"pi\" };\n\t}\n\n\tif (!isInstallTelemetryEnabled(settingsManager)) {\n\t\treturn undefined;\n\t}\n\n\tif (model.provider === \"openrouter\" || model.baseUrl.includes(\"openrouter.ai\")) {\n\t\treturn {\n\t\t\t\"HTTP-Referer\": \"https://pi.dev\",\n\t\t\t\"X-OpenRouter-Title\": \"pi\",\n\t\t\t\"X-OpenRouter-Categories\": \"cli-agent\",\n\t\t};\n\t}\n\n\tif (\n\t\tmodel.provider === \"cloudflare-workers-ai\" ||\n\t\tmodel.provider === \"cloudflare-ai-gateway\" ||\n\t\tmodel.baseUrl.includes(\"api.cloudflare.com\") ||\n\t\tmodel.baseUrl.includes(\"gateway.ai.cloudflare.com\")\n\t) {\n\t\treturn {\n\t\t\t\"User-Agent\": \"pi-coding-agent\",\n\t\t};\n\t}\n\n\treturn undefined;\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 '@caupulican/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: [\"read\", \"bash\"],\n * resourceLoader: loader,\n * sessionManager: SessionManager.inMemory(),\n * });\n * ```\n */\nexport async function createAgentSession(options: CreateAgentSessionOptions = {}): Promise<CreateAgentSessionResult> {\n\tconst cwd = resolvePath(options.cwd ?? options.sessionManager?.getCwd() ?? process.cwd());\n\tconst agentDir = options.agentDir ? resolvePath(options.agentDir) : getDefaultAgentDir();\n\tlet resourceLoader = options.resourceLoader;\n\n\t// Use provided or create AuthStorage and ModelRegistry\n\tconst authPath = options.agentDir ? configFile(agentDir, \"auth.json\") : undefined;\n\tconst modelsPath = options.agentDir ? configFile(agentDir, \"models.json\") : undefined;\n\tconst authStorage = options.authStorage ?? AuthStorage.create(authPath);\n\tconst modelRegistry = options.modelRegistry ?? ModelRegistry.create(authStorage, modelsPath);\n\n\tconst settingsManager = options.settingsManager ?? SettingsManager.create(cwd, agentDir);\n\tbindSavedBedrockScope(settingsManager, modelRegistry);\n\tconst isChildSession = options.isChildSession ?? process.env.PI_CHILD_SESSION === \"1\";\n\tconst forceBackgroundRequests = isChildSession || isWorkerSession();\n\tconst defaultServiceTier = options.serviceTier;\n\tconst orchestrationProfile = options.orchestrationProfile;\n\tif (orchestrationProfile) {\n\t\tvalidateOrchestrationProfile(orchestrationProfile);\n\t\tconst conflictingOptions = [\n\t\t\t...(options.model ? [\"model\"] : []),\n\t\t\t...(options.thinkingLevel !== undefined ? [\"thinkingLevel\"] : []),\n\t\t\t...(options.scopedModels !== undefined ? [\"scopedModels\"] : []),\n\t\t\t...(options.tools !== undefined ? [\"tools\"] : []),\n\t\t\t...(options.noTools !== undefined ? [\"noTools\"] : []),\n\t\t\t...(options.excludeTools !== undefined ? [\"excludeTools\"] : []),\n\t\t\t...(options.toolProfileFilter !== undefined ? [\"toolProfileFilter\"] : []),\n\t\t\t...(options.resourceProfiles !== undefined ? [\"resourceProfiles\"] : []),\n\t\t];\n\t\tif (conflictingOptions.length > 0) {\n\t\t\tthrow new TypeError(\n\t\t\t\t`Orchestration profile '${orchestrationProfile.profileId}' owns model, thinking, tools, and resources; remove conflicting SDK options: ${conflictingOptions.join(\", \")}.`,\n\t\t\t);\n\t\t}\n\t\tsettingsManager.setRuntimeResourceProfiles([...orchestrationProfile.resourceProfileNames]);\n\t}\n\tconst needsProfileReload =\n\t\toptions.resourceProfileDefinitions !== undefined ||\n\t\toptions.resourceProfileJson !== undefined ||\n\t\toptions.resourceProfiles !== undefined ||\n\t\torchestrationProfile !== undefined;\n\tif (options.resourceProfileDefinitions) {\n\t\tsettingsManager.addInlineResourceProfileDefinitions(options.resourceProfileDefinitions);\n\t}\n\tif (options.resourceProfileJson) {\n\t\tconst inputs = Array.isArray(options.resourceProfileJson)\n\t\t\t? options.resourceProfileJson\n\t\t\t: [options.resourceProfileJson];\n\t\tfor (const input of inputs) {\n\t\t\tsettingsManager.addInlineResourceProfileDefinitions(parseResourceProfileInput(input).profiles);\n\t\t}\n\t}\n\tif (!orchestrationProfile && options.resourceProfiles !== undefined) {\n\t\tsettingsManager.setRuntimeResourceProfiles(options.resourceProfiles);\n\t}\n\tconst sessionManager =\n\t\toptions.sessionManager ?? SessionManager.create(cwd, agentDir, getDefaultSessionDir(cwd, agentDir));\n\n\tif (!resourceLoader) {\n\t\tresourceLoader = new DefaultResourceLoader({ cwd, agentDir, settingsManager });\n\t\tawait resourceLoader.reload();\n\t\ttime(\"resourceLoader.reload\");\n\t} else if (needsProfileReload) {\n\t\tawait resourceLoader.reload();\n\t\ttime(\"resourceLoader.reload\");\n\t}\n\n\t// Check if session has existing data to restore\n\tconst existingSession = sessionManager.buildSessionContext();\n\tconst hasExistingSession = existingSession.messages.length > 0;\n\tconst hasThinkingEntry = sessionManager.getBranch().some((entry) => entry.type === \"thinking_level_change\");\n\n\tconst orchestrationModel = orchestrationProfile\n\t\t? resolveConfiguredOrchestrationModel(orchestrationProfile, modelRegistry)\n\t\t: undefined;\n\tif (orchestrationProfile && !orchestrationModel) {\n\t\tthrow new TypeError(\n\t\t\t`Orchestration profile '${orchestrationProfile.profileId}' has no configured, authenticated model that supports its exact thinking level.`,\n\t\t);\n\t}\n\tlet model = orchestrationModel?.model ?? options.model;\n\tlet modelFallbackMessage: string | undefined;\n\n\tlet thinkingLevel = orchestrationModel?.binding.thinkingLevel ?? options.thinkingLevel;\n\n\tconst activeProfileNames = settingsManager.getActiveResourceProfileNames();\n\tif (!orchestrationProfile && activeProfileNames.length > 0) {\n\t\tconst profileSettings = resolveProfileModelSettings({\n\t\t\tactiveProfileNames,\n\t\t\tregistry: settingsManager.getProfileRegistry(),\n\t\t\tmodelRegistry,\n\t\t\tcwd,\n\t\t});\n\t\tif (profileSettings.error) {\n\t\t\tmodelFallbackMessage = `Profile model resolution error: ${profileSettings.error}`;\n\t\t}\n\t\tif (!model && profileSettings.model) {\n\t\t\tmodel = profileSettings.model;\n\t\t}\n\t\tif (thinkingLevel === undefined && profileSettings.thinkingLevel) {\n\t\t\tthinkingLevel = profileSettings.thinkingLevel;\n\t\t}\n\t}\n\n\t// If session has data, try to restore model from it\n\tif (!model && hasExistingSession && existingSession.model) {\n\t\tconst restoredModel = modelRegistry.find(existingSession.model.provider, existingSession.model.modelId);\n\t\tif (restoredModel && modelRegistry.hasConfiguredAuth(restoredModel)) {\n\t\t\tmodel = restoredModel;\n\t\t}\n\t\tif (!model) {\n\t\t\tmodelFallbackMessage = `Could not restore model ${existingSession.model.provider}/${existingSession.model.modelId}`;\n\t\t}\n\t}\n\n\t// If still no model, use findInitialModel (checks settings default, then provider defaults)\n\tif (!model) {\n\t\tconst result = await findInitialModel({\n\t\t\tscopedModels: [],\n\t\t\tisContinuing: hasExistingSession,\n\t\t\tdefaultProvider: settingsManager.getDefaultProvider(),\n\t\t\tdefaultModelId: settingsManager.getDefaultModel(),\n\t\t\tdefaultThinkingLevel: settingsManager.getDefaultThinkingLevel(),\n\t\t\tmodelRegistry,\n\t\t});\n\t\tmodel = result.model;\n\t\tif (thinkingLevel === undefined && !(hasExistingSession && hasThinkingEntry)) {\n\t\t\tthinkingLevel = result.thinkingLevel;\n\t\t}\n\t\tif (!model) {\n\t\t\tmodelFallbackMessage = formatNoModelsAvailableMessage();\n\t\t} else if (modelFallbackMessage) {\n\t\t\tmodelFallbackMessage += `. Using ${model.provider}/${model.id}`;\n\t\t}\n\t}\n\n\t// If session has data, restore thinking level from it\n\tif (thinkingLevel === undefined && hasExistingSession) {\n\t\tthinkingLevel = hasThinkingEntry\n\t\t\t? (existingSession.thinkingLevel as ThinkingLevel)\n\t\t\t: settingsManager.getDefaultThinkingLevel();\n\t}\n\n\t// Resolve preference, model metadata, harness fallback, and capability clamping through the\n\t// same contract used by CLI startup and isolated lanes.\n\tif (!model) {\n\t\tthinkingLevel = \"off\";\n\t} else {\n\t\tthinkingLevel = resolveModelThinkingLevel(\n\t\t\tmodel,\n\t\t\tthinkingLevel ?? settingsManager.getDefaultThinkingLevel(),\n\t\t) as ThinkingLevel;\n\t}\n\n\tconst defaultActiveToolNames = [\n\t\t...DEFAULT_ACTIVE_TOOL_NAMES,\n\t\t...(settingsManager.getScoutSettings().enabled ? [\"context_scout\"] : []),\n\t];\n\tconst toolProfileFilter = orchestrationProfile\n\t\t? settingsManager.getResourceProfileFilter(\"tools\")\n\t\t: (options.toolProfileFilter ?? settingsManager.getResourceProfileFilter(\"tools\"));\n\tconst allowedToolNames = orchestrationProfile\n\t\t? [...orchestrationProfile.toolNames]\n\t\t: (options.tools ?? (options.noTools === \"all\" ? [] : undefined));\n\tconst excludedToolNames = orchestrationProfile ? undefined : options.excludeTools;\n\tconst excludedToolNameSet = excludedToolNames ? new Set(excludedToolNames) : undefined;\n\tconst initialActiveToolNames: string[] = (\n\t\torchestrationProfile\n\t\t\t? [...orchestrationProfile.toolNames]\n\t\t\t: options.tools\n\t\t\t\t? [...options.tools]\n\t\t\t\t: options.noTools\n\t\t\t\t\t? []\n\t\t\t\t\t: defaultActiveToolNames\n\t).filter((name) => !excludedToolNameSet?.has(name));\n\n\tlet agent: Agent;\n\n\t// Create convertToLlm wrapper that filters images if blockImages is enabled (defense-in-depth)\n\tconst convertToLlmWithBlockImages = (messages: AgentMessage[]): Message[] => {\n\t\tconst converted = convertToLlm(messages);\n\t\t// Check setting dynamically so mid-session changes take effect\n\t\tif (!settingsManager.getBlockImages()) {\n\t\t\treturn converted;\n\t\t}\n\t\t// Filter out ImageContent from all messages, replacing with text placeholder\n\t\treturn converted.map((msg) => {\n\t\t\tif (msg.role === \"user\" || msg.role === \"toolResult\") {\n\t\t\t\tconst content = msg.content;\n\t\t\t\tif (Array.isArray(content)) {\n\t\t\t\t\tconst hasImages = content.some((c) => c.type === \"image\");\n\t\t\t\t\tif (hasImages) {\n\t\t\t\t\t\tconst filteredContent = content\n\t\t\t\t\t\t\t.map((c) =>\n\t\t\t\t\t\t\t\tc.type === \"image\" ? { type: \"text\" as const, text: \"Image reading is disabled.\" } : c,\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t.filter(\n\t\t\t\t\t\t\t\t(c, i, arr) =>\n\t\t\t\t\t\t\t\t\t// Dedupe consecutive \"Image reading is disabled.\" texts\n\t\t\t\t\t\t\t\t\t!(\n\t\t\t\t\t\t\t\t\t\tc.type === \"text\" &&\n\t\t\t\t\t\t\t\t\t\tc.text === \"Image reading is disabled.\" &&\n\t\t\t\t\t\t\t\t\t\ti > 0 &&\n\t\t\t\t\t\t\t\t\t\tarr[i - 1].type === \"text\" &&\n\t\t\t\t\t\t\t\t\t\t(arr[i - 1] as { type: \"text\"; text: string }).text === \"Image reading is disabled.\"\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\treturn { ...msg, content: filteredContent };\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn msg;\n\t\t});\n\t};\n\n\tconst extensionRunnerRef: { current?: ExtensionRunner } = {};\n\n\tagent = new Agent({\n\t\tinitialState: {\n\t\t\tsystemPrompt: \"\",\n\t\t\tmodel,\n\t\t\tthinkingLevel,\n\t\t\ttools: [],\n\t\t},\n\t\tconvertToLlm: convertToLlmWithBlockImages,\n\t\tstreamFn: async (model, context, options) => {\n\t\t\tconst bedrockScope =\n\t\t\t\tmodel.provider === BEDROCK_PROVIDER_ID ? getActiveBedrockScope(settingsManager) : undefined;\n\t\t\tif (model.provider === BEDROCK_PROVIDER_ID && !bedrockScope && !isUnscopedBedrockProxy()) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Amazon Bedrock requires a verified profile/region scope. Run /login amazon-bedrock before using this model.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst auth = await modelRegistry.getApiKeyAndHeaders(model);\n\t\t\tif (!auth.ok) {\n\t\t\t\tthrow new Error(auth.error);\n\t\t\t}\n\t\t\tconst providerRetrySettings = settingsManager.getProviderRetrySettings();\n\t\t\tconst httpIdleTimeoutMs = settingsManager.getHttpIdleTimeoutMs();\n\t\t\t// SDKs treat timeout=0 as 0ms (immediate timeout), not \"no timeout\".\n\t\t\t// Use max int32 to effectively disable the timeout.\n\t\t\tconst effectiveTimeoutMs = httpIdleTimeoutMs === 0 ? 2147483647 : httpIdleTimeoutMs;\n\t\t\tconst timeoutMs = options?.timeoutMs ?? providerRetrySettings.timeoutMs ?? effectiveTimeoutMs;\n\t\t\tconst websocketConnectTimeoutMs =\n\t\t\t\toptions?.websocketConnectTimeoutMs ?? settingsManager.getWebSocketConnectTimeoutMs();\n\t\t\tconst attributionHeaders = getAttributionHeaders(model, settingsManager, options?.sessionId);\n\t\t\tconst fastModeServiceTier = resolveFastModeServiceTier(\n\t\t\t\tmodel,\n\t\t\t\tsettingsManager.getFastModeEnabled(model.provider),\n\t\t\t);\n\t\t\tconst providerOptions = {\n\t\t\t\t...options,\n\t\t\t\tserviceTier:\n\t\t\t\t\toptions?.serviceTier === undefined ? (fastModeServiceTier ?? defaultServiceTier) : options.serviceTier,\n\t\t\t\t...(bedrockScope ? { region: bedrockScope.region, profile: bedrockScope.profile } : {}),\n\t\t\t\tinteractionMode: forceBackgroundRequests ? \"background\" : (options?.interactionMode ?? \"user\"),\n\t\t\t\tonInteractiveAuthRecovery: options?.onInteractiveAuthRecovery ?? recoverBedrockSsoAuthentication,\n\t\t\t\tapiKey: auth.apiKey,\n\t\t\t\tonAuthRejection:\n\t\t\t\t\tauth.apiKey && model.provider === \"openai-codex\"\n\t\t\t\t\t\t? async () => modelRegistry.recoverRejectedOAuthApiKey(model.provider, auth.apiKey as string)\n\t\t\t\t\t\t: options?.onAuthRejection,\n\t\t\t\ttimeoutMs,\n\t\t\t\twebsocketConnectTimeoutMs,\n\t\t\t\tmaxRetries: options?.maxRetries ?? providerRetrySettings.maxRetries,\n\t\t\t\tmaxRetryDelayMs: options?.maxRetryDelayMs ?? providerRetrySettings.maxRetryDelayMs,\n\t\t\t\theaders:\n\t\t\t\t\tattributionHeaders || auth.headers || options?.headers\n\t\t\t\t\t\t? { ...attributionHeaders, ...auth.headers, ...options?.headers }\n\t\t\t\t\t\t: undefined,\n\t\t\t};\n\t\t\treturn streamSimple(model, context, providerOptions);\n\t\t},\n\t\tonPayload: async (payload, _model) => {\n\t\t\tconst runner = extensionRunnerRef.current;\n\t\t\tif (!runner?.hasHandlers(\"before_provider_request\")) {\n\t\t\t\treturn payload;\n\t\t\t}\n\t\t\treturn runner.emitBeforeProviderRequest(payload);\n\t\t},\n\t\tonResponse: async (response, _model) => {\n\t\t\tconst runner = extensionRunnerRef.current;\n\t\t\tif (!runner?.hasHandlers(\"after_provider_response\")) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tawait runner.emit({\n\t\t\t\ttype: \"after_provider_response\",\n\t\t\t\tstatus: response.status,\n\t\t\t\theaders: response.headers,\n\t\t\t});\n\t\t},\n\t\tsessionId: sessionManager.getSessionId(),\n\t\tsteeringMode: settingsManager.getSteeringMode(),\n\t\tfollowUpMode: settingsManager.getFollowUpMode(),\n\t\ttransport: settingsManager.getTransport(),\n\t\tthinkingBudgets: settingsManager.getThinkingBudgets(),\n\t\tmaxRetryDelayMs: settingsManager.getProviderRetrySettings().maxRetryDelayMs,\n\t});\n\n\t// Restore messages if session has existing data\n\tif (hasExistingSession) {\n\t\tagent.state.messages = existingSession.messages;\n\t\tif (!hasThinkingEntry) {\n\t\t\tsessionManager.appendThinkingLevelChange(thinkingLevel);\n\t\t}\n\t} else {\n\t\t// Save initial model and thinking level for new sessions so they can be restored on resume\n\t\tif (model) {\n\t\t\tsessionManager.appendModelChange(model.provider, model.id);\n\t\t}\n\t\tsessionManager.appendThinkingLevelChange(thinkingLevel);\n\t}\n\n\tconst session = new AgentSession({\n\t\tagent,\n\t\tsessionManager,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tagentDir,\n\t\tscopedModels: orchestrationModel\n\t\t\t? [{ model: orchestrationModel.model, thinkingLevel: orchestrationModel.binding.thinkingLevel }]\n\t\t\t: options.scopedModels,\n\t\tresourceLoader,\n\t\tcustomTools: options.customTools,\n\t\tmodelRegistry,\n\t\tinitialActiveToolNames,\n\t\tallowedToolNames,\n\t\texcludedToolNames,\n\t\textensionRunnerRef,\n\t\ttoolProfileFilter,\n\t\tisExplicitModel: orchestrationProfile ? true : (options.isExplicitModel ?? options.model != null),\n\t\tisExplicitThinking: orchestrationProfile\n\t\t\t? true\n\t\t\t: (options.isExplicitThinking ?? options.thinkingLevel !== undefined),\n\t\tisChildSession,\n\t\torchestrationProfile,\n\t\tsessionStartEvent: options.sessionStartEvent,\n\t});\n\ttry {\n\t\t// The initial runtime has now bound providers from profile-granted extensions. Re-resolve the\n\t\t// profile model against that authoritative registry generation, then resync model capability.\n\t\tawait session.reapplyActiveProfileModelSettings();\n\t\tif (modelFallbackMessage?.startsWith(\"Profile model resolution error:\")) {\n\t\t\tmodelFallbackMessage = undefined;\n\t\t}\n\t} catch (error) {\n\t\t// Preserve the established non-fatal fallback for a genuinely unresolved profile model.\n\t\tif (!modelFallbackMessage?.startsWith(\"Profile model resolution error:\")) {\n\t\t\tawait session.disposeAndWait();\n\t\t\tthrow error;\n\t\t}\n\t}\n\t// File-store memory tools exist only after providers initialize. Do this here so an SDK session\n\t// that never calls bindExtensions still has the requested `memory` tool when the grant allows it.\n\tawait session.initializeMemory();\n\tconst extensionsResult = resourceLoader.getExtensions();\n\n\treturn {\n\t\tsession,\n\t\textensionsResult,\n\t\tmodelFallbackMessage,\n\t};\n}\n"]}
@@ -204,7 +204,7 @@ export function credentialToolBlockReason(toolName, args, cwd, boundary) {
204
204
  const glob = typeof args.glob === "string" ? args.glob : undefined;
205
205
  if ((path && isProtectedCredentialPath(path, cwd, boundary)) ||
206
206
  (glob && /(?:^|[\\/])?\.env(?:\.|\*|$)/i.test(glob))) {
207
- return "Credential dotenv files are model-blind. Use secret_store migrate with the file path instead of searching its contents.";
207
+ return "Credential dotenv files are model-blind. Use secret_store discover instead of searching their contents.";
208
208
  }
209
209
  if (!(path && isExistingRegularFile(path, cwd)) && !(glob && isCredentialSafeGlob(glob))) {
210
210
  return "Credential-safe grep requires one explicit regular file or a narrow non-dotenv file glob (for example *.ts). Refine the search instead of scanning a directory without a file filter.";
@@ -215,7 +215,7 @@ export function credentialToolBlockReason(toolName, args, cwd, boundary) {
215
215
  const pattern = typeof args.pattern === "string" ? args.pattern : undefined;
216
216
  if ((path && isProtectedCredentialPath(path, cwd, boundary)) ||
217
217
  (pattern && /(?:^|[\\/])?\.env(?:\.|\*|$)/i.test(pattern))) {
218
- return "Credential dotenv files are model-blind. Use secret_store migrate with a known file path instead of discovering their contents.";
218
+ return "Credential dotenv files are model-blind. Use secret_store discover instead of searching their contents.";
219
219
  }
220
220
  }
221
221
  if (toolName === "bash" || toolName === "powershell" || toolName === "run_process") {
@@ -225,7 +225,7 @@ export function credentialToolBlockReason(toolName, args, cwd, boundary) {
225
225
  return "Credential-safe shell search requires a narrow non-dotenv file glob (for example -g '*.ts') or one explicit regular file. Refine the rg/grep command before retrying.";
226
226
  }
227
227
  if (shellRisk === "process_environment") {
228
- return "Direct process-environment projection is blocked because it can expose credentials. Use secret_store migrate with known environment-variable names.";
228
+ return "Direct process-environment projection is blocked because it can expose credentials. Use secret_store discover to list eligible source names without exposing values.";
229
229
  }
230
230
  if (SHELL_SECRET_READ_RE.test(command) || shellRisk === "credential_path") {
231
231
  return "Direct shell inspection of credential files is blocked. Use secret_store migrate with the file path, then run the credential-consuming command normally.";