qlogicagent 2.15.9 → 2.16.1

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 (61) hide show
  1. package/dist/agent.js +34 -16
  2. package/dist/cli.js +585 -514
  3. package/dist/index.js +584 -513
  4. package/dist/orchestration.js +9 -9
  5. package/dist/protocol.js +1 -1
  6. package/dist/types/agent/tool-loop/artifact-final-contract.d.ts +86 -0
  7. package/dist/types/agent/tool-loop/completion-action-policy.d.ts +1 -9
  8. package/dist/types/agent/tool-loop/tool-failure-policy.d.ts +2 -0
  9. package/dist/types/agent/tool-loop.d.ts +4 -10
  10. package/dist/types/agent/types.d.ts +9 -131
  11. package/dist/types/cli/acp-extended-handlers.d.ts +1 -0
  12. package/dist/types/cli/agent-config-coordinator.d.ts +11 -0
  13. package/dist/types/cli/core-tools/agent-tool-service.d.ts +1 -0
  14. package/dist/types/cli/handlers/agents-handler.d.ts +15 -6
  15. package/dist/types/cli/handlers/product-handler.d.ts +21 -2
  16. package/dist/types/cli/handlers/project-handler.d.ts +8 -0
  17. package/dist/types/cli/handlers/workflow-handler.d.ts +5 -0
  18. package/dist/types/cli/tool-bootstrap-core-registration.d.ts +5 -0
  19. package/dist/types/cli/turn-core.d.ts +4 -0
  20. package/dist/types/contracts/index.d.ts +1 -0
  21. package/dist/types/contracts/turn-event.d.ts +235 -0
  22. package/dist/types/orchestration/agent-instance.d.ts +45 -2
  23. package/dist/types/orchestration/agent-roster.d.ts +17 -0
  24. package/dist/types/orchestration/dag-scheduler.d.ts +27 -0
  25. package/dist/types/orchestration/product-budget.d.ts +7 -1
  26. package/dist/types/orchestration/product-persistence.d.ts +31 -0
  27. package/dist/types/orchestration/product-planner.d.ts +123 -0
  28. package/dist/types/orchestration/product-run-coordinator.d.ts +17 -1
  29. package/dist/types/orchestration/product-worktree.d.ts +3 -0
  30. package/dist/types/orchestration/skill-improvement.d.ts +2 -19
  31. package/dist/types/orchestration/solo-evaluator.d.ts +11 -6
  32. package/dist/types/orchestration/solo-spec-builder.d.ts +4 -0
  33. package/dist/types/orchestration/workflow/n8n-import.d.ts +26 -32
  34. package/dist/types/orchestration/workflow/n8n-template-compat.d.ts +5 -0
  35. package/dist/types/orchestration/workflow/node-registry.d.ts +13 -0
  36. package/dist/types/orchestration/workflow/node-schema.d.ts +10 -0
  37. package/dist/types/orchestration/workflow/qla-executor-host.d.ts +7 -1
  38. package/dist/types/protocol/methods.d.ts +8 -1
  39. package/dist/types/protocol/notifications.d.ts +1 -1
  40. package/dist/types/protocol/wire/acp-agent-management.d.ts +51 -0
  41. package/dist/types/protocol/wire/acp-protocol.d.ts +1 -0
  42. package/dist/types/protocol/wire/agent-events.d.ts +3 -3
  43. package/dist/types/protocol/wire/agent-methods.d.ts +14 -2
  44. package/dist/types/protocol/wire/index.d.ts +1 -1
  45. package/dist/types/protocol/wire/notification-payloads.d.ts +120 -11
  46. package/dist/types/runtime/infra/acp-detector.d.ts +37 -2
  47. package/dist/types/runtime/infra/acp-protocol-adapter.d.ts +9 -0
  48. package/dist/types/runtime/infra/agent-install-runner.d.ts +23 -0
  49. package/dist/types/runtime/infra/agent-process.d.ts +10 -0
  50. package/dist/types/runtime/ports/agent-execution-contracts.d.ts +4 -128
  51. package/dist/types/runtime/ports/tool-contracts.d.ts +6 -0
  52. package/dist/types/runtime/prompt/environment-context.d.ts +20 -1
  53. package/dist/types/skills/tools/ask-user-tool.d.ts +4 -2
  54. package/dist/types/skills/tools/shell/command-classification.d.ts +1 -0
  55. package/dist/types/skills/tools/tool-search-tool.d.ts +13 -0
  56. package/dist/types/skills/tools/tool-selection-eval.d.ts +49 -0
  57. package/dist/types/skills/tools/tool-selection-eval.dataset.d.ts +5 -0
  58. package/dist/types/skills/tools/write-tool.d.ts +2 -0
  59. package/dist/types/skills/tools.d.ts +21 -0
  60. package/dist/types/transport/acp-server.d.ts +1 -0
  61. package/package.json +2 -1
@@ -5,7 +5,6 @@
5
5
  * protocol/wire/. This file re-exports them and adds
6
6
  * internal-only extensions (e.g. backfillObservableInput on ToolDefinition).
7
7
  */
8
- import type { SkillInstruction } from "../orchestration/index.js";
9
8
  import type { HookRegistry } from "../contracts/hooks.js";
10
9
  import type { AccumulatedToolCall, LLMChunk, LLMRequest, LLMTransport } from "../runtime/ports/index.js";
11
10
  import type { ChatMessage as WireChatMessage, ChatMessageRole as WireChatMessageRole, ThinkingBlock as WireThinkingBlock, ToolCallMessage as WireToolCallMessage, ToolDefinition as WireToolDefinition, WireTokenUsage } from "../protocol/wire/index.js";
@@ -30,6 +29,7 @@ export interface ToolDefinition extends WireToolDefinition {
30
29
  * (inputTokens, outputTokens, reasoningTokens, cacheRead, cacheWrite).
31
30
  */
32
31
  export type TokenUsage = WireTokenUsage;
32
+ export type { DecisionStateRecord, GoalReconstructionState, MaintainedDocumentIndex, ReadCycleGuard, SkillCreateInstruction, SkillImproveInstruction, SkillInstruction, TurnEvent, } from "../contracts/turn-event.js";
33
33
  /**
34
34
  * Why the previous iteration continuedeach variant corresponds to one of
35
35
  * the 7 `continue` sites in the main while(true) loop.
@@ -79,7 +79,15 @@ export interface TurnRequest {
79
79
  turnId: string;
80
80
  sessionId: string;
81
81
  messages: ChatMessage[];
82
+ /** Full registered tool surface before per-turn policy filtering. */
83
+ availableTools?: ToolDefinition[];
82
84
  tools: ToolDefinition[];
85
+ /**
86
+ * Live tool-manifest rebuild, consulted each loop iteration (turnCount > 1).
87
+ * Lets a tool activated mid-turn via tool_search become callable in the SAME
88
+ * turn instead of only on the next user message.
89
+ */
90
+ refreshTools?: () => ToolDefinition[];
83
91
  systemPrompt?: string;
84
92
  config?: TurnConfig;
85
93
  }
@@ -158,136 +166,6 @@ export interface TurnConfig {
158
166
  /** MCP server configurations (stdio/sse/http). Passed from host to agent per-turn. */
159
167
  mcpServers?: Record<string, unknown>;
160
168
  }
161
- export type TurnEvent = {
162
- type: "start";
163
- turnId: string;
164
- } | {
165
- type: "delta";
166
- turnId: string;
167
- text: string;
168
- } | {
169
- type: "tool_call";
170
- turnId: string;
171
- callId: string;
172
- name: string;
173
- arguments: string;
174
- inputSummary?: string;
175
- } | {
176
- type: "end";
177
- turnId: string;
178
- content: string;
179
- usage?: TokenUsage;
180
- model?: string;
181
- provider?: string;
182
- /** Per-turn recovery trace (action -> count); present only when recoveries fired. */
183
- recoveryTrace?: Record<string, number>;
184
- } | {
185
- type: "error";
186
- turnId: string;
187
- error: string;
188
- code?: string;
189
- usage?: TokenUsage;
190
- } | {
191
- type: "skill_instruction";
192
- turnId: string;
193
- instruction: SkillInstruction;
194
- } | {
195
- type: "tool_result";
196
- turnId: string;
197
- callId: string;
198
- name: string;
199
- ok: boolean;
200
- error?: string;
201
- outputPreview?: string;
202
- durationMs?: number;
203
- exitCode?: number;
204
- stdout?: string;
205
- stderr?: string;
206
- details?: Record<string, unknown>;
207
- } | {
208
- type: "tool_blocked";
209
- turnId: string;
210
- callId: string;
211
- name: string;
212
- reason: string;
213
- } | {
214
- type: "recovery";
215
- turnId: string;
216
- action: string;
217
- detail?: string;
218
- } | {
219
- type: "plan_update";
220
- turnId: string;
221
- slug: string;
222
- content: string;
223
- } | {
224
- type: "heartbeat";
225
- turnId: string;
226
- message: string;
227
- } | {
228
- type: "tool_use_summary";
229
- turnId: string;
230
- summary: string;
231
- } | {
232
- type: "reasoning_delta";
233
- turnId: string;
234
- text: string;
235
- } | {
236
- type: "suggestions";
237
- turnId: string;
238
- items: Array<{
239
- text: string;
240
- icon?: string;
241
- action?: string;
242
- }>;
243
- } | {
244
- type: "media_result";
245
- turnId: string;
246
- mediaType: "image" | "tts" | "video" | "music" | "3d";
247
- url: string;
248
- model?: string;
249
- provider?: string;
250
- durationSeconds?: number;
251
- width?: number;
252
- height?: number;
253
- mimeType?: string;
254
- billingUnit?: string;
255
- billingQuantity?: number;
256
- taskId?: string;
257
- } | {
258
- type: "artifact";
259
- turnId: string;
260
- artifactId: string;
261
- artifactType: "code" | "file" | "image" | "document" | "diagram" | "table";
262
- title: string;
263
- filePath?: string;
264
- language?: string;
265
- content?: string;
266
- mimeType?: string;
267
- } | {
268
- type: "annotations";
269
- turnId: string;
270
- annotations: Array<{
271
- type: string;
272
- url?: string;
273
- title?: string;
274
- [key: string]: unknown;
275
- }>;
276
- } | {
277
- type: "subagent_started";
278
- turnId: string;
279
- subagentId: string;
280
- agentType: string;
281
- prompt?: string;
282
- } | {
283
- type: "subagent_ended";
284
- turnId: string;
285
- subagentId: string;
286
- agentType: string;
287
- ok: boolean;
288
- outputPreview?: string;
289
- error?: string;
290
- };
291
169
  /**
292
170
  * ToolInvoker: request tool execution from the host process (Gateway).
293
171
  * In CLI mode this sends a JSON-RPC notification over stdio and waits for result.
@@ -67,4 +67,5 @@ export declare function handleAcpProductStatus(host: AcpExtendedHost, params: Re
67
67
  export declare function handleAcpProductPause(host: AcpExtendedHost, params: Record<string, unknown>): Promise<unknown>;
68
68
  export declare function handleAcpProductCancel(host: AcpExtendedHost, params: Record<string, unknown>): Promise<unknown>;
69
69
  export declare function handleAcpProductRollback(host: AcpExtendedHost, params: Record<string, unknown>): Promise<unknown>;
70
+ export declare function handleAcpProductReplay(host: AcpExtendedHost, params: Record<string, unknown>): Promise<unknown>;
70
71
  export declare function handleAcpProductSubscribe(host: AcpExtendedHost, params: Record<string, unknown>): Promise<unknown>;
@@ -9,8 +9,19 @@ export declare function resolveLlmrouterProtocolBaseUrl(agentId: string, rawBase
9
9
  export declare class AgentConfigCoordinator {
10
10
  private readonly deps;
11
11
  private store;
12
+ /** Last resolved managed text model (llmrouterModel), to detect primary-model switches. */
13
+ private lastLlmrouterModel;
12
14
  constructor(deps: AgentConfigCoordinatorDeps);
13
15
  get currentStore(): AgentConfigStore | null;
14
16
  ensureStore(): Promise<AgentConfigStore>;
15
17
  private syncKeySources;
18
+ /**
19
+ * When the managed text model (llmrouterModel) actually changes, pooled OpenAI-compat agents
20
+ * (codex/qwen/opencode) still hold the OLD OPENAI_MODEL baked at spawn. Evict the platform-model
21
+ * followers — managed (explicit「平台额度」) or auto, NOT explicit account/userKey BYO — so the next
22
+ * turn respawns on the new model. The model-switch analogue of the credential-switch eviction (Cut 6);
23
+ * busy turns settle first (handled inside evictPooledAgentsByAgentId). Runs per agents operation via
24
+ * syncKeySources, so a primary-model switch takes effect on the next message.
25
+ */
26
+ private evictModelFollowersIfChanged;
16
27
  }
@@ -10,6 +10,7 @@ export interface AgentToolServiceHost {
10
10
  readonly currentTransport: LLMTransport | null;
11
11
  readonly currentApiKey: string;
12
12
  readonly currentModel: string;
13
+ readonly currentTurnId?: string;
13
14
  sendNotification(method: string, params: Record<string, unknown>): void;
14
15
  /** Unified background execution registry. Required for background=true forks. */
15
16
  getBackgroundTasks(): BackgroundTaskManager | null;
@@ -8,6 +8,7 @@ import { type AgentRpcError, type AgentRpcRequest } from "../../protocol/wire/in
8
8
  import { AgentProcessManager } from "../../runtime/infra/agent-process.js";
9
9
  import type { AgentConfigStore } from "../../runtime/infra/agent-config-store.js";
10
10
  import { type AcpDetector } from "../../runtime/infra/acp-detector.js";
11
+ import { type PooledTurnCtx } from "../../runtime/infra/external-agent-pool.js";
11
12
  export interface AgentsHandlerHost {
12
13
  acpDetector: AcpDetector;
13
14
  soloProcessManager: AgentProcessManager | null;
@@ -19,6 +20,13 @@ export interface AgentsHandlerHost {
19
20
  sendResponse(id: string | number, result?: unknown, error?: AgentRpcError): void;
20
21
  sendNotification?(method: string, params: Record<string, unknown>): void;
21
22
  }
23
+ export declare function relayPooledTurnNotification(input: {
24
+ agentId: string;
25
+ turn: PooledTurnCtx | null;
26
+ method: string;
27
+ payload: unknown;
28
+ sendNotification?: (method: string, params: Record<string, unknown>) => void;
29
+ }): void;
22
30
  /** Resolve a pending external-agent approval with the user's decision (delivered by the gateway). */
23
31
  export declare function handleAgentsApprovalResponse(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
24
32
  export declare function handleAgentsScan(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
@@ -29,12 +37,6 @@ export declare function handleAgentsList(this: AgentsHandlerHost, msg: AgentRpcR
29
37
  * summary + source for the confirm dialog (no secrets).
30
38
  */
31
39
  export declare function handleAgentsCatalog(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
32
- /**
33
- * Background update check (VS Code pattern): resolve latest npm versions for installed catalog agents
34
- * in PARALLEL, off the catalog hot path. The frontend calls this AFTER the (instant) catalog render
35
- * and merges the results to light up "update available" badges — never blocking the panel from
36
- * opening. Returns `{ updates: CatalogUpdateInfo[] }` (only agents with a resolved latest version).
37
- */
38
40
  export declare function handleAgentsCheckUpdates(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
39
41
  /**
40
42
  * One-click install a catalog agent by id. Runs ONLY the official command from the
@@ -42,6 +44,13 @@ export declare function handleAgentsCheckUpdates(this: AgentsHandlerHost, msg: A
42
44
  * agent.install.progress notification, then refreshes detection. Returns the outcome.
43
45
  */
44
46
  export declare function handleAgentsInstall(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
47
+ /**
48
+ * Open an OS terminal running an agent's interactive login/setup command (e.g. `kimi login`,
49
+ * `hermes acp --setup`). Lowers the barrier for own-store/oauth agents that can't be driven via
50
+ * injected credentials — the user completes the CLI's native login without leaving the app. The
51
+ * command is resolved server-side from the catalog (fixed string, no user input → no injection).
52
+ */
53
+ export declare function handleAgentsRunSetup(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
45
54
  export declare function handleAgentsConfig(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
46
55
  export declare function handleAgentsSetConfig(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
47
56
  export declare function handleAgentsGetConfig(this: AgentsHandlerHost, msg: AgentRpcRequest): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Product mode handlers.
3
- * Handles: product.plan/confirm/message/create/resume/pause/checkpoint/status/list/delete/cancel/rollback.
3
+ * Handles: product.plan/confirm/message/create/resume/pause/checkpoint/status/list/delete/cancel/rollback/replay.
4
4
  */
5
5
  import { type AgentRpcError, type AgentRpcRequest } from "../../protocol/wire/index.js";
6
6
  import { type ProductCoordinatorHost } from "../product-coordinator.js";
@@ -31,7 +31,26 @@ export declare function handleProductStatus(this: ProductHandlerHost, msg: Agent
31
31
  /** `product.list` - List all products. */
32
32
  export declare function handleProductList(this: ProductHandlerHost, msg: AgentRpcRequest): Promise<void>;
33
33
  export declare function handleProductDelete(this: ProductHandlerHost, msg: AgentRpcRequest): Promise<void>;
34
- /** `product.cancel` - Cancel a running product. */
34
+ /**
35
+ * Cancel a product no matter which lifecycle phase it is in. The orchestrator only knows
36
+ * POST-confirm (executing) sessions; while the leader is still PLANNING, the product lives in
37
+ * `ProductPlanner.sessions` instead. Previously cancel only routed to `orchestrator.delete`, so
38
+ * cancelling a stalled planning leader threw "Product not found" and never killed it.
39
+ *
40
+ * Strategy (idempotent):
41
+ * 1. Try `orchestrator.delete` (post-confirm path).
42
+ * 2. If that fails because the product isn't an orchestrator session ("not found"), fall back to
43
+ * `planner.cancel` (planning-phase path — kills the leader process).
44
+ * 3. If neither side has the product, resolve ok rather than throwing (cancel is best-effort).
45
+ */
46
+ export declare function cancelProductAnyPhase(orchestrator: {
47
+ delete(productId: string): Promise<void>;
48
+ }, planner: {
49
+ cancel(productId: string): Promise<void>;
50
+ }, productId: string): Promise<void>;
51
+ /** `product.cancel` - Cancel a running product (handles both executing and planning phases). */
35
52
  export declare function handleProductCancel(this: ProductHandlerHost, msg: AgentRpcRequest): Promise<void>;
36
53
  /** `product.rollback` - Rollback a product to a checkpoint. */
37
54
  export declare function handleProductRollback(this: ProductHandlerHost, msg: AgentRpcRequest): Promise<void>;
55
+ /** `product.replay` - Re-run from an arbitrary completed/failed task forward, reusing upstream outputs. */
56
+ export declare function handleProductReplay(this: ProductHandlerHost, msg: AgentRpcRequest): Promise<void>;
@@ -19,6 +19,14 @@ export interface ProjectHandlerHost {
19
19
  }
20
20
  export declare function handleProjectCreate(this: ProjectHandlerHost, msg: AgentRpcRequest): Promise<void>;
21
21
  export declare function handleProjectList(this: ProjectHandlerHost, msg: AgentRpcRequest): void;
22
+ /**
23
+ * Reliable recursive directory removal for Windows. fs.rmSync({recursive,force}) cannot be trusted
24
+ * here: on git repos it silently leaves read-only object/pack files (and whole subtrees) behind
25
+ * without throwing. This walks bottom-up, clearing the read-only attribute (chmod) on the EPERM
26
+ * retry, which deletes git worktrees/repos cleanly. Per-entry failures (e.g. a live EBUSY lock) are
27
+ * swallowed; the caller verifies via existsSync and decides success/retry.
28
+ */
29
+ export declare function rmDirRobustSync(target: string): void;
22
30
  export declare function handleProjectDelete(this: ProjectHandlerHost, msg: AgentRpcRequest): void;
23
31
  export declare function handleProjectPurgeAll(this: ProjectHandlerHost, msg: AgentRpcRequest): void;
24
32
  export declare function handleProjectRename(this: ProjectHandlerHost, msg: AgentRpcRequest): void;
@@ -39,6 +39,11 @@ export interface WorkflowCoordinatorHost {
39
39
  handleMcpToolCall(memberId: string, tool: string, args: Record<string, unknown>): Promise<unknown>;
40
40
  sendNotification(method: string, params: Record<string, unknown>): void;
41
41
  toolCatalog: ToolCatalog;
42
+ resolveClientForPurpose?: (purpose: "textGeneration") => {
43
+ transport: import("../provider-core-facade.js").LLMTransport;
44
+ apiKey: string;
45
+ model: string;
46
+ } | null;
42
47
  /** Per-root engine bundles keyed by resolved cwd; built lazily by ensureWorkflowRoot. */
43
48
  workflowRoots: Map<string, WorkflowRootBundle> | null;
44
49
  }
@@ -26,6 +26,11 @@ export interface LocalCoreToolRegistrationContext {
26
26
  listToolNames(): string[];
27
27
  findRegisteredTool(name: string): RuntimeToolContract | undefined;
28
28
  activateRegisteredTool(name: string): boolean;
29
+ listDeferredTools(): Array<{
30
+ name: string;
31
+ description: string;
32
+ searchHint?: string;
33
+ }>;
29
34
  }
30
35
  export declare function setGroupSecurityMode(enabled: boolean): void;
31
36
  export declare const localCoreToolRegistrationModule: import("../runtime/ports/tool-contracts.js").ToolRegistrationModule<LocalCoreToolRegistrationContext>;
@@ -11,7 +11,11 @@ export interface TurnCoreRequest {
11
11
  turnId: string;
12
12
  sessionId: string;
13
13
  messages: ChatMessage[];
14
+ /** Full registered tool surface before per-turn policy filtering. */
15
+ availableTools?: ToolDefinition[];
14
16
  tools: ToolDefinition[];
17
+ /** Live tool-manifest rebuild for same-turn activation (forwarded to the loop). */
18
+ refreshTools?: () => ToolDefinition[];
15
19
  systemPrompt: string;
16
20
  config: TurnConfig;
17
21
  }
@@ -2,3 +2,4 @@
2
2
  * Internal contracts — hooks.
3
3
  */
4
4
  export * from "./hooks.js";
5
+ export type { DecisionStateRecord, GoalReconstructionState, MaintainedDocumentIndex, ReadCycleGuard, SkillCreateInstruction, SkillImproveInstruction, SkillInstruction, TurnEvent, } from "./turn-event.js";
@@ -0,0 +1,235 @@
1
+ import type { WireTokenUsage } from "../protocol/wire/index.js";
2
+ export interface SkillCreateInstruction {
3
+ type: "skill.create";
4
+ /** Suggested skill name derived from tool usage pattern */
5
+ suggestedName: string;
6
+ /** Short description of what the skill does */
7
+ description: string;
8
+ /** Tool names involved */
9
+ tools: string[];
10
+ /** Number of orchestration steps */
11
+ stepCount: number;
12
+ }
13
+ export interface SkillImproveInstruction {
14
+ type: "skill.improve";
15
+ /** Existing skill to improve */
16
+ skillName: string;
17
+ /** Reason for improvement */
18
+ reason: string;
19
+ }
20
+ export type SkillInstruction = SkillCreateInstruction | SkillImproveInstruction;
21
+ export type TurnEvent = {
22
+ type: "start";
23
+ turnId: string;
24
+ } | {
25
+ type: "delta";
26
+ turnId: string;
27
+ text: string;
28
+ } | {
29
+ type: "tool_call";
30
+ turnId: string;
31
+ callId: string;
32
+ name: string;
33
+ arguments: string;
34
+ inputSummary?: string;
35
+ } | {
36
+ type: "end";
37
+ turnId: string;
38
+ content: string;
39
+ usage?: WireTokenUsage;
40
+ model?: string;
41
+ provider?: string;
42
+ /** Per-turn recovery trace (action -> count); present only when recoveries fired. */
43
+ recoveryTrace?: Record<string, number>;
44
+ } | {
45
+ type: "error";
46
+ turnId: string;
47
+ error: string;
48
+ code?: string;
49
+ usage?: WireTokenUsage;
50
+ } | {
51
+ type: "skill_instruction";
52
+ turnId: string;
53
+ instruction: SkillInstruction;
54
+ } | {
55
+ type: "tool_result";
56
+ turnId: string;
57
+ callId: string;
58
+ name: string;
59
+ ok: boolean;
60
+ error?: string;
61
+ outputPreview?: string;
62
+ durationMs?: number;
63
+ exitCode?: number;
64
+ stdout?: string;
65
+ stderr?: string;
66
+ details?: Record<string, unknown>;
67
+ } | {
68
+ type: "tool_blocked";
69
+ turnId: string;
70
+ callId: string;
71
+ name: string;
72
+ reason: string;
73
+ } | {
74
+ type: "recovery";
75
+ turnId: string;
76
+ action: string;
77
+ detail?: string;
78
+ } | {
79
+ type: "tool_selection_policy";
80
+ turnId: string;
81
+ policyId: string;
82
+ intent: "benchmark_state_maintenance" | "fresh_evidence" | "verification" | "final_answer" | "deferred_tool_discovery" | "tool_recovery" | "lifecycle_reconciliation";
83
+ reason: string;
84
+ availableToolNames: string[];
85
+ enabledToolNamesBefore: string[];
86
+ enabledToolNamesAfter: string[];
87
+ suppressedToolNames: string[];
88
+ nextAction: string;
89
+ } | {
90
+ type: "plan_update";
91
+ turnId: string;
92
+ slug: string;
93
+ content: string;
94
+ } | {
95
+ type: "heartbeat";
96
+ turnId: string;
97
+ message: string;
98
+ } | {
99
+ type: "tool_use_summary";
100
+ turnId: string;
101
+ telemetrySource?: "agent" | "agent-synthetic";
102
+ availableToolNames: string[];
103
+ enabledToolNames: string[];
104
+ toolCallNames: string[];
105
+ blockedToolCalls: Array<{
106
+ name: string;
107
+ reason: string;
108
+ }>;
109
+ } | {
110
+ type: "lifecycle";
111
+ turnId: string;
112
+ kind: "stage" | "reopen" | "resume" | "context_compression" | "goal_reconstruction" | "memory_drift" | "artifact_path_drift";
113
+ stage?: string;
114
+ status?: string;
115
+ detail?: string;
116
+ reconstruction?: GoalReconstructionState;
117
+ observedAt?: string;
118
+ } | {
119
+ type: "document_maintenance";
120
+ turnId: string;
121
+ checkpointId: string;
122
+ documents: MaintainedDocumentIndex[];
123
+ decisionStateTable: DecisionStateRecord[];
124
+ readCycleFindings: Array<Record<string, unknown>>;
125
+ readCycleGuard: ReadCycleGuard;
126
+ observedAt?: string;
127
+ } | {
128
+ type: "reasoning_delta";
129
+ turnId: string;
130
+ text: string;
131
+ } | {
132
+ type: "suggestions";
133
+ turnId: string;
134
+ items: Array<{
135
+ text: string;
136
+ icon?: string;
137
+ action?: string;
138
+ }>;
139
+ } | {
140
+ type: "media_result";
141
+ turnId: string;
142
+ mediaType: "image" | "tts" | "video" | "music" | "3d";
143
+ url: string;
144
+ model?: string;
145
+ provider?: string;
146
+ durationSeconds?: number;
147
+ width?: number;
148
+ height?: number;
149
+ mimeType?: string;
150
+ billingUnit?: string;
151
+ billingQuantity?: number;
152
+ taskId?: string;
153
+ } | {
154
+ type: "artifact";
155
+ turnId: string;
156
+ artifactId: string;
157
+ artifactType: "code" | "file" | "image" | "document" | "diagram" | "table";
158
+ title: string;
159
+ filePath?: string;
160
+ language?: string;
161
+ content?: string;
162
+ mimeType?: string;
163
+ } | {
164
+ type: "artifact_contract";
165
+ turnId: string;
166
+ artifactRoot?: string;
167
+ writePaths: string[];
168
+ outOfRootWrites: Array<{
169
+ path: string;
170
+ artifactRoot: string;
171
+ toolName: string;
172
+ }>;
173
+ devServerUrls: string[];
174
+ browserVerified: boolean;
175
+ browserEvidence: string[];
176
+ requiresBrowserAcceptance: boolean;
177
+ } | {
178
+ type: "annotations";
179
+ turnId: string;
180
+ annotations: Array<{
181
+ type: string;
182
+ url?: string;
183
+ title?: string;
184
+ [key: string]: unknown;
185
+ }>;
186
+ } | {
187
+ type: "subagent_started";
188
+ turnId: string;
189
+ subagentId: string;
190
+ agentType: string;
191
+ prompt?: string;
192
+ } | {
193
+ type: "subagent_ended";
194
+ turnId: string;
195
+ subagentId: string;
196
+ agentType: string;
197
+ ok: boolean;
198
+ outputPreview?: string;
199
+ error?: string;
200
+ };
201
+ export interface GoalReconstructionState {
202
+ goal: string;
203
+ artifactRoot: string;
204
+ decisions: string[];
205
+ defects: string[];
206
+ acceptanceCriteria: string[];
207
+ blockers: string[];
208
+ nextAction: string;
209
+ }
210
+ export interface MaintainedDocumentIndex {
211
+ name?: string;
212
+ path?: string;
213
+ indexed: true;
214
+ maintained: true;
215
+ indexVersion: string;
216
+ contentHash: string;
217
+ summary: string;
218
+ lastReviewedTurn: number;
219
+ fileSizeBytes: number;
220
+ recordCount: number;
221
+ }
222
+ export interface DecisionStateRecord {
223
+ id: string;
224
+ decision: string;
225
+ status: string;
226
+ evidence: string;
227
+ lastConfirmedTurn: number;
228
+ }
229
+ export interface ReadCycleGuard {
230
+ strategy: string;
231
+ nextReadPolicy: string;
232
+ budgetStatus: "within-budget";
233
+ maxReadsPerDocument: number;
234
+ observedReadsByPath: Record<string, number>;
235
+ }
@@ -24,7 +24,11 @@ export interface ProductCallbacks {
24
24
  warn(msg: string): void;
25
25
  };
26
26
  onTaskStarted?: (productId: string, taskId: string, assignee: string) => void;
27
- onTaskCompleted?: (productId: string, taskId: string, result: string) => void;
27
+ onTaskCompleted?: (productId: string, taskId: string, result: string, meta?: {
28
+ inputTokens: number;
29
+ outputTokens: number;
30
+ changedFiles: string[];
31
+ }) => void;
28
32
  onTaskFailed?: (productId: string, taskId: string, error: string) => void;
29
33
  onCheckpointed?: (productId: string, timestamp: string) => void;
30
34
  onBudgetWarning?: (productId: string, usedTokens: number, maxTotalTokens: number, percentage: number) => void;
@@ -42,7 +46,29 @@ export interface ProductCallbacks {
42
46
  onBudgetUpdate?: (productId: string, inputTokens: number, outputTokens: number, elapsed: number, maxTotalTokens?: number) => void;
43
47
  /** Streaming text output from a running task. */
44
48
  onTaskOutputDelta?: (productId: string, taskId: string, text: string) => void;
49
+ /** Team roster resolved at run start — fired once (engine-driven) for both initial start and resume,
50
+ * so the run view's 团队成员 panel populates live instead of only on a history reopen. */
51
+ onMembers?: (productId: string, members: {
52
+ agentId: string;
53
+ role: string;
54
+ name: string;
55
+ }[]) => void;
45
56
  }
57
+ /**
58
+ * Prepend completed upstream task outputs to a downstream task prompt so the
59
+ * worker agent can see what its predecessors produced (research→writing, etc.).
60
+ * If there are no upstream outputs the original prompt is returned unchanged.
61
+ *
62
+ * NOTE: Only used for the agent-facing sends (spawn/sendTask/recovery).
63
+ * The original prompt is kept separate for evidence heuristics
64
+ * (requiresExplicitCompletionEvidence, assertProductTaskCompletionEvidence,
65
+ * assertProductTaskMaterializedEvidence) which inspect the task instruction
66
+ * for specific markers and keywords — the context prefix must not pollute them.
67
+ */
68
+ export declare function buildTaskContextPrompt(upstream: {
69
+ taskId: string;
70
+ output: string;
71
+ }[], prompt: string): string;
46
72
  export declare class ProductOrchestrator {
47
73
  private processManager;
48
74
  private acpDetector;
@@ -66,9 +92,26 @@ export declare class ProductOrchestrator {
66
92
  /** Delete a product session, pausing first if active. */
67
93
  delete(productId: string): Promise<void>;
68
94
  /** Rollback a product to a checkpoint: delete running session then resume from disk. */
69
- rollback(productId: string, _checkpoint: string): Promise<void>;
95
+ rollback(productId: string, checkpoint?: string): Promise<void>;
96
+ /**
97
+ * Replay from an arbitrary completed/failed task (CrewAI Crew.replay(taskId) parity).
98
+ *
99
+ * Resets the task + all its transitive descendants to pending (clearing their outputs) while
100
+ * leaving ancestors completed — so the re-run automatically reuses upstream outputs via the
101
+ * existing task-context injection (getUpstreamOutputs at dispatch). Unlike rollback (which
102
+ * restores a whole-product checkpoint) or retryNode (which only accepts FAILED nodes), replay
103
+ * targets a successful-but-wrong task and re-runs forward from it in place.
104
+ */
105
+ replayTask(productId: string, taskId: string): Promise<void>;
70
106
  /** Get product status. */
71
107
  getStatus(productId: string): ProductStatus | null;
108
+ /** Live DAG progress snapshot for a product (for the planner's execution-phase leader). */
109
+ getProgressSnapshot(productId: string): {
110
+ total: number;
111
+ completed: number;
112
+ running: number;
113
+ failed: number;
114
+ } | null;
72
115
  getPersistedStatus(productId: string, cwd?: string): Promise<ProductStatus | null>;
73
116
  /** List all products (in-memory + on-disk). */
74
117
  list(cwd?: string): Promise<ProductSummary[]>;
@@ -0,0 +1,17 @@
1
+ import type { AgentRosterEntry, AgentConfigStoreData } from "../protocol/wire/acp-agent-management.js";
2
+ import { type AcpDetector } from "../runtime/infra/acp-detector.js";
3
+ /** Build the team roster the leader sees during planning: every ready agent with a coarse
4
+ * strengths hint + its backing model. Leader-only soft hints — NOT a capability contract.
5
+ *
6
+ * `allowedAgents` is PRESENCE-based (an explicit `[]` is meaningful, NOT the same as omitted):
7
+ * - `undefined` / omitted → ALL ready agents (backward compatible — WS probes, other callers, old
8
+ * sessions). The allow-set is `null` and the catalog filter applies no constraint.
9
+ * - `[]` (explicit empty array) → ONLY the leader 小智 (qlogicagent): the allow-set is an empty Set, so
10
+ * the catalog filter drops every non-leader entry; the leader is force-included below → roster = just
11
+ * 小智. This is the user deliberately deselecting every worker.
12
+ * - `[ids]` → those ready ids PLUS the leader 小智 (always included). A picked-but-unready id is dropped.
13
+ *
14
+ * The leader `qlogicagent` (小智) is ALWAYS present (universal coordinator / fallback executor) — appended
15
+ * if not already in the roster, so the leader always has ≥1 valid assignee even when the user's picks turn
16
+ * out unready (or when the pool is empty). */
17
+ export declare function buildAgentRoster(detector: AcpDetector, _configStore: AgentConfigStoreData | null, allowedAgents?: string[]): AgentRosterEntry[];