@astralyn/pi 0.87.2 → 0.87.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/bundle/chunks/{chunk-NBIUJDV6.js → chunk-ANT4TSUE.js} +1 -1
  3. package/dist/bundle/chunks/{chunk-RFLBIA5Z.js → chunk-CUDKRZ2V.js} +37 -24
  4. package/dist/bundle/chunks/{virtual-modules-GOHLE5JL.js → virtual-modules-Y2YZRMU3.js} +1 -1
  5. package/dist/bundle/cli.js +1 -1
  6. package/dist/bundle/index.js +1 -1
  7. package/dist/bundle/rpc-entry.js +1 -1
  8. package/dist/core/background/service.d.ts.map +1 -1
  9. package/dist/core/background/service.js +4 -3
  10. package/dist/core/background/service.js.map +1 -1
  11. package/dist/core/background/types.d.ts +11 -0
  12. package/dist/core/background/types.d.ts.map +1 -1
  13. package/dist/core/background/types.js +14 -0
  14. package/dist/core/background/types.js.map +1 -1
  15. package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  16. package/dist/core/tools/tool-definition-wrapper.js +121 -1
  17. package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  18. package/dist/extensions/background/actions.d.ts.map +1 -1
  19. package/dist/extensions/background/actions.js +126 -67
  20. package/dist/extensions/background/actions.js.map +1 -1
  21. package/dist/extensions/background/index.js +3 -3
  22. package/dist/extensions/background/index.js.map +1 -1
  23. package/dist/extensions/question/index.d.ts.map +1 -1
  24. package/dist/extensions/question/index.js +3 -1
  25. package/dist/extensions/question/index.js.map +1 -1
  26. package/dist/extensions/question/schema.d.ts +18 -0
  27. package/dist/extensions/question/schema.d.ts.map +1 -1
  28. package/dist/extensions/question/schema.js +52 -0
  29. package/dist/extensions/question/schema.js.map +1 -1
  30. package/dist/extensions/subagent/index.d.ts.map +1 -1
  31. package/dist/extensions/subagent/index.js +3 -1
  32. package/dist/extensions/subagent/index.js.map +1 -1
  33. package/dist/extensions/subagent/resolve.d.ts +14 -1
  34. package/dist/extensions/subagent/resolve.d.ts.map +1 -1
  35. package/dist/extensions/subagent/resolve.js +32 -18
  36. package/dist/extensions/subagent/resolve.js.map +1 -1
  37. package/dist/extensions/subagent/runner.d.ts.map +1 -1
  38. package/dist/extensions/subagent/runner.js +4 -1
  39. package/dist/extensions/subagent/runner.js.map +1 -1
  40. package/dist/extensions/subagent/schema.d.ts +9 -0
  41. package/dist/extensions/subagent/schema.d.ts.map +1 -1
  42. package/dist/extensions/subagent/schema.js +30 -1
  43. package/dist/extensions/subagent/schema.js.map +1 -1
  44. package/dist/extensions/subagent/types.d.ts +2 -0
  45. package/dist/extensions/subagent/types.d.ts.map +1 -1
  46. package/dist/extensions/subagent/types.js.map +1 -1
  47. package/dist/extensions/todo/constants.d.ts +1 -1
  48. package/dist/extensions/todo/constants.d.ts.map +1 -1
  49. package/dist/extensions/todo/constants.js +8 -8
  50. package/dist/extensions/todo/constants.js.map +1 -1
  51. package/dist/extensions/todo/index.d.ts.map +1 -1
  52. package/dist/extensions/todo/index.js +2 -1
  53. package/dist/extensions/todo/index.js.map +1 -1
  54. package/dist/extensions/todo/schema.d.ts +30 -25
  55. package/dist/extensions/todo/schema.d.ts.map +1 -1
  56. package/dist/extensions/todo/schema.js +26 -20
  57. package/dist/extensions/todo/schema.js.map +1 -1
  58. package/dist/extensions/todo/state.d.ts +12 -8
  59. package/dist/extensions/todo/state.d.ts.map +1 -1
  60. package/dist/extensions/todo/state.js +257 -171
  61. package/dist/extensions/todo/state.js.map +1 -1
  62. package/dist/extensions/todo/view.d.ts +6 -2
  63. package/dist/extensions/todo/view.d.ts.map +1 -1
  64. package/dist/extensions/todo/view.js +234 -144
  65. package/dist/extensions/todo/view.js.map +1 -1
  66. package/docs/bundled/extensions/background.md +1 -1
  67. package/docs/bundled/extensions/question.md +1 -0
  68. package/docs/bundled/extensions/subagent.md +3 -1
  69. package/docs/bundled/extensions/todo.md +35 -23
  70. package/docs/extensions.md +2 -0
  71. package/npm-shrinkwrap.json +2 -2
  72. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tool-definition-wrapper.js","sourceRoot":"","sources":["../../../src/core/tools/tool-definition-wrapper.ts"],"names":[],"mappings":"AAQA,oEAAoE;AACpE,MAAM,UAAU,kBAAkB,CACjC,UAA6C,EAC7C,UAAmC;IAEnC,OAAO;QACN,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,mBAAmB,EAAE,UAAU,CAAC,mBAAmB;QACnD,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;QAC7C,aAAa,EAAE,UAAU,CAAC,aAAa;QACvC,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAsB,EAAE,EAAE,CACzE,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAK,UAAU,EAAE,EAAuB,CAAC;KACtG,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,mBAAmB,CAClC,WAAuC,EACvC,UAAmC;IAEnC,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AACpF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iCAAiC,CAChD,IAA6C;IAE7C,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;QAC7C,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;KAC3G,CAAC;AACH,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { TSchema } from \"typebox\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\n\ntype PresentableAgentTool<TParams extends TSchema = TSchema, TDetails = unknown> = AgentTool<TParams, TDetails> & {\n\ttoolGroup?: string;\n};\n\n/** Wrap a ToolDefinition into an AgentTool for the core runtime. */\nexport function wrapToolDefinition<TParams extends TSchema, TDetails = unknown>(\n\tdefinition: ToolDefinition<TParams, TDetails>,\n\tctxFactory?: () => ExtensionContext,\n): PresentableAgentTool<TParams, TDetails> {\n\treturn {\n\t\tname: definition.name,\n\t\tlabel: definition.label,\n\t\tdescription: definition.description,\n\t\tparameters: definition.parameters,\n\t\tconstrainedSampling: definition.constrainedSampling,\n\t\ttoolGroup: definition.toolGroup,\n\t\tprepareArguments: definition.prepareArguments,\n\t\texecutionMode: definition.executionMode,\n\t\texecute: (toolCallId, params, signal, onUpdate, ctx?: ExtensionContext) =>\n\t\t\tdefinition.execute(toolCallId, params, signal, onUpdate, ctx ?? (ctxFactory?.() as ExtensionContext)),\n\t};\n}\n\n/** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */\nexport function wrapToolDefinitions(\n\tdefinitions: ToolDefinition<any, any>[],\n\tctxFactory?: () => ExtensionContext,\n): AgentTool<any>[] {\n\treturn definitions.map((definition) => wrapToolDefinition(definition, ctxFactory));\n}\n\n/**\n * Synthesize a minimal ToolDefinition from an AgentTool.\n *\n * This keeps AgentSession's internal registry definition-first even when a caller\n * provides plain AgentTool overrides that do not include prompt metadata or renderers.\n */\nexport function createToolDefinitionFromAgentTool<TParams extends TSchema, TDetails>(\n\ttool: PresentableAgentTool<TParams, TDetails>,\n): ToolDefinition<TParams, TDetails> {\n\treturn {\n\t\tname: tool.name,\n\t\tlabel: tool.label,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters,\n\t\tconstrainedSampling: tool.constrainedSampling,\n\t\ttoolGroup: tool.toolGroup,\n\t\tprepareArguments: tool.prepareArguments,\n\t\texecutionMode: tool.executionMode,\n\t\texecute: async (toolCallId, params, signal, onUpdate) => tool.execute(toolCallId, params, signal, onUpdate),\n\t};\n}\n"]}
1
+ {"version":3,"file":"tool-definition-wrapper.js","sourceRoot":"","sources":["../../../src/core/tools/tool-definition-wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG/E,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAM7C,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;AAC9D,MAAM,WAAW,GAAG,YAAY,CAAC;AACjC,MAAM,4BAA4B,GAAG,CAAC,GAAG,IAAI,CAAC;AAC9C,MAAM,4BAA4B,GAAG,EAAE,CAAC;AACxC,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,iBAAiB,CAAC,MAAe,EAAE,IAAa;IACxD,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,KAAK,GAAG,CAAC,IAAa,EAAE,KAAc,EAAE,IAAY,EAAQ,EAAE;QACnE,IAAI,KAAK,CAAC,MAAM,IAAI,eAAe,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;YAAE,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AE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAsB,EAAE,EAAE,CACzE,UAAU,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAK,UAAU,EAAE,EAAuB,CAAC;KACtG,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,mBAAmB,CAClC,WAAuC,EACvC,UAAmC;IAEnC,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC;AACpF,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iCAAiC,CAChD,IAA6C;IAE7C,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,mBAAmB,EAAE,IAAI,CAAC,mBAAmB;QAC7C,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;QACvC,aAAa,EAAE,IAAI,CAAC,aAAa;QACjC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC;KAC3G,CAAC;AACH,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport { type JsonObject, validateToolArguments } from \"@earendil-works/pi-ai\";\nimport type { Static, TSchema } from \"typebox\";\nimport type { ExtensionContext, ToolDefinition } from \"../extensions/types.ts\";\nimport { truncateHead } from \"./truncate.ts\";\n\ntype PresentableAgentTool<TParams extends TSchema = TSchema, TDetails = unknown> = AgentTool<TParams, TDetails> & {\n\ttoolGroup?: string;\n};\n\nconst RECEIVED_ARGUMENTS_MARKER = \"\\n\\nReceived arguments:\\n\";\nconst HINT_MARKER = \"\\n\\nHint: \";\nconst RECEIVED_ARGUMENTS_MAX_BYTES = 2 * 1024;\nconst RECEIVED_ARGUMENTS_MAX_LINES = 40;\nconst FIELD_HINTS_MAX = 10;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n\n/**\n * Walk schema and arguments in sync to name, at every object with\n * `additionalProperties: false`, the non-null fields the schema does not\n * declare, and at every object, the required fields the arguments lack. The\n * validator's own report says where validation failed; these hints say what\n * the legal shape is. Union variants (`anyOf`, e.g. a nullable field) are\n * walked through so nested shapes still get hints. Paths use the validator's\n * dotted style\n * (`tasks[0].prompt`). Non-null unknown fields are reported rather than\n * silently dropped: a field like `prompt_extra` may carry briefing content\n * the caller intended to send.\n */\nfunction collectFieldHints(schema: unknown, args: unknown): string[] {\n\tconst hints: string[] = [];\n\tconst visit = (node: unknown, value: unknown, path: string): void => {\n\t\tif (hints.length >= FIELD_HINTS_MAX || !isRecord(node)) return;\n\t\tif (Array.isArray(node.anyOf)) {\n\t\t\tfor (const variant of node.anyOf) visit(variant, value, path);\n\t\t\treturn;\n\t\t}\n\t\tif (node.type === \"array\" && Array.isArray(value)) {\n\t\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\t\tvisit(node.items, value[index], `${path}[${index}]`);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tif (node.type !== \"object\" || !isRecord(value)) return;\n\t\tconst properties = isRecord(node.properties) ? node.properties : {};\n\t\tconst fields = Object.keys(properties);\n\t\tconst where = path || \"root\";\n\t\tif (node.additionalProperties === false) {\n\t\t\tfor (const [key, entry] of Object.entries(value)) {\n\t\t\t\tif (entry !== null && !(key in properties) && hints.length < FIELD_HINTS_MAX) {\n\t\t\t\t\tconst subject = path ? `${path}.${key}` : key;\n\t\t\t\t\thints.push(`${subject} is not a field; fields at ${where}: ${fields.join(\", \")}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (Array.isArray(node.required)) {\n\t\t\tfor (const key of node.required) {\n\t\t\t\tif (typeof key === \"string\" && value[key] === undefined && hints.length < FIELD_HINTS_MAX) {\n\t\t\t\t\tconst subject = path ? `${path}.${key}` : key;\n\t\t\t\t\thints.push(`${subject} is required; fields at ${where}: ${fields.join(\", \")}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tfor (const key of fields) {\n\t\t\tif (value[key] !== undefined && value[key] !== null) {\n\t\t\t\tvisit(properties[key], value[key], path ? `${path}.${key}` : key);\n\t\t\t}\n\t\t}\n\t};\n\tvisit(schema, args, \"\");\n\treturn hints;\n}\n\n/**\n * Rebuild pi-ai's validation error so a model can self-correct: the legal\n * fields are named next to each offending one, and the echoed arguments are\n * bounded (a 50KB subagent prompt must not be reflected whole into context).\n * The `Validation failed for tool \"<name>\":` prefix stays intact — the\n * question tool's renderer parses it.\n */\nfunction enrichValidationError(error: unknown, parameters: TSchema, args: unknown): Error {\n\tconst message = error instanceof Error ? error.message : String(error);\n\t// A definition synthesized from an already-wrapped tool enriches on the\n\t// inside; do not stack a second layer of hints on the same failure.\n\tif (message.includes(HINT_MARKER)) return error instanceof Error ? error : new Error(message);\n\tconst hints = collectFieldHints(parameters, args);\n\tconst markerIndex = message.indexOf(RECEIVED_ARGUMENTS_MARKER);\n\tconst head = markerIndex === -1 ? message : message.slice(0, markerIndex);\n\tconst received = markerIndex === -1 ? \"\" : message.slice(markerIndex + RECEIVED_ARGUMENTS_MARKER.length);\n\tlet enriched = hints.length > 0 ? `${head}\\n\\nHint: ${hints.join(\"\\nHint: \")}` : head;\n\tif (markerIndex !== -1) {\n\t\tconst bounded = truncateHead(received, {\n\t\t\tmaxBytes: RECEIVED_ARGUMENTS_MAX_BYTES,\n\t\t\tmaxLines: RECEIVED_ARGUMENTS_MAX_LINES,\n\t\t});\n\t\tenriched += `${RECEIVED_ARGUMENTS_MARKER}${bounded.content}`;\n\t\tif (bounded.truncated) enriched += \"\\n… (arguments truncated)\";\n\t}\n\treturn new Error(enriched);\n}\n\n/**\n * Pre-validate prepared arguments so a validation failure reaches the model\n * with field-level hints. Valid arguments pass through untouched and are\n * validated again by the agent loop as before.\n */\nfunction wrapPrepareArguments<TParams extends TSchema, TDetails>(\n\tdefinition: ToolDefinition<TParams, TDetails>,\n): (raw: unknown) => Static<TParams> {\n\tconst tool = { name: definition.name, description: definition.description, parameters: definition.parameters };\n\treturn (raw: unknown): Static<TParams> => {\n\t\tconst args = definition.prepareArguments ? definition.prepareArguments(raw) : raw;\n\t\ttry {\n\t\t\tvalidateToolArguments(tool, {\n\t\t\t\ttype: \"toolCall\",\n\t\t\t\tid: \"\",\n\t\t\t\tname: definition.name,\n\t\t\t\targuments: args as JsonObject,\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tthrow enrichValidationError(error, definition.parameters, args);\n\t\t}\n\t\treturn args as Static<TParams>;\n\t};\n}\n\n/** Wrap a ToolDefinition into an AgentTool for the core runtime. */\nexport function wrapToolDefinition<TParams extends TSchema, TDetails = unknown>(\n\tdefinition: ToolDefinition<TParams, TDetails>,\n\tctxFactory?: () => ExtensionContext,\n): PresentableAgentTool<TParams, TDetails> {\n\treturn {\n\t\tname: definition.name,\n\t\tlabel: definition.label,\n\t\tdescription: definition.description,\n\t\tparameters: definition.parameters,\n\t\tconstrainedSampling: definition.constrainedSampling,\n\t\ttoolGroup: definition.toolGroup,\n\t\tprepareArguments: wrapPrepareArguments(definition),\n\t\texecutionMode: definition.executionMode,\n\t\texecute: (toolCallId, params, signal, onUpdate, ctx?: ExtensionContext) =>\n\t\t\tdefinition.execute(toolCallId, params, signal, onUpdate, ctx ?? (ctxFactory?.() as ExtensionContext)),\n\t};\n}\n\n/** Wrap multiple ToolDefinitions into AgentTools for the core runtime. */\nexport function wrapToolDefinitions(\n\tdefinitions: ToolDefinition<any, any>[],\n\tctxFactory?: () => ExtensionContext,\n): AgentTool<any>[] {\n\treturn definitions.map((definition) => wrapToolDefinition(definition, ctxFactory));\n}\n\n/**\n * Synthesize a minimal ToolDefinition from an AgentTool.\n *\n * This keeps AgentSession's internal registry definition-first even when a caller\n * provides plain AgentTool overrides that do not include prompt metadata or renderers.\n */\nexport function createToolDefinitionFromAgentTool<TParams extends TSchema, TDetails>(\n\ttool: PresentableAgentTool<TParams, TDetails>,\n): ToolDefinition<TParams, TDetails> {\n\treturn {\n\t\tname: tool.name,\n\t\tlabel: tool.label,\n\t\tdescription: tool.description,\n\t\tparameters: tool.parameters,\n\t\tconstrainedSampling: tool.constrainedSampling,\n\t\ttoolGroup: tool.toolGroup,\n\t\tprepareArguments: tool.prepareArguments,\n\t\texecutionMode: tool.executionMode,\n\t\texecute: async (toolCallId, params, signal, onUpdate) => tool.execute(toolCallId, params, signal, onUpdate),\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../../../src/extensions/background/actions.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,KAAK,iBAAiB,EAEtB,KAAK,cAAc,EAEnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAItE,OAAO,EAAE,KAAK,OAAO,EAA+D,MAAM,aAAa,CAAC;AAExG,OAAO,KAAK,EAAa,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAExG,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAID,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,SAAa,GAAG,MAAM,CAE/E;AAeD,wBAAsB,OAAO,CAAC,UAAU,EAAE,iBAAiB,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAmBpH;AACD,wBAAsB,OAAO,CAC5B,UAAU,EAAE,i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,UAAU,EAAE,iBAAiB,GAAG,eAAe,CAAC,aAAa,CAAC,CAmBrF"}
@@ -1,6 +1,6 @@
1
1
  /** Management only: execution and delivery belong to the session Background service. */
2
2
  import { boundText } from "../../core/background/output.js";
3
- import { isBackgroundTerminal, } from "../../core/background/types.js";
3
+ import { BackgroundLookupError, isBackgroundTerminal, } from "../../core/background/types.js";
4
4
  import { truncateHead } from "../../core/tools/truncate.js";
5
5
  import { sanitizeBinaryOutput } from "../../utils/shell.js";
6
6
  import { BG_LIST_FINISHED_SHOWN, BG_WAIT_DELTA_BYTES } from "./constants.js";
@@ -15,6 +15,55 @@ function result(text, details) {
15
15
  export function describeTaskLine(task, now = Date.now()) {
16
16
  return `${task.id} ${task.kind} ${task.status} (${task.mode}) ${runtimeLabel(task, now)} ${task.title.slice(0, 200)}`;
17
17
  }
18
+ const LOOKUP_LIST_LIMIT = 10;
19
+ /**
20
+ * Finished rows sort most-recent first. list() is creation-ordered, so an
21
+ * unsorted slice would surface the oldest completions rather than the recent
22
+ * finishes a caller is most likely looking for.
23
+ */
24
+ function recentFinishedFirst(tasks) {
25
+ return tasks.sort((left, right) => (right.endedAt ?? 0) - (left.endedAt ?? 0));
26
+ }
27
+ /**
28
+ * Listings cover backgrounded work only; foreground executions deliver inline
29
+ * in the transcript, so they are counted rather than shown. Every listing
30
+ * (bg list output and lookup-failure messages) shares this scope.
31
+ */
32
+ function listedTasks(background) {
33
+ const all = background.list();
34
+ const tasks = all.filter((task) => task.mode === "background");
35
+ return { tasks, foregroundOmitted: all.length - tasks.length };
36
+ }
37
+ function foregroundOmissionNote(omitted) {
38
+ return omitted > 0
39
+ ? `\n${omitted} foreground ${omitted === 1 ? "execution" : "executions"} omitted — foreground work is delivered inline in the transcript.`
40
+ : "";
41
+ }
42
+ /**
43
+ * Rewrite the service's bare lookup failure into an actionable one: an
44
+ * unknown id gets the session's current tasks (active first, then recent
45
+ * finishes) so the next call can use a real id without a separate list call,
46
+ * and an ambiguous prefix gets exactly the tasks it matched — including
47
+ * records outside the current branch, which listings hide but the prefix
48
+ * still collides with.
49
+ */
50
+ function lookupFailure(background, id, error) {
51
+ if (!(error instanceof BackgroundLookupError))
52
+ return error instanceof Error ? error : new Error(String(error));
53
+ if (error.kind === "ambiguous") {
54
+ const lines = error.matches.map((task) => describeTaskLine(task)).join("\n");
55
+ return new Error(`Ambiguous background task ID "${id}" matches ${error.matches.length} tasks:\n${lines}`);
56
+ }
57
+ const { tasks, foregroundOmitted } = listedTasks(background);
58
+ const active = tasks.filter((task) => !isBackgroundTerminal(task.status));
59
+ const finished = recentFinishedFirst(tasks.filter((task) => isBackgroundTerminal(task.status)));
60
+ const shown = [...active, ...finished].slice(0, LOOKUP_LIST_LIMIT);
61
+ if (shown.length === 0) {
62
+ return new Error(`No background task "${id}" in this session. No background tasks in this session.`);
63
+ }
64
+ const lines = shown.map((task) => describeTaskLine(task)).join("\n");
65
+ return new Error(`No background task "${id}" in this session. IDs from other sessions are not valid here.\nCurrent tasks:\n${lines}${foregroundOmissionNote(foregroundOmitted)}`);
66
+ }
18
67
  /** Reserve space for each independent diagnostic before allowing raw output to fill the budget. */
19
68
  function readText(header, slice) {
20
69
  const boundedField = (text, maxBytes) => truncateHead(boundText(sanitizeBinaryOutput(text), maxBytes), { maxBytes, maxLines: 100 }).content;
@@ -29,86 +78,96 @@ function readText(header, slice) {
29
78
  .join("\n");
30
79
  }
31
80
  export async function runRead(background, input) {
32
- const mode = input.mode ?? "tail";
33
- const slice = await background.read(requireTaskId(input), { mode, bytes: clampReadBytes(input.bytes) });
34
- return result(readText(`[${describeTaskLine(slice.task)} · ${slice.totalBytes} bytes${slice.truncated ? " · truncated" : ""}]`, slice), {
35
- action: "read",
36
- taskId: slice.task.id,
37
- mode,
38
- sliceBytes: Buffer.byteLength(slice.text),
39
- totalBytes: slice.totalBytes,
40
- outputPath: slice.task.outputPath ?? "",
41
- kind: slice.task.kind,
42
- status: slice.task.status,
43
- });
44
- }
45
- export async function runWait(background, input, signal) {
46
81
  const id = requireTaskId(input);
47
- const release = background.pin(id);
48
82
  try {
49
- const start = Date.now();
50
- const task = await background.wait(id, clampWaitMs(input.waitMs), signal);
51
- const timedOut = !isBackgroundTerminal(task.status);
52
- // A closed host resolves waits early without settling anything; do not claim
53
- // the execution merely outlived the wait window.
54
- const windowNote = background.closed
55
- ? " · host closed; execution state unconfirmed"
56
- : timedOut
57
- ? " · wait window expired; execution continues"
58
- : "";
59
- const slice = await background.read(id, {
60
- bytes: BG_WAIT_DELTA_BYTES,
61
- sinceBytes: clampSinceBytes(input.sinceBytes),
62
- });
63
- signal?.throwIfAborted();
64
- return result(readText(`[${describeTaskLine(task)}${windowNote}]`, slice), {
65
- action: "wait",
66
- taskId: task.id,
67
- ...(!timedOut ? { backgroundTaskId: task.id } : {}),
68
- status: task.status,
69
- kind: task.kind,
70
- timedOut,
71
- exitCode: undefined,
72
- waitedMs: Date.now() - start,
73
- deltaBytes: Buffer.byteLength(slice.text),
83
+ const mode = input.mode ?? "tail";
84
+ const slice = await background.read(id, { mode, bytes: clampReadBytes(input.bytes) });
85
+ return result(readText(`[${describeTaskLine(slice.task)} · ${slice.totalBytes} bytes${slice.truncated ? " · truncated" : ""}]`, slice), {
86
+ action: "read",
87
+ taskId: slice.task.id,
88
+ mode,
89
+ sliceBytes: Buffer.byteLength(slice.text),
74
90
  totalBytes: slice.totalBytes,
75
- deltaTruncated: slice.truncated,
76
- outputPath: task.outputPath ?? "",
91
+ outputPath: slice.task.outputPath ?? "",
92
+ kind: slice.task.kind,
93
+ status: slice.task.status,
77
94
  });
78
95
  }
79
- finally {
80
- release();
96
+ catch (error) {
97
+ throw lookupFailure(background, id, error);
98
+ }
99
+ }
100
+ export async function runWait(background, input, signal) {
101
+ const id = requireTaskId(input);
102
+ try {
103
+ const release = background.pin(id);
104
+ try {
105
+ const start = Date.now();
106
+ const task = await background.wait(id, clampWaitMs(input.waitMs), signal);
107
+ const timedOut = !isBackgroundTerminal(task.status);
108
+ // A closed host resolves waits early without settling anything; do not claim
109
+ // the execution merely outlived the wait window.
110
+ const windowNote = background.closed
111
+ ? " · host closed; execution state unconfirmed"
112
+ : timedOut
113
+ ? " · wait window expired; execution continues"
114
+ : "";
115
+ const slice = await background.read(id, {
116
+ bytes: BG_WAIT_DELTA_BYTES,
117
+ sinceBytes: clampSinceBytes(input.sinceBytes),
118
+ });
119
+ signal?.throwIfAborted();
120
+ return result(readText(`[${describeTaskLine(task)}${windowNote}]`, slice), {
121
+ action: "wait",
122
+ taskId: task.id,
123
+ ...(!timedOut ? { backgroundTaskId: task.id } : {}),
124
+ status: task.status,
125
+ kind: task.kind,
126
+ timedOut,
127
+ exitCode: undefined,
128
+ waitedMs: Date.now() - start,
129
+ deltaBytes: Buffer.byteLength(slice.text),
130
+ totalBytes: slice.totalBytes,
131
+ deltaTruncated: slice.truncated,
132
+ outputPath: task.outputPath ?? "",
133
+ });
134
+ }
135
+ finally {
136
+ release();
137
+ }
138
+ }
139
+ catch (error) {
140
+ throw lookupFailure(background, id, error);
81
141
  }
82
142
  }
83
143
  export function runKill(background, input) {
84
- const task = background.get(requireTaskId(input));
85
- const requested = background.kill(task.id);
86
- return result(requested
87
- ? `Cancellation requested for ${task.id}. The task or whole group is stopping; cleanup may still be in progress.`
88
- : `No new cancellation requested for ${task.id} (${background.get(task.id).status}).`, {
89
- action: "kill",
90
- taskId: task.id,
91
- command: task.command ?? task.title,
92
- requested,
93
- status: background.get(task.id).status,
94
- });
144
+ const id = requireTaskId(input);
145
+ try {
146
+ const task = background.get(id);
147
+ const requested = background.kill(task.id);
148
+ return result(requested
149
+ ? `Cancellation requested for ${task.id}. The task or whole group is stopping; cleanup may still be in progress.`
150
+ : `No new cancellation requested for ${task.id} (${background.get(task.id).status}).`, {
151
+ action: "kill",
152
+ taskId: task.id,
153
+ command: task.command ?? task.title,
154
+ requested,
155
+ status: background.get(task.id).status,
156
+ });
157
+ }
158
+ catch (error) {
159
+ throw lookupFailure(background, id, error);
160
+ }
95
161
  }
96
162
  export function runList(background) {
97
- // Listings cover backgrounded work only; foreground executions deliver
98
- // inline in the transcript, so they are counted here rather than shown.
99
- const all = background.list();
100
- const tasks = all.filter((task) => task.mode === "background");
101
- const foregroundOmitted = all.length - tasks.length;
163
+ const { tasks, foregroundOmitted } = listedTasks(background);
102
164
  const active = tasks.filter((task) => !isBackgroundTerminal(task.status));
103
- const finished = tasks.filter((task) => isBackgroundTerminal(task.status));
165
+ const finished = recentFinishedFirst(tasks.filter((task) => isBackgroundTerminal(task.status)));
104
166
  const shown = [...active, ...finished.slice(0, BG_LIST_FINISHED_SHOWN)].slice(0, 100);
105
167
  const hidden = tasks.length - shown.length;
106
- const foregroundNote = foregroundOmitted > 0
107
- ? `\n${foregroundOmitted} foreground ${foregroundOmitted === 1 ? "execution" : "executions"} omitted — foreground work is delivered inline in the transcript.`
108
- : "";
109
168
  return result(shown.length
110
- ? `${shown.map((task) => describeTaskLine(task)).join("\n")}${hidden > 0 ? `\n${hidden} more records not shown.` : ""}${foregroundNote}`
111
- : `No background tasks. Start work through bash or subagent with background: true.${foregroundNote}`, {
169
+ ? `${shown.map((task) => describeTaskLine(task)).join("\n")}${hidden > 0 ? `\n${hidden} more records not shown.` : ""}${foregroundOmissionNote(foregroundOmitted)}`
170
+ : `No background tasks. Start work through bash or subagent with background: true.${foregroundOmissionNote(foregroundOmitted)}`, {
112
171
  action: "list",
113
172
  running: active.length,
114
173
  finished: finished.length,
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../src/extensions/background/actions.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAIN,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,mBAA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O,EAAE,MAAM,CAAC,MAAM;QACtB,QAAQ,EAAE,QAAQ,CAAC,MAAM;QACzB,KAAK,EAAE,KAAK,CAAC,MAAM;QACnB,MAAM;QACN,GAAG,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvD,CACD,CAAC;AACH,CAAC","sourcesContent":["/** Management only: execution and delivery belong to the session Background service. */\nimport { boundText } from \"../../core/background/output.ts\";\nimport {\n\ttype BackgroundContext,\n\ttype BackgroundRead,\n\ttype BackgroundTask,\n\tisBackgroundTerminal,\n} from \"../../core/background/types.ts\";\nimport type { AgentToolResult } from \"../../core/extensions/types.ts\";\nimport { truncateHead } from \"../../core/tools/truncate.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport { BG_LIST_FINISHED_SHOWN, BG_WAIT_DELTA_BYTES } from \"./constants.ts\";\nimport { type BgInput, clampReadBytes, clampSinceBytes, clampWaitMs, requireTaskId } from \"./schema.ts\";\nimport { runtimeLabel } from \"./task-view.ts\";\nimport type { BgDetails, BgKillDetails, BgListDetails, BgReadDetails, BgWaitDetails } from \"./types.ts\";\n\nexport function boundedText(text: string): string {\n\treturn truncateHead(sanitizeBinaryOutput(text), { maxBytes: 50 * 1024, maxLines: 2000 }).content;\n}\nfunction result<T extends BgDetails>(text: string, details: T): AgentToolResult<T> {\n\treturn { content: [{ type: \"text\", text: boundedText(text) }], details };\n}\nexport function describeTaskLine(task: BackgroundTask, now = Date.now()): string {\n\treturn `${task.id} ${task.kind} ${task.status} (${task.mode}) ${runtimeLabel(task, now)} ${task.title.slice(0, 200)}`;\n}\n/** Reserve space for each independent diagnostic before allowing raw output to fill the budget. */\nfunction readText(header: string, slice: BackgroundRead): string {\n\tconst boundedField = (text: string, maxBytes: number) =>\n\t\ttruncateHead(boundText(sanitizeBinaryOutput(text), maxBytes), { maxBytes, maxLines: 100 }).content;\n\treturn [\n\t\tboundedField(header, 4096),\n\t\tslice.task.error ? `Task error: ${boundedField(slice.task.error, 4096)}` : \"\",\n\t\tslice.readError ? `Output read error: ${boundedField(slice.readError, 4096)}` : \"\",\n\t\tboundedField(slice.task.outputPath ?? \"\", 8192),\n\t\tslice.text || \"(no output yet)\",\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\"\\n\");\n}\nexport async function runRead(background: BackgroundContext, input: BgInput): Promise<AgentToolResult<BgReadDetails>> {\n\tconst mode = input.mode ?? \"tail\";\n\tconst slice = await background.read(requireTaskId(input), { mode, bytes: clampReadBytes(input.bytes) });\n\treturn result(\n\t\treadText(\n\t\t\t`[${describeTaskLine(slice.task)} · ${slice.totalBytes} bytes${slice.truncated ? \" · truncated\" : \"\"}]`,\n\t\t\tslice,\n\t\t),\n\t\t{\n\t\t\taction: \"read\",\n\t\t\ttaskId: slice.task.id,\n\t\t\tmode,\n\t\t\tsliceBytes: Buffer.byteLength(slice.text),\n\t\t\ttotalBytes: slice.totalBytes,\n\t\t\toutputPath: slice.task.outputPath ?? \"\",\n\t\t\tkind: slice.task.kind,\n\t\t\tstatus: slice.task.status,\n\t\t},\n\t);\n}\nexport async function runWait(\n\tbackground: BackgroundContext,\n\tinput: BgInput,\n\tsignal?: AbortSignal,\n): Promise<AgentToolResult<BgWaitDetails>> {\n\tconst id = requireTaskId(input);\n\tconst release = background.pin(id);\n\ttry {\n\t\tconst start = Date.now();\n\t\tconst task = await background.wait(id, clampWaitMs(input.waitMs), signal);\n\t\tconst timedOut = !isBackgroundTerminal(task.status);\n\t\t// A closed host resolves waits early without settling anything; do not claim\n\t\t// the execution merely outlived the wait window.\n\t\tconst windowNote = background.closed\n\t\t\t? \" · host closed; execution state unconfirmed\"\n\t\t\t: timedOut\n\t\t\t\t? \" · wait window expired; execution continues\"\n\t\t\t\t: \"\";\n\t\tconst slice = await background.read(id, {\n\t\t\tbytes: BG_WAIT_DELTA_BYTES,\n\t\t\tsinceBytes: clampSinceBytes(input.sinceBytes),\n\t\t});\n\t\tsignal?.throwIfAborted();\n\t\treturn result(readText(`[${describeTaskLine(task)}${windowNote}]`, slice), {\n\t\t\taction: \"wait\",\n\t\t\ttaskId: task.id,\n\t\t\t...(!timedOut ? { backgroundTaskId: task.id } : {}),\n\t\t\tstatus: task.status,\n\t\t\tkind: task.kind,\n\t\t\ttimedOut,\n\t\t\texitCode: undefined,\n\t\t\twaitedMs: Date.now() - start,\n\t\t\tdeltaBytes: Buffer.byteLength(slice.text),\n\t\t\ttotalBytes: slice.totalBytes,\n\t\t\tdeltaTruncated: slice.truncated,\n\t\t\toutputPath: task.outputPath ?? \"\",\n\t\t});\n\t} finally {\n\t\trelease();\n\t}\n}\nexport function runKill(background: BackgroundContext, input: BgInput): AgentToolResult<BgKillDetails> {\n\tconst task = background.get(requireTaskId(input));\n\tconst requested = background.kill(task.id);\n\treturn result(\n\t\trequested\n\t\t\t? `Cancellation requested for ${task.id}. The task or whole group is stopping; cleanup may still be in progress.`\n\t\t\t: `No new cancellation requested for ${task.id} (${background.get(task.id).status}).`,\n\t\t{\n\t\t\taction: \"kill\",\n\t\t\ttaskId: task.id,\n\t\t\tcommand: task.command ?? task.title,\n\t\t\trequested,\n\t\t\tstatus: background.get(task.id).status,\n\t\t},\n\t);\n}\nexport function runList(background: BackgroundContext): AgentToolResult<BgListDetails> {\n\t// Listings cover backgrounded work only; foreground executions deliver\n\t// inline in the transcript, so they are counted here rather than shown.\n\tconst all = background.list();\n\tconst tasks = all.filter((task) => task.mode === \"background\");\n\tconst foregroundOmitted = all.length - tasks.length;\n\tconst active = tasks.filter((task) => !isBackgroundTerminal(task.status));\n\tconst finished = tasks.filter((task) => isBackgroundTerminal(task.status));\n\tconst shown = [...active, ...finished.slice(0, BG_LIST_FINISHED_SHOWN)].slice(0, 100);\n\tconst hidden = tasks.length - shown.length;\n\tconst foregroundNote =\n\t\tforegroundOmitted > 0\n\t\t\t? `\\n${foregroundOmitted} foreground ${foregroundOmitted === 1 ? \"execution\" : \"executions\"} omitted — foreground work is delivered inline in the transcript.`\n\t\t\t: \"\";\n\treturn result(\n\t\tshown.length\n\t\t\t? `${shown.map((task) => describeTaskLine(task)).join(\"\\n\")}${hidden > 0 ? `\\n${hidden} more records not shown.` : \"\"}${foregroundNote}`\n\t\t\t: `No background tasks. Start work through bash or subagent with background: true.${foregroundNote}`,\n\t\t{\n\t\t\taction: \"list\",\n\t\t\trunning: active.length,\n\t\t\tfinished: finished.length,\n\t\t\tshown: shown.length,\n\t\t\thidden,\n\t\t\t...(foregroundOmitted > 0 ? { foregroundOmitted } : {}),\n\t\t},\n\t);\n}\n"]}
1
+ {"version":3,"file":"actions.js","sourceRoot":"","sources":["../../../src/extensions/background/actions.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAEN,qBAAqB,EAGrB,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAgB,cAAc,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,MAAM,UAAU,WAAW,CAAC,IAAY;IACvC,OAAO,YAAY,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC;AAClG,CAAC;AACD,SAAS,MAAM,CAAsB,IAAY,EAAE,OAAU;IAC5D,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,C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AAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAChG,MAAM,KAAK,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,sBAAsB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACtF,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC3C,OAAO,MAAM,CACZ,KAAK,CAAC,MAAM;QACX,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,MAAM,0BAA0B,CAAC,CAAC,CAAC,EAAE,GAAG,sBAAsB,CAAC,iBAAiB,CAAC,EAAE;QACnK,CAAC,CAAC,kFAAkF,sBAAsB,CAAC,iBAAiB,CAAC,EAAE,EAChI;QACC,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,MAAM,CAAC,MAAM;QACtB,QAAQ,EAAE,QAAQ,CAAC,MAAM;QACzB,KAAK,EAAE,KAAK,CAAC,MAAM;QACnB,MAAM;QACN,GAAG,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvD,CACD,CAAC;AACH,CAAC","sourcesContent":["/** Management only: execution and delivery belong to the session Background service. */\nimport { boundText } from \"../../core/background/output.ts\";\nimport {\n\ttype BackgroundContext,\n\tBackgroundLookupError,\n\ttype BackgroundRead,\n\ttype BackgroundTask,\n\tisBackgroundTerminal,\n} from \"../../core/background/types.ts\";\nimport type { AgentToolResult } from \"../../core/extensions/types.ts\";\nimport { truncateHead } from \"../../core/tools/truncate.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport { BG_LIST_FINISHED_SHOWN, BG_WAIT_DELTA_BYTES } from \"./constants.ts\";\nimport { type BgInput, clampReadBytes, clampSinceBytes, clampWaitMs, requireTaskId } from \"./schema.ts\";\nimport { runtimeLabel } from \"./task-view.ts\";\nimport type { BgDetails, BgKillDetails, BgListDetails, BgReadDetails, BgWaitDetails } from \"./types.ts\";\n\nexport function boundedText(text: string): string {\n\treturn truncateHead(sanitizeBinaryOutput(text), { maxBytes: 50 * 1024, maxLines: 2000 }).content;\n}\nfunction result<T extends BgDetails>(text: string, details: T): AgentToolResult<T> {\n\treturn { content: [{ type: \"text\", text: boundedText(text) }], details };\n}\nexport function describeTaskLine(task: BackgroundTask, now = Date.now()): string {\n\treturn `${task.id} ${task.kind} ${task.status} (${task.mode}) ${runtimeLabel(task, now)} ${task.title.slice(0, 200)}`;\n}\n\nconst LOOKUP_LIST_LIMIT = 10;\n\n/**\n * Finished rows sort most-recent first. list() is creation-ordered, so an\n * unsorted slice would surface the oldest completions rather than the recent\n * finishes a caller is most likely looking for.\n */\nfunction recentFinishedFirst(tasks: BackgroundTask[]): BackgroundTask[] {\n\treturn tasks.sort((left, right) => (right.endedAt ?? 0) - (left.endedAt ?? 0));\n}\n\n/**\n * Listings cover backgrounded work only; foreground executions deliver inline\n * in the transcript, so they are counted rather than shown. Every listing\n * (bg list output and lookup-failure messages) shares this scope.\n */\nfunction listedTasks(background: BackgroundContext): { tasks: BackgroundTask[]; foregroundOmitted: number } {\n\tconst all = background.list();\n\tconst tasks = all.filter((task) => task.mode === \"background\");\n\treturn { tasks, foregroundOmitted: all.length - tasks.length };\n}\n\nfunction foregroundOmissionNote(omitted: number): string {\n\treturn omitted > 0\n\t\t? `\\n${omitted} foreground ${omitted === 1 ? \"execution\" : \"executions\"} omitted — foreground work is delivered inline in the transcript.`\n\t\t: \"\";\n}\n\n/**\n * Rewrite the service's bare lookup failure into an actionable one: an\n * unknown id gets the session's current tasks (active first, then recent\n * finishes) so the next call can use a real id without a separate list call,\n * and an ambiguous prefix gets exactly the tasks it matched — including\n * records outside the current branch, which listings hide but the prefix\n * still collides with.\n */\nfunction lookupFailure(background: BackgroundContext, id: string, error: unknown): Error {\n\tif (!(error instanceof BackgroundLookupError)) return error instanceof Error ? error : new Error(String(error));\n\tif (error.kind === \"ambiguous\") {\n\t\tconst lines = error.matches.map((task) => describeTaskLine(task)).join(\"\\n\");\n\t\treturn new Error(`Ambiguous background task ID \"${id}\" matches ${error.matches.length} tasks:\\n${lines}`);\n\t}\n\tconst { tasks, foregroundOmitted } = listedTasks(background);\n\tconst active = tasks.filter((task) => !isBackgroundTerminal(task.status));\n\tconst finished = recentFinishedFirst(tasks.filter((task) => isBackgroundTerminal(task.status)));\n\tconst shown = [...active, ...finished].slice(0, LOOKUP_LIST_LIMIT);\n\tif (shown.length === 0) {\n\t\treturn new Error(`No background task \"${id}\" in this session. No background tasks in this session.`);\n\t}\n\tconst lines = shown.map((task) => describeTaskLine(task)).join(\"\\n\");\n\treturn new Error(\n\t\t`No background task \"${id}\" in this session. IDs from other sessions are not valid here.\\nCurrent tasks:\\n${lines}${foregroundOmissionNote(foregroundOmitted)}`,\n\t);\n}\n/** Reserve space for each independent diagnostic before allowing raw output to fill the budget. */\nfunction readText(header: string, slice: BackgroundRead): string {\n\tconst boundedField = (text: string, maxBytes: number) =>\n\t\ttruncateHead(boundText(sanitizeBinaryOutput(text), maxBytes), { maxBytes, maxLines: 100 }).content;\n\treturn [\n\t\tboundedField(header, 4096),\n\t\tslice.task.error ? `Task error: ${boundedField(slice.task.error, 4096)}` : \"\",\n\t\tslice.readError ? `Output read error: ${boundedField(slice.readError, 4096)}` : \"\",\n\t\tboundedField(slice.task.outputPath ?? \"\", 8192),\n\t\tslice.text || \"(no output yet)\",\n\t]\n\t\t.filter(Boolean)\n\t\t.join(\"\\n\");\n}\nexport async function runRead(background: BackgroundContext, input: BgInput): Promise<AgentToolResult<BgReadDetails>> {\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst mode = input.mode ?? \"tail\";\n\t\tconst slice = await background.read(id, { mode, bytes: clampReadBytes(input.bytes) });\n\t\treturn result(\n\t\t\treadText(\n\t\t\t\t`[${describeTaskLine(slice.task)} · ${slice.totalBytes} bytes${slice.truncated ? \" · truncated\" : \"\"}]`,\n\t\t\t\tslice,\n\t\t\t),\n\t\t\t{\n\t\t\t\taction: \"read\",\n\t\t\t\ttaskId: slice.task.id,\n\t\t\t\tmode,\n\t\t\t\tsliceBytes: Buffer.byteLength(slice.text),\n\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\toutputPath: slice.task.outputPath ?? \"\",\n\t\t\t\tkind: slice.task.kind,\n\t\t\t\tstatus: slice.task.status,\n\t\t\t},\n\t\t);\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nexport async function runWait(\n\tbackground: BackgroundContext,\n\tinput: BgInput,\n\tsignal?: AbortSignal,\n): Promise<AgentToolResult<BgWaitDetails>> {\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst release = background.pin(id);\n\t\ttry {\n\t\t\tconst start = Date.now();\n\t\t\tconst task = await background.wait(id, clampWaitMs(input.waitMs), signal);\n\t\t\tconst timedOut = !isBackgroundTerminal(task.status);\n\t\t\t// A closed host resolves waits early without settling anything; do not claim\n\t\t\t// the execution merely outlived the wait window.\n\t\t\tconst windowNote = background.closed\n\t\t\t\t? \" · host closed; execution state unconfirmed\"\n\t\t\t\t: timedOut\n\t\t\t\t\t? \" · wait window expired; execution continues\"\n\t\t\t\t\t: \"\";\n\t\t\tconst slice = await background.read(id, {\n\t\t\t\tbytes: BG_WAIT_DELTA_BYTES,\n\t\t\t\tsinceBytes: clampSinceBytes(input.sinceBytes),\n\t\t\t});\n\t\t\tsignal?.throwIfAborted();\n\t\t\treturn result(readText(`[${describeTaskLine(task)}${windowNote}]`, slice), {\n\t\t\t\taction: \"wait\",\n\t\t\t\ttaskId: task.id,\n\t\t\t\t...(!timedOut ? { backgroundTaskId: task.id } : {}),\n\t\t\t\tstatus: task.status,\n\t\t\t\tkind: task.kind,\n\t\t\t\ttimedOut,\n\t\t\t\texitCode: undefined,\n\t\t\t\twaitedMs: Date.now() - start,\n\t\t\t\tdeltaBytes: Buffer.byteLength(slice.text),\n\t\t\t\ttotalBytes: slice.totalBytes,\n\t\t\t\tdeltaTruncated: slice.truncated,\n\t\t\t\toutputPath: task.outputPath ?? \"\",\n\t\t\t});\n\t\t} finally {\n\t\t\trelease();\n\t\t}\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nexport function runKill(background: BackgroundContext, input: BgInput): AgentToolResult<BgKillDetails> {\n\tconst id = requireTaskId(input);\n\ttry {\n\t\tconst task = background.get(id);\n\t\tconst requested = background.kill(task.id);\n\t\treturn result(\n\t\t\trequested\n\t\t\t\t? `Cancellation requested for ${task.id}. The task or whole group is stopping; cleanup may still be in progress.`\n\t\t\t\t: `No new cancellation requested for ${task.id} (${background.get(task.id).status}).`,\n\t\t\t{\n\t\t\t\taction: \"kill\",\n\t\t\t\ttaskId: task.id,\n\t\t\t\tcommand: task.command ?? task.title,\n\t\t\t\trequested,\n\t\t\t\tstatus: background.get(task.id).status,\n\t\t\t},\n\t\t);\n\t} catch (error) {\n\t\tthrow lookupFailure(background, id, error);\n\t}\n}\nexport function runList(background: BackgroundContext): AgentToolResult<BgListDetails> {\n\tconst { tasks, foregroundOmitted } = listedTasks(background);\n\tconst active = tasks.filter((task) => !isBackgroundTerminal(task.status));\n\tconst finished = recentFinishedFirst(tasks.filter((task) => isBackgroundTerminal(task.status)));\n\tconst shown = [...active, ...finished.slice(0, BG_LIST_FINISHED_SHOWN)].slice(0, 100);\n\tconst hidden = tasks.length - shown.length;\n\treturn result(\n\t\tshown.length\n\t\t\t? `${shown.map((task) => describeTaskLine(task)).join(\"\\n\")}${hidden > 0 ? `\\n${hidden} more records not shown.` : \"\"}${foregroundOmissionNote(foregroundOmitted)}`\n\t\t\t: `No background tasks. Start work through bash or subagent with background: true.${foregroundOmissionNote(foregroundOmitted)}`,\n\t\t{\n\t\t\taction: \"list\",\n\t\t\trunning: active.length,\n\t\t\tfinished: finished.length,\n\t\t\tshown: shown.length,\n\t\t\thidden,\n\t\t\t...(foregroundOmitted > 0 ? { foregroundOmitted } : {}),\n\t\t},\n\t);\n}\n"]}
@@ -53,6 +53,7 @@ export function createBackgroundExtension() {
53
53
  promptSnippet: BG_PROMPT_SNIPPET,
54
54
  promptGuidelines: BG_PROMPT_GUIDELINES,
55
55
  parameters: bgSchema,
56
+ constrainedSampling: { type: "json_schema", strict: "prefer" },
56
57
  async execute(_id, params, signal, _onUpdate, ctx) {
57
58
  try {
58
59
  switch (params.action) {
@@ -67,10 +68,9 @@ export function createBackgroundExtension() {
67
68
  }
68
69
  }
69
70
  catch (error) {
71
+ // Lookup failures already carry the current task list from actions.ts.
70
72
  const message = error instanceof Error ? error.message : String(error);
71
- // Unknown/ambiguous ids recover through the same step as a missing id.
72
- const hint = message.includes("background task ID") ? " Use action list to find the execution id." : "";
73
- throw new Error(boundedText(`${message}${hint}`));
73
+ throw new Error(boundedText(message));
74
74
  }
75
75
  },
76
76
  renderCall: renderBgCall,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/background/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAEtE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AA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CAAC,UAAU;yBACZ,IAAI,EAAE;yBACN,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC;yBAC5C,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;yBACZ,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC;yBACrC,IAAI,CAAC,IAAI,CAAC,CACZ,IAAI,sBAAsB,EAC3B,MAAM,CACN,CAAC;oBACF,OAAO;gBACR,CAAC;gBACD,SAAS,EAAE,EAAE,CAAC;gBACd,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAClB,CAAC,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE;oBACjC,MAAM,KAAK,GAAG,GAAG,EAAE;wBAClB,IAAI,SAAS,KAAK,KAAK;4BAAE,SAAS,GAAG,SAAS,CAAC;wBAC/C,IAAI,EAAE,CAAC;oBACR,CAAC,CAAC;oBACF,SAAS,GAAG,KAAK,CAAC;oBAClB,OAAO,IAAI,mBAAmB,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;gBACnG,CAAC,EACD,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,CACzF,CAAC;YACH,CAAC;SACD,CAAC,CAAC;IACJ,CAAC,CAAC;AACH,CAAC;AACD,eAAe,yBAAyB,EAAE,CAAC","sourcesContent":["/** bg is an observer/controller of the public session-owned Background capability. */\nimport \"./keybindings.ts\";\nimport { getKeybindings } from \"@earendil-works/pi-tui\";\nimport { isBackgroundTerminal } from \"../../core/background/types.ts\";\nimport type { ExtensionAPI } from \"../../core/extensions/types.ts\";\nimport { boundedText, describeTaskLine, runKill, runList, runRead, runWait } from \"./actions.ts\";\nimport { renderBackgroundCompletion } from \"./completion-render.ts\";\nimport { BG_COMPLETION_TYPE, BG_NOTIFICATION_TYPE } from \"./constants.ts\";\nimport { BackgroundTasksMenu } from \"./manager.ts\";\nimport { type BgRenderState, renderBackgroundNotification, renderBgCall, renderBgResult } from \"./render.ts\";\nimport { BG_PROMPT_GUIDELINES, BG_PROMPT_SNIPPET, BG_TOOL_DESCRIPTION, bgSchema } from \"./schema.ts\";\nimport type { BgDetails, BgNotificationDetails } from \"./types.ts\";\n\nexport function createBackgroundExtension(): (pi: ExtensionAPI) => void {\n\treturn (pi) => {\n\t\tlet unsubscribe: (() => void) | undefined;\n\t\tlet unsubscribeDetachKey: (() => void) | undefined;\n\t\tlet closeMenu: (() => void) | undefined;\n\t\tpi.on(\"session_start\", (_event, ctx) => {\n\t\t\tunsubscribe?.();\n\t\t\tunsubscribeDetachKey?.();\n\t\t\tconst update = () => {\n\t\t\t\t// The status counts backgrounded work only; foreground executions\n\t\t\t\t// are already visible as ordinary tool rows in the transcript.\n\t\t\t\tconst tasks = ctx.background.list().filter((task) => task.mode === \"background\");\n\t\t\t\tconst running = tasks.filter((task) => !isBackgroundTerminal(task.status)).length;\n\t\t\t\tctx.ui.setStatus(\n\t\t\t\t\t\"background\",\n\t\t\t\t\ttasks.length ? `bg ${running} active · ${tasks.length - running} finished` : undefined,\n\t\t\t\t);\n\t\t\t};\n\t\t\tunsubscribe = ctx.background.subscribe(update);\n\t\t\tunsubscribeDetachKey = ctx.ui.onTerminalInput((data) => {\n\t\t\t\tif (!getKeybindings().matches(data, \"app.backgroundTasks.detach\")) return undefined;\n\t\t\t\tconst count = ctx.background.detachForeground();\n\t\t\t\t// Nothing can move: let the key fall through to editor bindings instead of\n\t\t\t\t// spending it on a \"nothing happened\" status line.\n\t\t\t\tif (count === 0) return undefined;\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`Moved ${count} execution${count === 1 ? \"\" : \"s\"} to the background. Use /bg to manage tasks.`,\n\t\t\t\t);\n\t\t\t\treturn { consume: true };\n\t\t\t});\n\t\t\tupdate();\n\t\t});\n\t\tpi.on(\"session_shutdown\", (_event, ctx) => {\n\t\t\tunsubscribe?.();\n\t\t\tunsubscribe = undefined;\n\t\t\tunsubscribeDetachKey?.();\n\t\t\tunsubscribeDetachKey = undefined;\n\t\t\tcloseMenu?.();\n\t\t\tcloseMenu = undefined;\n\t\t\tctx.ui.setStatus(\"background\", undefined);\n\t\t});\n\t\tpi.registerTool<typeof bgSchema, BgDetails, BgRenderState>({\n\t\t\tname: \"bg\",\n\t\t\tlabel: \"bg\",\n\t\t\tdescription: BG_TOOL_DESCRIPTION,\n\t\t\tpromptSnippet: BG_PROMPT_SNIPPET,\n\t\t\tpromptGuidelines: BG_PROMPT_GUIDELINES,\n\t\t\tparameters: bgSchema,\n\t\t\tasync execute(_id, params, signal, _onUpdate, ctx) {\n\t\t\t\ttry {\n\t\t\t\t\tswitch (params.action) {\n\t\t\t\t\t\tcase \"read\":\n\t\t\t\t\t\t\treturn await runRead(ctx.background, params);\n\t\t\t\t\t\tcase \"wait\":\n\t\t\t\t\t\t\treturn await runWait(ctx.background, params, signal);\n\t\t\t\t\t\tcase \"kill\":\n\t\t\t\t\t\t\treturn runKill(ctx.background, params);\n\t\t\t\t\t\tcase \"list\":\n\t\t\t\t\t\t\treturn runList(ctx.background);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\t\t// Unknown/ambiguous ids recover through the same step as a missing id.\n\t\t\t\t\tconst hint = message.includes(\"background task ID\") ? \" Use action list to find the execution id.\" : \"\";\n\t\t\t\t\tthrow new Error(boundedText(`${message}${hint}`));\n\t\t\t\t}\n\t\t\t},\n\t\t\trenderCall: renderBgCall,\n\t\t\trenderResult: renderBgResult,\n\t\t});\n\t\t// Stored legacy create results and notification details remain renderable.\n\t\tpi.registerMessageRenderer<BgNotificationDetails>(BG_NOTIFICATION_TYPE, renderBackgroundNotification);\n\t\tpi.registerMessageRenderer(BG_COMPLETION_TYPE, renderBackgroundCompletion);\n\t\tpi.registerCommand(\"bg\", {\n\t\t\tdescription: \"View and manage Bash tasks and Subagent groups\",\n\t\t\thandler: async (_args, ctx) => {\n\t\t\t\tif (ctx.mode !== \"tui\") {\n\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\tboundedText(\n\t\t\t\t\t\t\tctx.background\n\t\t\t\t\t\t\t\t.list()\n\t\t\t\t\t\t\t\t.filter((task) => task.mode === \"background\")\n\t\t\t\t\t\t\t\t.slice(0, 10)\n\t\t\t\t\t\t\t\t.map((task) => describeTaskLine(task))\n\t\t\t\t\t\t\t\t.join(\"\\n\"),\n\t\t\t\t\t\t) || \"No background tasks.\",\n\t\t\t\t\t\t\"info\",\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcloseMenu?.();\n\t\t\t\tawait ctx.ui.custom<void>(\n\t\t\t\t\t(tui, theme, keybindings, done) => {\n\t\t\t\t\t\tconst close = () => {\n\t\t\t\t\t\t\tif (closeMenu === close) closeMenu = undefined;\n\t\t\t\t\t\t\tdone();\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcloseMenu = close;\n\t\t\t\t\t\treturn new BackgroundTasksMenu({ tui, theme, keybindings, host: ctx.background, onClose: close });\n\t\t\t\t\t},\n\t\t\t\t\t{ overlay: true, overlayOptions: { anchor: \"center\", width: \"100%\", maxHeight: \"100%\" } },\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t};\n}\nexport default createBackgroundExtension();\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/background/index.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAEtE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the public session-owned Background capability. */\nimport \"./keybindings.ts\";\nimport { getKeybindings } from \"@earendil-works/pi-tui\";\nimport { isBackgroundTerminal } from \"../../core/background/types.ts\";\nimport type { ExtensionAPI } from \"../../core/extensions/types.ts\";\nimport { boundedText, describeTaskLine, runKill, runList, runRead, runWait } from \"./actions.ts\";\nimport { renderBackgroundCompletion } from \"./completion-render.ts\";\nimport { BG_COMPLETION_TYPE, BG_NOTIFICATION_TYPE } from \"./constants.ts\";\nimport { BackgroundTasksMenu } from \"./manager.ts\";\nimport { type BgRenderState, renderBackgroundNotification, renderBgCall, renderBgResult } from \"./render.ts\";\nimport { BG_PROMPT_GUIDELINES, BG_PROMPT_SNIPPET, BG_TOOL_DESCRIPTION, bgSchema } from \"./schema.ts\";\nimport type { BgDetails, BgNotificationDetails } from \"./types.ts\";\n\nexport function createBackgroundExtension(): (pi: ExtensionAPI) => void {\n\treturn (pi) => {\n\t\tlet unsubscribe: (() => void) | undefined;\n\t\tlet unsubscribeDetachKey: (() => void) | undefined;\n\t\tlet closeMenu: (() => void) | undefined;\n\t\tpi.on(\"session_start\", (_event, ctx) => {\n\t\t\tunsubscribe?.();\n\t\t\tunsubscribeDetachKey?.();\n\t\t\tconst update = () => {\n\t\t\t\t// The status counts backgrounded work only; foreground executions\n\t\t\t\t// are already visible as ordinary tool rows in the transcript.\n\t\t\t\tconst tasks = ctx.background.list().filter((task) => task.mode === \"background\");\n\t\t\t\tconst running = tasks.filter((task) => !isBackgroundTerminal(task.status)).length;\n\t\t\t\tctx.ui.setStatus(\n\t\t\t\t\t\"background\",\n\t\t\t\t\ttasks.length ? `bg ${running} active · ${tasks.length - running} finished` : undefined,\n\t\t\t\t);\n\t\t\t};\n\t\t\tunsubscribe = ctx.background.subscribe(update);\n\t\t\tunsubscribeDetachKey = ctx.ui.onTerminalInput((data) => {\n\t\t\t\tif (!getKeybindings().matches(data, \"app.backgroundTasks.detach\")) return undefined;\n\t\t\t\tconst count = ctx.background.detachForeground();\n\t\t\t\t// Nothing can move: let the key fall through to editor bindings instead of\n\t\t\t\t// spending it on a \"nothing happened\" status line.\n\t\t\t\tif (count === 0) return undefined;\n\t\t\t\tctx.ui.notify(\n\t\t\t\t\t`Moved ${count} execution${count === 1 ? \"\" : \"s\"} to the background. Use /bg to manage tasks.`,\n\t\t\t\t);\n\t\t\t\treturn { consume: true };\n\t\t\t});\n\t\t\tupdate();\n\t\t});\n\t\tpi.on(\"session_shutdown\", (_event, ctx) => {\n\t\t\tunsubscribe?.();\n\t\t\tunsubscribe = undefined;\n\t\t\tunsubscribeDetachKey?.();\n\t\t\tunsubscribeDetachKey = undefined;\n\t\t\tcloseMenu?.();\n\t\t\tcloseMenu = undefined;\n\t\t\tctx.ui.setStatus(\"background\", undefined);\n\t\t});\n\t\tpi.registerTool<typeof bgSchema, BgDetails, BgRenderState>({\n\t\t\tname: \"bg\",\n\t\t\tlabel: \"bg\",\n\t\t\tdescription: BG_TOOL_DESCRIPTION,\n\t\t\tpromptSnippet: BG_PROMPT_SNIPPET,\n\t\t\tpromptGuidelines: BG_PROMPT_GUIDELINES,\n\t\t\tparameters: bgSchema,\n\t\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\t\tasync execute(_id, params, signal, _onUpdate, ctx) {\n\t\t\t\ttry {\n\t\t\t\t\tswitch (params.action) {\n\t\t\t\t\t\tcase \"read\":\n\t\t\t\t\t\t\treturn await runRead(ctx.background, params);\n\t\t\t\t\t\tcase \"wait\":\n\t\t\t\t\t\t\treturn await runWait(ctx.background, params, signal);\n\t\t\t\t\t\tcase \"kill\":\n\t\t\t\t\t\t\treturn runKill(ctx.background, params);\n\t\t\t\t\t\tcase \"list\":\n\t\t\t\t\t\t\treturn runList(ctx.background);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// Lookup failures already carry the current task list from actions.ts.\n\t\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\t\tthrow new Error(boundedText(message));\n\t\t\t\t}\n\t\t\t},\n\t\t\trenderCall: renderBgCall,\n\t\t\trenderResult: renderBgResult,\n\t\t});\n\t\t// Stored legacy create results and notification details remain renderable.\n\t\tpi.registerMessageRenderer<BgNotificationDetails>(BG_NOTIFICATION_TYPE, renderBackgroundNotification);\n\t\tpi.registerMessageRenderer(BG_COMPLETION_TYPE, renderBackgroundCompletion);\n\t\tpi.registerCommand(\"bg\", {\n\t\t\tdescription: \"View and manage Bash tasks and Subagent groups\",\n\t\t\thandler: async (_args, ctx) => {\n\t\t\t\tif (ctx.mode !== \"tui\") {\n\t\t\t\t\tctx.ui.notify(\n\t\t\t\t\t\tboundedText(\n\t\t\t\t\t\t\tctx.background\n\t\t\t\t\t\t\t\t.list()\n\t\t\t\t\t\t\t\t.filter((task) => task.mode === \"background\")\n\t\t\t\t\t\t\t\t.slice(0, 10)\n\t\t\t\t\t\t\t\t.map((task) => describeTaskLine(task))\n\t\t\t\t\t\t\t\t.join(\"\\n\"),\n\t\t\t\t\t\t) || \"No background tasks.\",\n\t\t\t\t\t\t\"info\",\n\t\t\t\t\t);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tcloseMenu?.();\n\t\t\t\tawait ctx.ui.custom<void>(\n\t\t\t\t\t(tui, theme, keybindings, done) => {\n\t\t\t\t\t\tconst close = () => {\n\t\t\t\t\t\t\tif (closeMenu === close) closeMenu = undefined;\n\t\t\t\t\t\t\tdone();\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcloseMenu = close;\n\t\t\t\t\t\treturn new BackgroundTasksMenu({ tui, theme, keybindings, host: ctx.background, onClose: close });\n\t\t\t\t\t},\n\t\t\t\t\t{ overlay: true, overlayOptions: { anchor: \"center\", width: \"100%\", maxHeight: \"100%\" } },\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t};\n}\nexport default createBackgroundExtension();\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/question/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAcnE,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAmCvD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/extensions/question/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAcnE,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAAE,EAAE,YAAY,GAAG,IAAI,CAqCvD"}
@@ -2,7 +2,7 @@ import { QUESTION_DESCRIPTION, QUESTION_LABEL, QUESTION_PROMPT_GUIDELINES, QUEST
2
2
  import { createQuestionDialog } from "./dialog.js";
3
3
  import { renderQuestionCall, renderQuestionResult } from "./render.js";
4
4
  import { cancelResult, clarificationResult, errorResult, successResult } from "./results.js";
5
- import { QuestionParams, validateQuestions } from "./schema.js";
5
+ import { normalizeQuestionArguments, QuestionParams, validateQuestions } from "./schema.js";
6
6
  export default function question(pi) {
7
7
  pi.registerTool({
8
8
  name: QUESTION_TOOL_NAME,
@@ -11,6 +11,8 @@ export default function question(pi) {
11
11
  promptSnippet: QUESTION_PROMPT_SNIPPET,
12
12
  promptGuidelines: QUESTION_PROMPT_GUIDELINES,
13
13
  parameters: QuestionParams,
14
+ constrainedSampling: { type: "json_schema", strict: "prefer" },
15
+ prepareArguments: normalizeQuestionArguments,
14
16
  executionMode: "sequential",
15
17
  renderCall(args, theme, context) {
16
18
  return renderQuestionCall(args, theme, context.expanded);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/question/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACN,oBAAoB,EACpB,cAAc,EACd,0BAA0B,EAC1B,uBAAuB,EACvB,kBAAkB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,a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,CAAC;YAE7E,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAe,oBAAoB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;YAC1F,IAAI,MAAM,CAAC,OAAO,KAAK,WAAW;gBAAE,OAAO,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACxE,IAAI,MAAM,CAAC,OAAO,KAAK,qBAAqB;gBAAE,OAAO,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACzF,OAAO,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;KACD,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QACpC,IAAI,KAAK,CAAC,QAAQ,KAAK,kBAAkB;YAAE,OAAO;QAClD,MAAM,OAAO,GAAG,KAAK,CAAC,OAA0C,CAAC;QACjE,IAAI,OAAO,EAAE,OAAO,KAAK,OAAO;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC5D,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * question — ask the user structured questions during execution.\n *\n * This is a Pi-native AskUserQuestion-style tool. It keeps the UI lightweight\n * while returning a structured result envelope the model can reliably consume.\n */\nimport type { ExtensionAPI } from \"../../core/extensions/types.ts\";\nimport {\n\tQUESTION_DESCRIPTION,\n\tQUESTION_LABEL,\n\tQUESTION_PROMPT_GUIDELINES,\n\tQUESTION_PROMPT_SNIPPET,\n\tQUESTION_TOOL_NAME,\n} from \"./constants.ts\";\nimport { createQuestionDialog } from \"./dialog.ts\";\nimport { renderQuestionCall, renderQuestionResult } from \"./render.ts\";\nimport { cancelResult, clarificationResult, errorResult, successResult } from \"./results.ts\";\nimport { QuestionParams, validateQuestions } from \"./schema.ts\";\nimport type { DialogResult, Question, QuestionToolDetails } from \"./types.ts\";\n\nexport default function question(pi: ExtensionAPI): void {\n\tpi.registerTool<typeof QuestionParams, QuestionToolDetails>({\n\t\tname: QUESTION_TOOL_NAME,\n\t\tlabel: QUESTION_LABEL,\n\t\tdescription: QUESTION_DESCRIPTION,\n\t\tpromptSnippet: QUESTION_PROMPT_SNIPPET,\n\t\tpromptGuidelines: QUESTION_PROMPT_GUIDELINES,\n\t\tparameters: QuestionParams,\n\t\texecutionMode: \"sequential\",\n\t\trenderCall(args, theme, context) {\n\t\t\treturn renderQuestionCall(args, theme, context.expanded);\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\treturn renderQuestionResult(result, options, theme, context.args);\n\t\t},\n\n\t\tasync execute(_toolCallId, params, signal, _onUpdate, ctx) {\n\t\t\tconst questions = params.questions as Question[];\n\t\t\tif (!ctx.hasUI || ctx.mode !== \"tui\") return errorResult(\"no_ui\", \"question tool requires an interactive TUI\");\n\n\t\t\tconst validation = validateQuestions(questions);\n\t\t\tif (!validation.ok) return errorResult(validation.error, validation.message);\n\n\t\t\tconst result = await ctx.ui.custom<DialogResult>(createQuestionDialog(questions, signal));\n\t\t\tif (result.outcome === \"cancelled\") return cancelResult(result.answers);\n\t\t\tif (result.outcome === \"needs_clarification\") return clarificationResult(result.answers);\n\t\t\treturn successResult(result.answers);\n\t\t},\n\t});\n\n\tpi.on(\"tool_result\", async (event) => {\n\t\tif (event.toolName !== QUESTION_TOOL_NAME) return;\n\t\tconst details = event.details as QuestionToolDetails | undefined;\n\t\tif (details?.outcome === \"error\") return { isError: true };\n\t});\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/extensions/question/index.ts"],"names":[],"mappings":"AAOA,OAAO,EACN,oBAAoB,EACpB,cAAc,EACd,0BAA0B,EAC1B,uBAAuB,EACvB,kBAAkB,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACv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,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;YAE7E,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,MAAM,CAAe,oBAAoB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;YAC1F,IAAI,MAAM,CAAC,OAAO,KAAK,WAAW;gBAAE,OAAO,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACxE,IAAI,MAAM,CAAC,OAAO,KAAK,qBAAqB;gBAAE,OAAO,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACzF,OAAO,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACtC,CAAC;KACD,CAAC,CAAC;IAEH,EAAE,CAAC,EAAE,CAAC,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QACpC,IAAI,KAAK,CAAC,QAAQ,KAAK,kBAAkB;YAAE,OAAO;QAClD,MAAM,OAAO,GAAG,KAAK,CAAC,OAA0C,CAAC;QACjE,IAAI,OAAO,EAAE,OAAO,KAAK,OAAO;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC5D,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * question — ask the user structured questions during execution.\n *\n * This is a Pi-native AskUserQuestion-style tool. It keeps the UI lightweight\n * while returning a structured result envelope the model can reliably consume.\n */\nimport type { ExtensionAPI } from \"../../core/extensions/types.ts\";\nimport {\n\tQUESTION_DESCRIPTION,\n\tQUESTION_LABEL,\n\tQUESTION_PROMPT_GUIDELINES,\n\tQUESTION_PROMPT_SNIPPET,\n\tQUESTION_TOOL_NAME,\n} from \"./constants.ts\";\nimport { createQuestionDialog } from \"./dialog.ts\";\nimport { renderQuestionCall, renderQuestionResult } from \"./render.ts\";\nimport { cancelResult, clarificationResult, errorResult, successResult } from \"./results.ts\";\nimport { normalizeQuestionArguments, QuestionParams, validateQuestions } from \"./schema.ts\";\nimport type { DialogResult, Question, QuestionToolDetails } from \"./types.ts\";\n\nexport default function question(pi: ExtensionAPI): void {\n\tpi.registerTool<typeof QuestionParams, QuestionToolDetails>({\n\t\tname: QUESTION_TOOL_NAME,\n\t\tlabel: QUESTION_LABEL,\n\t\tdescription: QUESTION_DESCRIPTION,\n\t\tpromptSnippet: QUESTION_PROMPT_SNIPPET,\n\t\tpromptGuidelines: QUESTION_PROMPT_GUIDELINES,\n\t\tparameters: QuestionParams,\n\t\tconstrainedSampling: { type: \"json_schema\", strict: \"prefer\" },\n\t\tprepareArguments: normalizeQuestionArguments,\n\t\texecutionMode: \"sequential\",\n\t\trenderCall(args, theme, context) {\n\t\t\treturn renderQuestionCall(args, theme, context.expanded);\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\treturn renderQuestionResult(result, options, theme, context.args);\n\t\t},\n\n\t\tasync execute(_toolCallId, params, signal, _onUpdate, ctx) {\n\t\t\tconst questions = params.questions as Question[];\n\t\t\tif (!ctx.hasUI || ctx.mode !== \"tui\") return errorResult(\"no_ui\", \"question tool requires an interactive TUI\");\n\n\t\t\tconst validation = validateQuestions(questions);\n\t\t\tif (!validation.ok) return errorResult(validation.error, validation.message);\n\n\t\t\tconst result = await ctx.ui.custom<DialogResult>(createQuestionDialog(questions, signal));\n\t\t\tif (result.outcome === \"cancelled\") return cancelResult(result.answers);\n\t\t\tif (result.outcome === \"needs_clarification\") return clarificationResult(result.answers);\n\t\t\treturn successResult(result.answers);\n\t\t},\n\t});\n\n\tpi.on(\"tool_result\", async (event) => {\n\t\tif (event.toolName !== QUESTION_TOOL_NAME) return;\n\t\tconst details = event.details as QuestionToolDetails | undefined;\n\t\tif (details?.outcome === \"error\") return { isError: true };\n\t});\n}\n"]}
@@ -1,5 +1,8 @@
1
1
  import { Type } from "typebox";
2
2
  import type { Question, QuestionToolError } from "./types.ts";
3
+ type QuestionArgs = {
4
+ questions: Question[];
5
+ };
3
6
  export declare const QuestionParams: Type.TObject<{
4
7
  questions: Type.TArray<Type.TObject<{
5
8
  question: Type.TString;
@@ -12,6 +15,20 @@ export declare const QuestionParams: Type.TObject<{
12
15
  multiSelect: Type.TOptional<Type.TBoolean>;
13
16
  }>>;
14
17
  }>;
18
+ /**
19
+ * Unambiguous argument normalizations applied before schema validation; the
20
+ * schema itself stays a single object shape because strict constrained
21
+ * sampling does not support object unions. Everything else is left for
22
+ * validation to report.
23
+ *
24
+ * - a lone question written flat at the root ({question, header?, options,
25
+ * multiSelect?} with no questions) wraps into questions[0];
26
+ * - a root-level question string fills a questions[0] object that lost its
27
+ * own question field to the root;
28
+ * - a stringified questions array parses back into an array (a parse failure
29
+ * stays for validation to reject).
30
+ */
31
+ export declare function normalizeQuestionArguments(raw: unknown): QuestionArgs;
15
32
  /**
16
33
  * Checks visible non-whitespace text and cross-field rules the schema cannot
17
34
  * express. Length and count limits remain enforced by `QuestionParams` first.
@@ -23,4 +40,5 @@ export declare function validateQuestions(questions: Question[]): {
23
40
  error: QuestionToolError;
24
41
  message: string;
25
42
  };
43
+ export {};
26
44
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/extensions/question/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,KAAK,EAAE,QAAQ,EAAkB,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAyD9E,eAAO,MAAM,cAAc;;;;;;;;;;;EAMzB,CAAC;AAEH;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,SAAS,EAAE,QAAQ,EAAE,GACnB;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAiEzE"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/extensions/question/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,KAAK,EAAE,QAAQ,EAAkB,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE9E,KAAK,YAAY,GAAG;IAAE,SAAS,EAAE,QAAQ,EAAE,CAAA;CAAE,CAAC;AAyD9C,eAAO,MAAM,cAAc;;;;;;;;;;;EAMzB,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,YAAY,CAuCrE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAChC,SAAS,EAAE,QAAQ,EAAE,GACnB;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAiEzE"}
@@ -50,6 +50,58 @@ export const QuestionParams = Type.Object({
50
50
  description: "Related decisions to ask now (1-4); ask only what is needed to unblock progress.",
51
51
  }),
52
52
  });
53
+ /**
54
+ * Unambiguous argument normalizations applied before schema validation; the
55
+ * schema itself stays a single object shape because strict constrained
56
+ * sampling does not support object unions. Everything else is left for
57
+ * validation to report.
58
+ *
59
+ * - a lone question written flat at the root ({question, header?, options,
60
+ * multiSelect?} with no questions) wraps into questions[0];
61
+ * - a root-level question string fills a questions[0] object that lost its
62
+ * own question field to the root;
63
+ * - a stringified questions array parses back into an array (a parse failure
64
+ * stays for validation to reject).
65
+ */
66
+ export function normalizeQuestionArguments(raw) {
67
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw))
68
+ return raw;
69
+ const args = { ...raw };
70
+ if (typeof args.questions === "string") {
71
+ try {
72
+ const parsed = JSON.parse(args.questions);
73
+ if (Array.isArray(parsed))
74
+ args.questions = parsed;
75
+ }
76
+ catch {
77
+ // Leave the string for schema validation to reject.
78
+ }
79
+ }
80
+ const rootQuestion = typeof args.question === "string" ? args.question : undefined;
81
+ const onlyQuestion = Array.isArray(args.questions) && args.questions.length === 1 ? args.questions[0] : undefined;
82
+ if (rootQuestion !== undefined &&
83
+ onlyQuestion !== null &&
84
+ typeof onlyQuestion === "object" &&
85
+ !Array.isArray(onlyQuestion) &&
86
+ onlyQuestion.question === undefined) {
87
+ args.questions = [{ ...onlyQuestion, question: rootQuestion }];
88
+ delete args.question;
89
+ return args;
90
+ }
91
+ if (args.questions === undefined && rootQuestion !== undefined && args.options !== undefined) {
92
+ const question = { question: rootQuestion, options: args.options };
93
+ if (args.header !== undefined)
94
+ question.header = args.header;
95
+ if (args.multiSelect !== undefined)
96
+ question.multiSelect = args.multiSelect;
97
+ delete args.question;
98
+ delete args.options;
99
+ delete args.header;
100
+ delete args.multiSelect;
101
+ args.questions = [question];
102
+ }
103
+ return args;
104
+ }
53
105
  /**
54
106
  * Checks visible non-whitespace text and cross-field rules the schema cannot
55
107
  * express. Length and count limits remain enforced by `QuestionParams` first.