@xzzpig/pi-subagents 0.24.0 → 0.24.2

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 (36) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/bundle/{chunk-UFNSLL5D.js → chunk-224WMDIV.js} +86 -10
  3. package/bundle/{chunk-7K3Z6DM7.js → chunk-4UH4WS4G.js} +4 -4
  4. package/bundle/{chunk-KD2IMFN4.js → chunk-BQ2OAB4Q.js} +1 -1
  5. package/bundle/{chunk-F3NSN7UH.js → chunk-CYY5UMJU.js} +9 -4
  6. package/bundle/{chunk-LPVUHUZ7.js → chunk-EUPJB4S7.js} +1 -1
  7. package/bundle/{chunk-T65XRVVM.js → chunk-FG6SQJAR.js} +2 -2
  8. package/bundle/{chunk-MYCL5QEJ.js → chunk-JEA2ZKUA.js} +2 -2
  9. package/bundle/{chunk-RK2HDPLK.js → chunk-LVWU2HOO.js} +1 -1
  10. package/bundle/{chunk-OTLRAB22.js → chunk-O4D5PBVI.js} +3 -3
  11. package/bundle/{chunk-NCWCVJLT.js → chunk-RU522D5W.js} +4 -4
  12. package/bundle/{chunk-3G4JXNZ4.js → chunk-TMHVDPYW.js} +2 -0
  13. package/bundle/{chunk-NTRJDXBC.js → chunk-X6LOM3Z4.js} +2 -2
  14. package/bundle/{chunk-OFGSZBHP.js → chunk-XWWUDWUW.js} +14 -6
  15. package/bundle/index.js +1 -1
  16. package/docs/goal-auto-continuation-gate.md +26 -0
  17. package/node_modules/@xzzpig/pi-components/CHANGELOG.md +12 -0
  18. package/node_modules/@xzzpig/pi-components/README.md +94 -0
  19. package/node_modules/@xzzpig/pi-components/dist/src/transcript-presenter.d.ts +186 -0
  20. package/node_modules/@xzzpig/pi-components/dist/src/transcript-presenter.js +693 -0
  21. package/node_modules/@xzzpig/pi-components/package.json +5 -1
  22. package/package.json +3 -3
  23. package/src/extension/index.js +12 -0
  24. package/src/goal-auto-continue-gate.d.ts +17 -0
  25. package/src/goal-auto-continue-gate.js +61 -0
  26. package/src/goal-auto-continue-state.d.ts +22 -0
  27. package/src/goal-auto-continue-state.js +20 -0
  28. package/src/runs/background/async-execution.d.ts +3 -1
  29. package/src/runs/background/async-execution.js +4 -0
  30. package/src/runs/background/async-job-tracker.js +5 -0
  31. package/src/runs/background/async-status.d.ts +2 -0
  32. package/src/runs/background/async-status.js +2 -0
  33. package/src/runs/background/notify.d.ts +2 -0
  34. package/src/runs/background/notify.js +5 -0
  35. package/src/runs/foreground/subagent-executor.js +4 -0
  36. package/src/shared/types.d.ts +2 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xzzpig/pi-components",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "private": true,
5
5
  "description": "Reusable transcript components for Pi extensions.",
6
6
  "license": "MIT",
@@ -21,6 +21,10 @@
21
21
  "./transcript": {
22
22
  "types": "./dist/src/transcript.d.ts",
23
23
  "default": "./dist/src/transcript.js"
24
+ },
25
+ "./transcript-presenter": {
26
+ "types": "./dist/src/transcript-presenter.d.ts",
27
+ "default": "./src/transcript-presenter.ts"
24
28
  }
25
29
  },
26
30
  "scripts": {
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@xzzpig/pi-subagents",
4
- "version": "0.24.0",
4
+ "version": "0.24.2",
5
5
  "description": "Pi extension for single-agent delegation and scripted multi-agent workflows",
6
6
  "author": "Nico Bailon",
7
7
  "license": "MIT",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/nicobailon/pi-subagents.git"
10
+ "url": "git+https://github.com/xzzpig/pi-extensions.git"
11
11
  },
12
12
  "homepage": "https://github.com/nicobailon/pi-subagents#readme",
13
13
  "bugs": {
@@ -17,7 +17,7 @@
17
17
  "pi-subagents": "install.mjs"
18
18
  },
19
19
  "dependencies": {
20
- "@xzzpig/pi-components": "0.4.0",
20
+ "@xzzpig/pi-components": "0.5.0",
21
21
  "@js-temporal/polyfill": "0.5.1",
22
22
  "acorn": "8.18.0",
23
23
  "jiti": "2.7.0",
@@ -66,6 +66,7 @@ import { buildActiveRunsSection } from "./active-runs-prompt.js";
66
66
  import { createWaitSubscriptionManager } from "../runs/background/wait-subscriptions.js";
67
67
  import { drainOutstandingWork } from "../runs/background/auto-drain.js";
68
68
  import registerSubagentNotify from "../runs/background/notify.js";
69
+ import { registerGoalAutoContinueGate } from "../goal-auto-continue-gate.js";
69
70
  import { createParentWake } from "../shared/parent-wake.js";
70
71
  import { handleSubagentSteeringNotice } from "./steering-notices.js";
71
72
  import { SUBAGENT_CHILD_ENV, SUBAGENT_PARENT_SESSION_ENV } from "../runs/shared/child-runtime-config.js";
@@ -341,6 +342,7 @@ export default function registerSubagentExtension(pi) {
341
342
  : undefined;
342
343
  let goalTurnId = 0;
343
344
  let releaseHostSessionLiveness = () => { };
345
+ let disposeGoalAutoContinueGate = () => { };
344
346
  const scheduledStoreRoot = config.scheduledRuns?.storeRoot === undefined ? undefined : resolveScheduledStoreRoot(config.scheduledRuns.storeRoot);
345
347
  const scheduledRunManager = createScheduledRunManager({
346
348
  config,
@@ -873,6 +875,7 @@ export default function registerSubagentExtension(pi) {
873
875
  }),
874
876
  pi.events.on(SUBAGENT_CONTROL_EVENT, controlEventHandler),
875
877
  pi.events.on(SUBAGENT_STEERING_NOTICE_EVENT, steeringNoticeHandler),
878
+ () => disposeGoalAutoContinueGate(),
876
879
  herdrStatusBridge.dispose,
877
880
  rpcBridge.dispose,
878
881
  ];
@@ -1234,8 +1237,17 @@ export default function registerSubagentExtension(pi) {
1234
1237
  startSessionMaintenance();
1235
1238
  scheduleModulePreload();
1236
1239
  const recovering = event.reason === "startup" || event.reason === "reload" || event.reason === "resume";
1240
+ disposeGoalAutoContinueGate();
1237
1241
  resetSessionState(ctx, recovering, event.previousSessionFile);
1238
1242
  refreshContextInjectionSnapshot(ctx);
1243
+ disposeGoalAutoContinueGate = registerGoalAutoContinueGate(pi, {
1244
+ state,
1245
+ ownership: resultDeliveryOwnership,
1246
+ notifier: completionNotifier,
1247
+ parentWake,
1248
+ isHeld: parentWake.isHeld,
1249
+ owedResultRunIds,
1250
+ });
1239
1251
  releaseHostSessionLiveness();
1240
1252
  const sessionId = ctx.sessionManager.getSessionId();
1241
1253
  const sessionFile = ctx.sessionManager.getSessionFile();
@@ -0,0 +1,17 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ import type { ResultDeliveryOwnership } from "./runs/background/result-delivery-ownership.ts";
3
+ import type { ParentWake } from "./shared/parent-wake.ts";
4
+ import { type CompletionNotifier } from "./runs/background/notify.ts";
5
+ import type { SubagentState } from "./shared/types.ts";
6
+ export declare const GOAL_AUTO_CONTINUE_GATE_EVENT = "pi-goal:before-auto-continue:v1";
7
+ export declare const GOAL_AUTO_CONTINUE_GATE_VERSION: 1;
8
+ export interface GoalAutoContinueGateDependencies {
9
+ state: SubagentState;
10
+ ownership: Pick<ResultDeliveryOwnership, "owns">;
11
+ notifier: Pick<CompletionNotifier, "hasPendingWake">;
12
+ parentWake: Pick<ParentWake, "isPending">;
13
+ isHeld(): boolean;
14
+ owedResultRunIds: ReadonlySet<string>;
15
+ }
16
+ /** Install one synchronous listener for the current parent runtime; dispose it on session replacement/reload. */
17
+ export declare function registerGoalAutoContinueGate(pi: Pick<ExtensionAPI, "events">, dependencies: GoalAutoContinueGateDependencies): () => void;
@@ -0,0 +1,61 @@
1
+ import { ownsRun } from "./runs/shared/run-ownership.js";
2
+ import { scheduledCompletionTriggersTurn } from "./runs/background/notify.js";
3
+ import { hasGoalAutoContinueWakeWork } from "./goal-auto-continue-state.js";
4
+ export const GOAL_AUTO_CONTINUE_GATE_EVENT = "pi-goal:before-auto-continue:v1";
5
+ export const GOAL_AUTO_CONTINUE_GATE_VERSION = 1;
6
+ function gateRequest(value) {
7
+ if (!value || typeof value !== "object")
8
+ return undefined;
9
+ const candidate = value;
10
+ if (typeof candidate.defer !== "function")
11
+ return undefined;
12
+ return candidate;
13
+ }
14
+ /** Install one synchronous listener for the current parent runtime; dispose it on session replacement/reload. */
15
+ export function registerGoalAutoContinueGate(pi, dependencies) {
16
+ return pi.events.on(GOAL_AUTO_CONTINUE_GATE_EVENT, (value) => {
17
+ const request = gateRequest(value);
18
+ if (!request)
19
+ return;
20
+ try {
21
+ if (request.version !== GOAL_AUTO_CONTINUE_GATE_VERSION || typeof request.sessionId !== "string" || typeof request.goalId !== "string") {
22
+ request.defer({ owner: "pi-subagents", reason: "gate-protocol-invalid" });
23
+ return;
24
+ }
25
+ const { state } = dependencies;
26
+ if (state.supervisorOwnerSessionId !== request.sessionId)
27
+ return;
28
+ const blocked = hasGoalAutoContinueWakeWork(state, request.sessionId, {
29
+ ownsAsyncRun: (job) => typeof job.sessionId === "string" && dependencies.ownership.owns(job.sessionId, job.completionOwnerId),
30
+ ownsForegroundRun: (control) => typeof control.sessionId === "string" && ownsRun(state.currentSessionId, control.sessionId),
31
+ hasOwedResultHandoff: () => {
32
+ if (dependencies.isHeld())
33
+ return false;
34
+ for (const runId of dependencies.owedResultRunIds) {
35
+ const job = state.asyncJobs.get(runId);
36
+ if (!job)
37
+ return true;
38
+ const outcome = job.status === "complete" ? "completed" : job.status;
39
+ if (scheduledCompletionTriggersTurn(job.scheduleOrigin, outcome))
40
+ return true;
41
+ }
42
+ return false;
43
+ },
44
+ hasPendingNativeWake: () => !dependencies.isHeld()
45
+ && (dependencies.notifier.hasPendingWake() || dependencies.parentWake.isPending()),
46
+ });
47
+ if (blocked)
48
+ request.defer({ owner: "pi-subagents", reason: "parent-wake-pending" });
49
+ }
50
+ catch {
51
+ // The host event bus swallows listener errors. Fail this send closed using only bounded local diagnostics.
52
+ try {
53
+ request.defer({ owner: "pi-subagents", reason: "state-unavailable" });
54
+ }
55
+ catch {
56
+ // A malformed or already-closed gate request cannot be recovered by this listener.
57
+ }
58
+ console.error("[pi-subagents] Goal auto-continuation state unavailable; deferring this send attempt.");
59
+ }
60
+ });
61
+ }
@@ -0,0 +1,22 @@
1
+ import type { AsyncJobState, ForegroundRunControl } from "./shared/types.ts";
2
+ export interface GoalAutoContinueStateView {
3
+ supervisorOwnerSessionId?: string | null;
4
+ asyncJobs: ReadonlyMap<string, AsyncJobState>;
5
+ foregroundControls: ReadonlyMap<string, ForegroundRunControl>;
6
+ }
7
+ export interface GoalAutoContinueStateQueries {
8
+ /** Reuses pi-subagents' authoritative completion-owner/session-succession decision. */
9
+ ownsAsyncRun(job: AsyncJobState): boolean;
10
+ /** Reuses the same owning-session decision for live detached foreground controls. */
11
+ ownsForegroundRun(control: ForegroundRunControl): boolean;
12
+ /** Existing result watcher/notifier state; this is not a new completion counter. */
13
+ hasOwedResultHandoff(): boolean;
14
+ /** True only for notifier work with a native parent-turn wake still pending. */
15
+ hasPendingNativeWake(): boolean;
16
+ }
17
+ /**
18
+ * Read-only projection used by pi-goal-x's synchronous final-send gate.
19
+ * It deliberately inspects only existing in-memory ownership and lifecycle state;
20
+ * it performs no filesystem, event-log, transcript, or tool-result lookup.
21
+ */
22
+ export declare function hasGoalAutoContinueWakeWork(state: GoalAutoContinueStateView, requestSessionId: string, queries: GoalAutoContinueStateQueries): boolean;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Read-only projection used by pi-goal-x's synchronous final-send gate.
3
+ * It deliberately inspects only existing in-memory ownership and lifecycle state;
4
+ * it performs no filesystem, event-log, transcript, or tool-result lookup.
5
+ */
6
+ export function hasGoalAutoContinueWakeWork(state, requestSessionId, queries) {
7
+ if (!requestSessionId || state.supervisorOwnerSessionId !== requestSessionId)
8
+ return false;
9
+ for (const job of state.asyncJobs.values()) {
10
+ if ((job.status === "queued" || job.status === "running")
11
+ && job.scheduleOrigin?.quiet !== true
12
+ && queries.ownsAsyncRun(job))
13
+ return true;
14
+ }
15
+ for (const control of state.foregroundControls.values()) {
16
+ if (queries.ownsForegroundRun(control))
17
+ return true;
18
+ }
19
+ return queries.hasOwedResultHandoff() || queries.hasPendingNativeWake();
20
+ }
@@ -12,7 +12,7 @@ import { type AvailableModelInfo, type ModelOrigin, type ParentModel } from "../
12
12
  import { type ModelScopeConfig } from "../shared/model-scope.ts";
13
13
  import { type ThinkingLevel } from "../../shared/thinking-ceiling.ts";
14
14
  import { buildWorkflowGraphSnapshot } from "../shared/workflow-graph.ts";
15
- import { type AcceptanceInput, type AgentContract, type ArtifactConfig, type Details, type IntercomBridgeConfig, type JsonSchemaObject, type MaxOutputConfig, type NestedRouteInfo, type ResolvedControlConfig, type ResolvedToolBudget, type RunFanoutBudgetDescriptor, type ToolBudgetConfig, type SubagentRunMode, type WorkflowLaneMetadata, type UsageBudgetConfig } from "../../shared/types.ts";
15
+ import { type AcceptanceInput, type AgentContract, type ArtifactConfig, type Details, type IntercomBridgeConfig, type JsonSchemaObject, type MaxOutputConfig, type NestedRouteInfo, type ResolvedControlConfig, type ResolvedToolBudget, type RunFanoutBudgetDescriptor, type ScheduleOrigin, type ToolBudgetConfig, type SubagentRunMode, type WorkflowLaneMetadata, type UsageBudgetConfig } from "../../shared/types.ts";
16
16
  import { type ChildRuntimeConfig } from "../shared/child-runtime-config.ts";
17
17
  import type { ImportedAsyncRoot } from "./chain-root-attachment.ts";
18
18
  import type { SessionLeaseRequest } from "../shared/session-lease.ts";
@@ -117,6 +117,7 @@ interface AsyncChainParams {
117
117
  parentWorkflowRunId?: string;
118
118
  workflowKey?: string;
119
119
  lane?: WorkflowLaneMetadata;
120
+ scheduleOrigin?: ScheduleOrigin;
120
121
  activeAsyncCapacity?: ActiveAsyncCapacityHandle;
121
122
  }
122
123
  interface AsyncSingleParams {
@@ -197,6 +198,7 @@ interface AsyncSingleParams {
197
198
  parentWorkflowRunId?: string;
198
199
  workflowKey?: string;
199
200
  lane?: WorkflowLaneMetadata;
201
+ scheduleOrigin?: ScheduleOrigin;
200
202
  workflowAwaitAsync?: boolean;
201
203
  activeAsyncCapacity?: ActiveAsyncCapacityHandle;
202
204
  externalJobFollowUp?: {
@@ -1449,6 +1449,7 @@ export function executeAsyncChain(id, params) {
1449
1449
  ...(initialCompletionOwnerId ? { completionOwnerId: initialCompletionOwnerId } : {}),
1450
1450
  completionOwnerProcess,
1451
1451
  mode: resultMode,
1452
+ ...(params.scheduleOrigin ? { scheduleOrigin: params.scheduleOrigin } : {}),
1452
1453
  state: "running",
1453
1454
  startedAt: initialStatusAt,
1454
1455
  lastUpdate: initialStatusAt,
@@ -1567,6 +1568,7 @@ export function executeAsyncChain(id, params) {
1567
1568
  goal: workflowGoal?.trim() ? PROMPT_REDACTED : undefined,
1568
1569
  chain: eventChain.map((s) => isParallelStep(s) ? `[${s.parallel.map((t) => t.agent).join("+")}]` : isDynamicParallelStep(s) ? `expand:${s.parallel.agent}` : s.agent),
1569
1570
  chainStepCount: eventChain.length,
1571
+ ...(params.scheduleOrigin ? { scheduleOrigin: params.scheduleOrigin } : {}),
1570
1572
  parallelGroups,
1571
1573
  workflowGraph,
1572
1574
  cwd: runnerCwd,
@@ -2102,6 +2104,7 @@ export function executeAsyncSingle(id, params) {
2102
2104
  ...(initialCompletionOwnerId ? { completionOwnerId: initialCompletionOwnerId } : {}),
2103
2105
  completionOwnerProcess,
2104
2106
  mode: "single",
2107
+ ...(params.scheduleOrigin ? { scheduleOrigin: params.scheduleOrigin } : {}),
2105
2108
  ...(params.toolCallId ? { toolCallId: params.toolCallId } : {}),
2106
2109
  state: "running",
2107
2110
  startedAt: initialStatusAt,
@@ -2179,6 +2182,7 @@ export function executeAsyncSingle(id, params) {
2179
2182
  sessionId: ctx.currentSessionId,
2180
2183
  completionOwnerId: ctx.completionOwnerId ?? currentCompletionOwnerId(),
2181
2184
  mode: "single",
2185
+ ...(params.scheduleOrigin ? { scheduleOrigin: params.scheduleOrigin } : {}),
2182
2186
  ...(params.toolCallId ? { toolCallId: params.toolCallId } : {}),
2183
2187
  agent,
2184
2188
  ...(sandbox ? { sandbox } : {}),
@@ -128,6 +128,7 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
128
128
  toolCallId: run.toolCallId,
129
129
  status: run.state,
130
130
  sessionId: run.sessionId,
131
+ completionOwnerId: run.completionOwnerId,
131
132
  activityState: run.activityState,
132
133
  lastActivityAt: run.lastActivityAt,
133
134
  currentTool: run.currentTool,
@@ -137,6 +138,7 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
137
138
  toolCount: run.toolCount,
138
139
  steering: run.steering,
139
140
  mode: run.mode,
141
+ scheduleOrigin: run.scheduleOrigin,
140
142
  context: run.context,
141
143
  cwd: run.cwd,
142
144
  sessionRoot: run.sessionRoot,
@@ -496,6 +498,7 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
496
498
  if (!isTerminalJobStatus(job.status))
497
499
  cancelCleanup(job.asyncId);
498
500
  job.sessionId = status.sessionId ?? job.sessionId;
501
+ job.completionOwnerId = status.completionOwnerId ?? job.completionOwnerId;
499
502
  job.activityState = status.activityState;
500
503
  job.lastActivityAt = status.lastActivityAt ?? job.lastActivityAt;
501
504
  job.currentTool = status.currentTool;
@@ -505,6 +508,7 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
505
508
  job.toolCount = status.toolCount ?? job.toolCount;
506
509
  job.steering = status.steering ?? job.steering;
507
510
  job.mode = status.mode;
511
+ job.scheduleOrigin = status.scheduleOrigin ?? job.scheduleOrigin;
508
512
  job.parentWorkflowRunId = status.parentWorkflowRunId ?? job.parentWorkflowRunId;
509
513
  job.workflowKey = status.workflowKey ?? job.workflowKey;
510
514
  job.lane = status.lane ?? job.lane;
@@ -791,6 +795,7 @@ export function createAsyncJobTracker(pi, state, asyncDirRoot, options = {}) {
791
795
  ...(typeof info.sessionId === "string" ? { sessionId: info.sessionId } : {}),
792
796
  ...(typeof info.completionOwnerId === "string" ? { completionOwnerId: info.completionOwnerId } : {}),
793
797
  mode: info.mode ?? (info.chain ? "chain" : "single"),
798
+ scheduleOrigin: info.scheduleOrigin,
794
799
  description: info.goal ?? info.task,
795
800
  agents,
796
801
  chainStepCount: info.chainStepCount,
@@ -76,6 +76,7 @@ export interface AsyncRunSummary {
76
76
  asyncDir: string;
77
77
  toolCallId?: string;
78
78
  sessionId?: string;
79
+ completionOwnerId?: string;
79
80
  state: "queued" | "running" | "complete" | "failed" | "partial" | "paused" | "stopped" | "rejected";
80
81
  error?: string;
81
82
  activityState?: ActivityState;
@@ -87,6 +88,7 @@ export interface AsyncRunSummary {
87
88
  toolCount?: number;
88
89
  steering?: SteeringStatus;
89
90
  mode: SubagentRunMode;
91
+ scheduleOrigin?: AsyncStatus["scheduleOrigin"];
90
92
  context?: ContextSummary;
91
93
  sandbox?: string;
92
94
  permissionProfile?: string;
@@ -297,6 +297,7 @@ function statusToSummary(asyncDir, status, nestedWarnings = [], nestedRoute) {
297
297
  asyncDir,
298
298
  ...(status.toolCallId ? { toolCallId: status.toolCallId } : {}),
299
299
  ...(status.sessionId ? { sessionId: status.sessionId } : {}),
300
+ ...(status.completionOwnerId ? { completionOwnerId: status.completionOwnerId } : {}),
300
301
  state: status.state,
301
302
  ...(status.error ? { error: status.error } : {}),
302
303
  activityState,
@@ -308,6 +309,7 @@ function statusToSummary(asyncDir, status, nestedWarnings = [], nestedRoute) {
308
309
  toolCount: status.toolCount,
309
310
  steering: status.steering,
310
311
  mode: status.mode,
312
+ ...(status.scheduleOrigin ? { scheduleOrigin: status.scheduleOrigin } : {}),
311
313
  ...(summarizeContextModes(summarizedSteps.map((step) => step.context)) ? { context: summarizeContextModes(summarizedSteps.map((step) => step.context)) } : {}),
312
314
  ...(sandbox ? { sandbox } : {}),
313
315
  ...(permissionProfile ? { permissionProfile } : {}),
@@ -151,6 +151,8 @@ export interface CompletionNotifier {
151
151
  deliver(result: CompletionNotification): Promise<boolean>;
152
152
  /** True while a completion is batched, being sent, or accepted as a wake that Pi has not started yet. */
153
153
  hasPendingDelivery(): boolean;
154
+ /** True only while a completion with a native turn-wake contract is pending or accepted but not started. */
155
+ hasPendingWake(): boolean;
154
156
  /** Releases a completion wake once Pi starts it (native message_start). */
155
157
  messageStarted(message: AgentMessage): void;
156
158
  /** Adopts wakes a reloaded notifier left queued for the same session manager and session UUID. */
@@ -676,6 +676,7 @@ export function buildCompletionDetails(result) {
676
676
  export default function registerSubagentNotify(pi, state, options = {}) {
677
677
  const seen = new Map();
678
678
  const pending = new Map();
679
+ const pendingWakeKeys = new Set();
679
680
  const ttlMs = COMPLETION_SEND_TTL_MS;
680
681
  const now = options.now ?? Date.now;
681
682
  const sendRegistry = options.sendRegistry ?? processCompletionSendRegistry;
@@ -698,6 +699,7 @@ export default function registerSubagentNotify(pi, state, options = {}) {
698
699
  if (reason)
699
700
  traceNotification(reason, item.trace);
700
701
  pending.delete(item.key);
702
+ pendingWakeKeys.delete(item.key);
701
703
  if (accepted)
702
704
  markSeenWithTtl(seen, item.key, now(), ttlMs);
703
705
  item.resolve(accepted);
@@ -789,6 +791,8 @@ export default function registerSubagentNotify(pi, state, options = {}) {
789
791
  triggerTurn: result.triggerTurn !== false && scheduledCompletionTriggersTurn(result.scheduleOrigin, details.status),
790
792
  resolve,
791
793
  };
794
+ if (item.triggerTurn)
795
+ pendingWakeKeys.add(key);
792
796
  if (notificationDebug.enabled)
793
797
  item.trace = traceIdentity(result);
794
798
  if (details.source === "foreground") {
@@ -906,6 +910,7 @@ export default function registerSubagentNotify(pi, state, options = {}) {
906
910
  return {
907
911
  deliver,
908
912
  hasPendingDelivery: () => pending.size > 0 || unstartedWakes.length > 0,
913
+ hasPendingWake: () => !pi.isHeld() && (pendingWakeKeys.size > 0 || unstartedWakes.length > 0),
909
914
  messageStarted(message) {
910
915
  if (message.role !== "custom" || message.customType !== "subagent-notify")
911
916
  return;
@@ -1050,6 +1050,7 @@ function appendStepToAsyncChain(input) {
1050
1050
  pi: input.deps.pi,
1051
1051
  cwd: input.ctx.cwd,
1052
1052
  currentSessionId: resolveCurrentSessionId(input.ctx.sessionManager),
1053
+ completionOwnerId: input.deps.state.completionOwnerId,
1053
1054
  parentSessionId: input.ctx.sessionManager.getSessionId() ?? undefined,
1054
1055
  parentSessionFile: input.ctx.sessionManager.getSessionFile() ?? undefined,
1055
1056
  currentModelProvider: parentModel?.provider,
@@ -3148,6 +3149,7 @@ async function runAsyncPath(data, deps) {
3148
3149
  pi: deps.pi,
3149
3150
  cwd: ctx.cwd,
3150
3151
  currentSessionId: data.parentSessionId,
3152
+ completionOwnerId: deps.state.completionOwnerId,
3151
3153
  parentSessionId: data.parentPiSessionId,
3152
3154
  parentSessionFile: ctx.sessionManager.getSessionFile() ?? undefined,
3153
3155
  currentModelProvider: parentModel?.provider,
@@ -3283,6 +3285,7 @@ async function runAsyncPath(data, deps) {
3283
3285
  parentWorkflowRunId: params.workflowParentRunId,
3284
3286
  workflowKey: params.workflowKey,
3285
3287
  lane: params.lane,
3288
+ scheduleOrigin: params.scheduleOrigin,
3286
3289
  workflowAwaitAsync: params.workflowAwaitAsync,
3287
3290
  }));
3288
3291
  return waitForWorkflowAsyncSingleResult(params, asyncResult, { runId: id, task: params.task ?? "", signal: data.signal, state: deps.state, pi: deps.pi, kill: deps.kill });
@@ -5445,6 +5448,7 @@ export function createSubagentExecutor(deps) {
5445
5448
  sessionId: currentSessionId ?? undefined,
5446
5449
  completionOwnerId,
5447
5450
  mode: "workflow",
5451
+ ...(requestParams.scheduleOrigin ? { scheduleOrigin: requestParams.scheduleOrigin } : {}),
5448
5452
  agent: "workflow",
5449
5453
  goal: derivedObjective.trim() ? PROMPT_REDACTED : undefined,
5450
5454
  ...(timeout !== undefined ? { timeoutMs: timeout, deadlineAt: startedAt + timeout } : {}),
@@ -1645,6 +1645,7 @@ export interface AsyncStartedEvent {
1645
1645
  sessionId?: string;
1646
1646
  completionOwnerId?: string;
1647
1647
  mode?: SubagentRunMode;
1648
+ scheduleOrigin?: ScheduleOrigin;
1648
1649
  agent?: string;
1649
1650
  agents?: string[];
1650
1651
  /** Redacted prompt marker for the first child task; workflow roots may omit this field. */
@@ -2079,6 +2080,7 @@ export interface AsyncJobState {
2079
2080
  toolCount?: number;
2080
2081
  steering?: SteeringStatus;
2081
2082
  mode?: SubagentRunMode;
2083
+ scheduleOrigin?: ScheduleOrigin;
2082
2084
  /** Run-level context summary derived from step contexts. */
2083
2085
  context?: "fresh" | "fork" | "mixed";
2084
2086
  agents?: string[];