@selesai/code 0.2.1 → 0.3.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.
- package/dist/config.d.ts +4 -15
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +5 -45
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +8 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/diagnostics.d.ts +1 -0
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/diagnostics.js.map +1 -1
- package/dist/core/model-registry.d.ts +4 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +101 -51
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/package-manager.d.ts +10 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +93 -8
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/package-manager.test.d.ts +2 -0
- package/dist/core/package-manager.test.d.ts.map +1 -0
- package/dist/core/package-manager.test.js +20 -0
- package/dist/core/package-manager.test.js.map +1 -0
- package/dist/core/resource-loader.d.ts +3 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +10 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/settings-manager.d.ts +1 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/defaults/models.json +64 -113
- package/dist/extensions/caveman/caveman-instructions.cjs +39 -0
- package/dist/extensions/caveman/index.js +116 -0
- package/dist/extensions/caveman/package.json +8 -0
- package/dist/extensions/caveman/test/extension.test.js +185 -0
- package/dist/extensions/caveman/test/helpers.test.js +67 -0
- package/dist/extensions/copy-turn.ts +2 -2
- package/dist/extensions/pi-intercom/broker/broker.ts +2 -3
- package/dist/extensions/pi-intercom/broker/paths.ts +10 -5
- package/dist/extensions/pi-intercom/broker/spawn.ts +2 -3
- package/dist/extensions/pi-intercom/config.ts +2 -2
- package/dist/extensions/pi-intercom/index.ts +2 -2
- package/dist/extensions/pi-intercom/package.json +2 -2
- package/dist/extensions/pi-intercom/ui/compose.ts +3 -3
- package/dist/extensions/pi-intercom/ui/inline-message.ts +3 -3
- package/dist/extensions/pi-intercom/ui/session-list.ts +3 -3
- package/dist/extensions/pi-powerline-footer/bash-mode/editor.ts +2 -2
- package/dist/extensions/pi-powerline-footer/bash-mode/history.ts +2 -1
- package/dist/extensions/pi-powerline-footer/index.ts +40 -47
- package/dist/extensions/pi-powerline-footer/package.json +2 -2
- package/dist/extensions/pi-powerline-footer/tests/bash-mode.test.ts +10 -10
- package/dist/extensions/pi-powerline-footer/tests/jump-shortcuts.test.ts +1 -1
- package/dist/extensions/pi-powerline-footer/tests/working-vibes.test.ts +2 -2
- package/dist/extensions/pi-powerline-footer/theme.ts +6 -6
- package/dist/extensions/pi-powerline-footer/tps.ts +1 -1
- package/dist/extensions/pi-powerline-footer/types.ts +7 -7
- package/dist/extensions/pi-powerline-footer/welcome.ts +23 -16
- package/dist/extensions/pi-powerline-footer/working-vibes.ts +52 -59
- package/dist/extensions/pi-rewind-hook/index.ts +1 -1
- package/dist/extensions/pi-rewind-hook/package.json +1 -1
- package/dist/extensions/pi-subagents/README.md +224 -52
- package/dist/extensions/pi-subagents/agents/architect.md +188 -0
- package/dist/extensions/pi-subagents/agents/builder.md +120 -0
- package/dist/extensions/pi-subagents/agents/commentator.md +131 -0
- package/dist/extensions/pi-subagents/agents/explorer.md +51 -0
- package/dist/extensions/pi-subagents/agents/recapper.md +21 -0
- package/dist/extensions/pi-subagents/install.mjs +93 -0
- package/dist/extensions/pi-subagents/package.json +4 -5
- package/dist/extensions/pi-subagents/prompts/parallel-context-build.md +1 -1
- package/dist/extensions/pi-subagents/prompts/parallel-handoff-plan.md +1 -1
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +76 -13
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +179 -2
- package/dist/extensions/pi-subagents/src/agents/agent-memory.ts +254 -0
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +11 -0
- package/dist/extensions/pi-subagents/src/agents/agents.ts +193 -19
- package/dist/extensions/pi-subagents/src/agents/chain-serializer.ts +27 -2
- package/dist/extensions/pi-subagents/src/extension/config.ts +27 -4
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +1 -7
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +3 -2
- package/dist/extensions/pi-subagents/src/extension/index.ts +73 -71
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +369 -0
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +54 -10
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +200 -0
- package/dist/extensions/pi-subagents/src/intercom/intercom-bridge.ts +21 -253
- package/dist/extensions/pi-subagents/src/intercom/native-supervisor-channel.ts +519 -0
- package/dist/extensions/pi-subagents/src/profiles/profiles.ts +1 -1
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +195 -105
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +88 -2
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +67 -10
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +34 -4
- package/dist/extensions/pi-subagents/src/runs/background/completion-batcher.ts +166 -0
- package/dist/extensions/pi-subagents/src/runs/background/control-channel.ts +156 -1
- package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +515 -0
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +161 -44
- package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +1 -2
- package/dist/extensions/pi-subagents/src/runs/background/run-id-resolver.ts +3 -2
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +167 -6
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +514 -0
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +28 -1
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +873 -204
- package/dist/extensions/pi-subagents/src/runs/background/wait.ts +353 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-execution.ts +123 -27
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +174 -70
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +569 -81
- package/dist/extensions/pi-subagents/src/runs/shared/acceptance.ts +45 -22
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +3 -1
- package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +2 -2
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +172 -21
- package/dist/extensions/pi-subagents/src/runs/shared/model-scope.ts +128 -0
- package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +89 -0
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +50 -1
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +35 -4
- package/dist/extensions/pi-subagents/src/runs/shared/pi-spawn.ts +63 -45
- package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +2 -0
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +125 -5
- package/dist/extensions/pi-subagents/src/runs/shared/tool-budget.ts +74 -0
- package/dist/extensions/pi-subagents/src/runs/shared/turn-budget.ts +52 -0
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +28 -5
- package/dist/extensions/pi-subagents/src/shared/artifacts.ts +16 -1
- package/dist/extensions/pi-subagents/src/shared/atomic-json.ts +15 -2
- package/dist/extensions/pi-subagents/src/shared/child-transcript.ts +212 -0
- package/dist/extensions/pi-subagents/src/shared/fork-context.ts +133 -22
- package/dist/extensions/pi-subagents/src/shared/settings.ts +3 -1
- package/dist/extensions/pi-subagents/src/shared/types.ts +197 -4
- package/dist/extensions/pi-subagents/src/shared/utils.ts +108 -17
- package/dist/extensions/pi-subagents/src/slash/prompt-workflows.ts +330 -0
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +135 -4
- package/dist/extensions/pi-subagents/src/tui/render.ts +32 -12
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +94 -0
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +2772 -0
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +1107 -0
- package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +463 -0
- package/dist/extensions/pi-subagents/test/integration/chain-clarify.test.ts +274 -0
- package/dist/extensions/pi-subagents/test/integration/chain-execution.test.ts +1535 -0
- package/dist/extensions/pi-subagents/test/integration/detect-error.test.ts +242 -0
- package/dist/extensions/pi-subagents/test/integration/doctor-executor.test.ts +128 -0
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +252 -0
- package/dist/extensions/pi-subagents/test/integration/foreground-result-size.test.ts +188 -0
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +1306 -0
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +1033 -0
- package/dist/extensions/pi-subagents/test/integration/parallel-execution.test.ts +397 -0
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +583 -0
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +691 -0
- package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +892 -0
- package/dist/extensions/pi-subagents/test/integration/session-tokens.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +1824 -0
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +1284 -0
- package/dist/extensions/pi-subagents/test/integration/slash-live-state.test.ts +127 -0
- package/dist/extensions/pi-subagents/test/integration/template-resolution.test.ts +299 -0
- package/dist/extensions/pi-subagents/test/integration/top-level-async.test.ts +37 -0
- package/dist/extensions/pi-subagents/test/support/helpers.ts +189 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi-script.mjs +335 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +129 -0
- package/dist/extensions/pi-subagents/test/support/real-session-child-cli.mjs +184 -0
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +285 -0
- package/dist/extensions/pi-subagents/test/support/register-loader.mjs +15 -0
- package/dist/extensions/pi-subagents/test/support/ts-loader.mjs +108 -0
- package/dist/extensions/pi-subagents/test/unit/acceptance.test.ts +421 -0
- package/dist/extensions/pi-subagents/test/unit/agent-disabled.test.ts +213 -0
- package/dist/extensions/pi-subagents/test/unit/agent-eject-disable.test.ts +343 -0
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +1199 -0
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +556 -0
- package/dist/extensions/pi-subagents/test/unit/agent-memory.test.ts +420 -0
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +579 -0
- package/dist/extensions/pi-subagents/test/unit/agent-scope.test.ts +20 -0
- package/dist/extensions/pi-subagents/test/unit/agent-selection.test.ts +88 -0
- package/dist/extensions/pi-subagents/test/unit/artifacts.test.ts +24 -0
- package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +86 -0
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +221 -0
- package/dist/extensions/pi-subagents/test/unit/async-permission-session.test.ts +98 -0
- package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +285 -0
- package/dist/extensions/pi-subagents/test/unit/atomic-json.test.ts +112 -0
- package/dist/extensions/pi-subagents/test/unit/chain-append.test.ts +206 -0
- package/dist/extensions/pi-subagents/test/unit/chain-root-attachment.test.ts +159 -0
- package/dist/extensions/pi-subagents/test/unit/chain-serializer.test.ts +229 -0
- package/dist/extensions/pi-subagents/test/unit/child-transcript.test.ts +225 -0
- package/dist/extensions/pi-subagents/test/unit/close-grace-timer.test.ts +101 -0
- package/dist/extensions/pi-subagents/test/unit/completion-batcher.test.ts +228 -0
- package/dist/extensions/pi-subagents/test/unit/completion-dedupe.test.ts +36 -0
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +152 -0
- package/dist/extensions/pi-subagents/test/unit/config-dir-runtime.test.ts +72 -0
- package/dist/extensions/pi-subagents/test/unit/control-channel.test.ts +327 -0
- package/dist/extensions/pi-subagents/test/unit/control-notices.test.ts +161 -0
- package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +159 -0
- package/dist/extensions/pi-subagents/test/unit/dynamic-fanout.test.ts +217 -0
- package/dist/extensions/pi-subagents/test/unit/extra-agent-dirs.test.ts +88 -0
- package/dist/extensions/pi-subagents/test/unit/file-coalescer.test.ts +68 -0
- package/dist/extensions/pi-subagents/test/unit/foreground-tool-call-compaction.test.ts +78 -0
- package/dist/extensions/pi-subagents/test/unit/fork-context.test.ts +415 -0
- package/dist/extensions/pi-subagents/test/unit/get-final-output.test.ts +126 -0
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +271 -0
- package/dist/extensions/pi-subagents/test/unit/intercom-bridge.test.ts +173 -0
- package/dist/extensions/pi-subagents/test/unit/jsonl-writer.test.ts +119 -0
- package/dist/extensions/pi-subagents/test/unit/live-async-resume.test.ts +170 -0
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +346 -0
- package/dist/extensions/pi-subagents/test/unit/model-info.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/unit/model-scope-settings.test.ts +87 -0
- package/dist/extensions/pi-subagents/test/unit/model-scope.test.ts +145 -0
- package/dist/extensions/pi-subagents/test/unit/native-supervisor-channel.test.ts +162 -0
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +470 -0
- package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +329 -0
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +319 -0
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +70 -0
- package/dist/extensions/pi-subagents/test/unit/parallel-utils.test.ts +247 -0
- package/dist/extensions/pi-subagents/test/unit/path-handling.test.ts +113 -0
- package/dist/extensions/pi-subagents/test/unit/path-resolution.test.ts +94 -0
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +803 -0
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +209 -0
- package/dist/extensions/pi-subagents/test/unit/pi-spawn.test.ts +238 -0
- package/dist/extensions/pi-subagents/test/unit/proactive-skills.test.ts +118 -0
- package/dist/extensions/pi-subagents/test/unit/profiles.test.ts +299 -0
- package/dist/extensions/pi-subagents/test/unit/prompt-template-bridge.test.ts +408 -0
- package/dist/extensions/pi-subagents/test/unit/prompt-workflows.test.ts +134 -0
- package/dist/extensions/pi-subagents/test/unit/recursion-guard.test.ts +257 -0
- package/dist/extensions/pi-subagents/test/unit/render-helpers.test.ts +209 -0
- package/dist/extensions/pi-subagents/test/unit/result-intercom.test.ts +226 -0
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +294 -0
- package/dist/extensions/pi-subagents/test/unit/run-id-resolver.test.ts +147 -0
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +997 -0
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +478 -0
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +562 -0
- package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +213 -0
- package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +438 -0
- package/dist/extensions/pi-subagents/test/unit/slash-bridge.test.ts +54 -0
- package/dist/extensions/pi-subagents/test/unit/slash-chain-groups.test.ts +464 -0
- package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +255 -0
- package/dist/extensions/pi-subagents/test/unit/status-format.test.ts +19 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-control.test.ts +245 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +517 -0
- package/dist/extensions/pi-subagents/test/unit/temp-paths.test.ts +72 -0
- package/dist/extensions/pi-subagents/test/unit/tool-budget.test.ts +52 -0
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +237 -0
- package/dist/extensions/pi-subagents/test/unit/total-cost.test.ts +60 -0
- package/dist/extensions/pi-subagents/test/unit/ts-loader.test.ts +33 -0
- package/dist/extensions/pi-subagents/test/unit/turn-budget.test.ts +202 -0
- package/dist/extensions/pi-subagents/test/unit/types-fork-preamble.test.ts +23 -0
- package/dist/extensions/pi-subagents/test/unit/wait.test.ts +398 -0
- package/dist/extensions/pi-subagents/test/unit/widget-nested-render.test.ts +88 -0
- package/dist/extensions/pi-subagents/test/unit/windows-hide-spawn.test.ts +26 -0
- package/dist/extensions/pi-subagents/test/unit/workflow-graph.test.ts +134 -0
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +479 -0
- package/dist/extensions/pi-web-agent/package.json +2 -2
- package/dist/extensions/pi-web-agent/src/backends/settings-reader.ts +2 -2
- package/dist/extensions/pi-web-agent/src/changelog-notice.ts +5 -2
- package/dist/extensions/pi-web-agent/src/commands/web-agent-config.ts +1 -1
- package/dist/extensions/pi-web-agent/src/extension.ts +1 -1
- package/dist/extensions/pi-web-agent/src/presentation/config-store.ts +6 -4
- package/dist/extensions/question/helpers.ts +3 -3
- package/dist/extensions/question/index.ts +2 -2
- package/dist/extensions/question/navigation.ts +2 -2
- package/dist/extensions/question/package.json +2 -2
- package/dist/extensions/question/question-list.ts +2 -2
- package/dist/extensions/question/tests/question-list.test.ts +2 -2
- package/dist/extensions/question/tui-adapter.ts +2 -2
- package/dist/extensions/question/types.ts +2 -2
- package/dist/extensions/question/ui-protocol.ts +2 -2
- package/dist/extensions/rtk.ts +2 -2
- package/dist/extensions/tokenin-onboarding.ts +2 -2
- package/dist/extensions/undo.ts +1 -1
- package/dist/extensions/web-agent-onboarding.ts +3 -3
- package/dist/extensions/workflow/adapter.ts +16 -8
- package/dist/extensions/workflow/extension.ts +1 -1
- package/dist/extensions/workflow/package.json +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +2 -0
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.js +19 -5
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
- package/dist/skills/caveman/SKILL.md +49 -0
- package/dist/skills/handoff-text/SKILL.md +13 -0
- package/dist/utils/thinking-tags.d.ts +7 -0
- package/dist/utils/thinking-tags.d.ts.map +1 -0
- package/dist/utils/thinking-tags.js +63 -0
- package/dist/utils/thinking-tags.js.map +1 -0
- package/docs/docs.json +4 -0
- package/docs/extensions.md +2 -0
- package/docs/settings.md +15 -0
- package/docs/shared-host-extensions.md +109 -0
- package/package.json +2 -2
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { afterEach, describe, it } from "node:test";
|
|
5
|
+
import type { AsyncJobState, SubagentState } from "../../src/shared/types.ts";
|
|
6
|
+
import {
|
|
7
|
+
buildNestedRouteIndex,
|
|
8
|
+
createNestedRoute,
|
|
9
|
+
hasLiveNestedDescendants,
|
|
10
|
+
parseNestedEventRecords,
|
|
11
|
+
projectNestedEvents,
|
|
12
|
+
resolveNestedParentAddressFromEnv,
|
|
13
|
+
resolveNestedRouteFromEnv,
|
|
14
|
+
updateAsyncJobNestedProjection,
|
|
15
|
+
updateForegroundNestedProjection,
|
|
16
|
+
writeNestedEvent,
|
|
17
|
+
} from "../../src/runs/shared/nested-events.ts";
|
|
18
|
+
import {
|
|
19
|
+
SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV,
|
|
20
|
+
SUBAGENT_PARENT_CHILD_INDEX_ENV,
|
|
21
|
+
SUBAGENT_PARENT_CONTROL_INBOX_ENV,
|
|
22
|
+
SUBAGENT_PARENT_DEPTH_ENV,
|
|
23
|
+
SUBAGENT_PARENT_EVENT_SINK_ENV,
|
|
24
|
+
SUBAGENT_PARENT_PATH_ENV,
|
|
25
|
+
SUBAGENT_PARENT_ROOT_RUN_ID_ENV,
|
|
26
|
+
SUBAGENT_PARENT_RUN_ID_ENV,
|
|
27
|
+
} from "../../src/runs/shared/pi-args.ts";
|
|
28
|
+
|
|
29
|
+
const routes: Array<{ eventSink: string }> = [];
|
|
30
|
+
const savedEnv = {
|
|
31
|
+
[SUBAGENT_PARENT_EVENT_SINK_ENV]: process.env[SUBAGENT_PARENT_EVENT_SINK_ENV],
|
|
32
|
+
[SUBAGENT_PARENT_CONTROL_INBOX_ENV]: process.env[SUBAGENT_PARENT_CONTROL_INBOX_ENV],
|
|
33
|
+
[SUBAGENT_PARENT_ROOT_RUN_ID_ENV]: process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV],
|
|
34
|
+
[SUBAGENT_PARENT_RUN_ID_ENV]: process.env[SUBAGENT_PARENT_RUN_ID_ENV],
|
|
35
|
+
[SUBAGENT_PARENT_CHILD_INDEX_ENV]: process.env[SUBAGENT_PARENT_CHILD_INDEX_ENV],
|
|
36
|
+
[SUBAGENT_PARENT_DEPTH_ENV]: process.env[SUBAGENT_PARENT_DEPTH_ENV],
|
|
37
|
+
[SUBAGENT_PARENT_PATH_ENV]: process.env[SUBAGENT_PARENT_PATH_ENV],
|
|
38
|
+
[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV]: process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
for (const route of routes.splice(0)) {
|
|
43
|
+
fs.rmSync(path.dirname(route.eventSink), { recursive: true, force: true });
|
|
44
|
+
}
|
|
45
|
+
for (const [key, value] of Object.entries(savedEnv)) {
|
|
46
|
+
if (value === undefined) delete process.env[key];
|
|
47
|
+
else process.env[key] = value;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
function trackRoute(rootRunId = "root-run") {
|
|
52
|
+
const route = createNestedRoute(rootRunId);
|
|
53
|
+
routes.push(route);
|
|
54
|
+
return route;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function child(id: string, state: "queued" | "running" | "complete" | "failed" | "paused", ts: number, parentRunId = "root-run") {
|
|
58
|
+
return {
|
|
59
|
+
id,
|
|
60
|
+
parentRunId,
|
|
61
|
+
parentStepIndex: 1,
|
|
62
|
+
depth: 1,
|
|
63
|
+
path: [{ runId: parentRunId, stepIndex: 1 }],
|
|
64
|
+
mode: "single" as const,
|
|
65
|
+
state,
|
|
66
|
+
agent: "reviewer",
|
|
67
|
+
agents: ["reviewer"],
|
|
68
|
+
startedAt: 10,
|
|
69
|
+
lastUpdate: ts,
|
|
70
|
+
steps: [{ agent: "leaf", status: state === "running" ? "running" as const : "complete" as const }],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
describe("nested route index", () => {
|
|
75
|
+
it("indexes routes by root run id in a single directory scan", () => {
|
|
76
|
+
const routeA = trackRoute("index-root-a");
|
|
77
|
+
const routeB = trackRoute("index-root-b");
|
|
78
|
+
|
|
79
|
+
const index = buildNestedRouteIndex();
|
|
80
|
+
|
|
81
|
+
assert.equal(index.get("index-root-a")?.capabilityToken, routeA.capabilityToken);
|
|
82
|
+
assert.equal(index.get("index-root-b")?.capabilityToken, routeB.capabilityToken);
|
|
83
|
+
assert.equal(index.get("missing-root"), undefined);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("keeps at most one route when a root run id has duplicate route dirs", () => {
|
|
87
|
+
const first = trackRoute("dup-root");
|
|
88
|
+
const second = trackRoute("dup-root");
|
|
89
|
+
|
|
90
|
+
const index = buildNestedRouteIndex();
|
|
91
|
+
|
|
92
|
+
// readdir order is not guaranteed, so the contract is deduplication: exactly
|
|
93
|
+
// one route is indexed per root run id, not a specific winner.
|
|
94
|
+
const indexed = index.get("dup-root");
|
|
95
|
+
assert.ok(indexed, "expected one route for dup-root");
|
|
96
|
+
const tokens = new Set([first.capabilityToken, second.capabilityToken]);
|
|
97
|
+
assert.ok(tokens.has(indexed.capabilityToken), "indexed route must be one of the two created routes");
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("nested event route validation", () => {
|
|
102
|
+
it("resolves nested parent addresses with full inherited path", () => {
|
|
103
|
+
process.env[SUBAGENT_PARENT_RUN_ID_ENV] = "nested-parent";
|
|
104
|
+
process.env[SUBAGENT_PARENT_CHILD_INDEX_ENV] = "2";
|
|
105
|
+
process.env[SUBAGENT_PARENT_DEPTH_ENV] = "3";
|
|
106
|
+
process.env[SUBAGENT_PARENT_PATH_ENV] = JSON.stringify([
|
|
107
|
+
{ runId: "root-run", stepIndex: 0, agent: "root-agent" },
|
|
108
|
+
{ runId: "../unsafe", stepIndex: 1, agent: "bad" },
|
|
109
|
+
{ runId: "nested-parent", stepIndex: 2, agent: "nested-agent" },
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
assert.deepEqual(resolveNestedParentAddressFromEnv(), {
|
|
113
|
+
parentRunId: "nested-parent",
|
|
114
|
+
parentStepIndex: 2,
|
|
115
|
+
depth: 3,
|
|
116
|
+
path: [
|
|
117
|
+
{ runId: "root-run", stepIndex: 0, agent: "root-agent" },
|
|
118
|
+
{ runId: "nested-parent", stepIndex: 2, agent: "nested-agent" },
|
|
119
|
+
],
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("ignores unsafe nested parent ids from env", () => {
|
|
124
|
+
process.env[SUBAGENT_PARENT_RUN_ID_ENV] = "../unsafe";
|
|
125
|
+
process.env[SUBAGENT_PARENT_CHILD_INDEX_ENV] = "2";
|
|
126
|
+
|
|
127
|
+
assert.equal(resolveNestedParentAddressFromEnv(), undefined);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("resolves only matching contained routes from env", () => {
|
|
131
|
+
const route = trackRoute();
|
|
132
|
+
process.env[SUBAGENT_PARENT_EVENT_SINK_ENV] = route.eventSink;
|
|
133
|
+
process.env[SUBAGENT_PARENT_CONTROL_INBOX_ENV] = route.controlInbox;
|
|
134
|
+
process.env[SUBAGENT_PARENT_ROOT_RUN_ID_ENV] = route.rootRunId;
|
|
135
|
+
process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV] = route.capabilityToken;
|
|
136
|
+
|
|
137
|
+
assert.deepEqual(resolveNestedRouteFromEnv(), route);
|
|
138
|
+
|
|
139
|
+
process.env[SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV] = "wrong-token";
|
|
140
|
+
assert.throws(() => resolveNestedRouteFromEnv(), /capability token/);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe("nested event parsing and projection", () => {
|
|
145
|
+
it("projects started, updated, and completed records into async and foreground parent state", () => {
|
|
146
|
+
const route = trackRoute();
|
|
147
|
+
writeNestedEvent(route, {
|
|
148
|
+
type: "subagent.nested.started",
|
|
149
|
+
ts: 100,
|
|
150
|
+
parentRunId: "root-run",
|
|
151
|
+
parentStepIndex: 1,
|
|
152
|
+
child: child("nested-a", "running", 100),
|
|
153
|
+
});
|
|
154
|
+
writeNestedEvent(route, {
|
|
155
|
+
type: "subagent.nested.updated",
|
|
156
|
+
ts: 200,
|
|
157
|
+
parentRunId: "root-run",
|
|
158
|
+
parentStepIndex: 1,
|
|
159
|
+
child: { ...child("nested-a", "running", 200), currentTool: "read" },
|
|
160
|
+
});
|
|
161
|
+
writeNestedEvent(route, {
|
|
162
|
+
type: "subagent.nested.completed",
|
|
163
|
+
ts: 300,
|
|
164
|
+
parentRunId: "root-run",
|
|
165
|
+
parentStepIndex: 1,
|
|
166
|
+
child: child("nested-a", "complete", 300),
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const registry = projectNestedEvents(route);
|
|
170
|
+
assert.equal(registry.children.length, 1);
|
|
171
|
+
assert.equal(registry.children[0]?.id, "nested-a");
|
|
172
|
+
assert.equal(registry.children[0]?.state, "complete");
|
|
173
|
+
assert.equal(registry.children[0]?.steps?.[0]?.agent, "leaf");
|
|
174
|
+
|
|
175
|
+
const job: AsyncJobState = {
|
|
176
|
+
asyncId: "root-run",
|
|
177
|
+
asyncDir: "/tmp/root-run",
|
|
178
|
+
status: "running",
|
|
179
|
+
nestedRoute: route,
|
|
180
|
+
steps: [
|
|
181
|
+
{ agent: "owner-0", status: "running", index: 0 },
|
|
182
|
+
{ agent: "owner-1", status: "running", index: 1 },
|
|
183
|
+
],
|
|
184
|
+
};
|
|
185
|
+
updateAsyncJobNestedProjection(job);
|
|
186
|
+
assert.equal(job.nestedChildren?.[0]?.id, "nested-a");
|
|
187
|
+
assert.equal(job.steps?.[1]?.children?.[0]?.id, "nested-a");
|
|
188
|
+
|
|
189
|
+
const control: SubagentState["foregroundControls"] extends Map<string, infer T> ? T : never = {
|
|
190
|
+
runId: "root-run",
|
|
191
|
+
mode: "single",
|
|
192
|
+
startedAt: 1,
|
|
193
|
+
updatedAt: 1,
|
|
194
|
+
nestedRoute: route,
|
|
195
|
+
};
|
|
196
|
+
updateForegroundNestedProjection(control);
|
|
197
|
+
assert.equal(control.nestedChildren?.[0]?.id, "nested-a");
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("attaches root children to visible step slices by original step index", () => {
|
|
201
|
+
const route = trackRoute();
|
|
202
|
+
writeNestedEvent(route, {
|
|
203
|
+
type: "subagent.nested.updated",
|
|
204
|
+
ts: 100,
|
|
205
|
+
parentRunId: "root-run",
|
|
206
|
+
parentStepIndex: 3,
|
|
207
|
+
child: { ...child("nested-visible", "running", 100), parentStepIndex: 3, path: [{ runId: "root-run", stepIndex: 3 }] },
|
|
208
|
+
});
|
|
209
|
+
const job: AsyncJobState = {
|
|
210
|
+
asyncId: "root-run",
|
|
211
|
+
asyncDir: "/tmp/root-run",
|
|
212
|
+
status: "running",
|
|
213
|
+
nestedRoute: route,
|
|
214
|
+
steps: [
|
|
215
|
+
{ agent: "owner-2", status: "running", index: 2 },
|
|
216
|
+
{ agent: "owner-3", status: "running", index: 3 },
|
|
217
|
+
],
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
updateAsyncJobNestedProjection(job);
|
|
221
|
+
|
|
222
|
+
assert.equal(job.steps?.[0]?.children, undefined);
|
|
223
|
+
assert.equal(job.steps?.[1]?.children?.[0]?.id, "nested-visible");
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("ignores corrupt, partial, wrong-token, duplicate, and stale records while preserving terminal state", () => {
|
|
227
|
+
const route = trackRoute();
|
|
228
|
+
fs.writeFileSync(path.join(route.eventSink, "0000000000001-corrupt.json"), "{not json", "utf-8");
|
|
229
|
+
fs.writeFileSync(
|
|
230
|
+
path.join(route.eventSink, "0000000000002-partial.jsonl"),
|
|
231
|
+
`${JSON.stringify({
|
|
232
|
+
type: "subagent.nested.started",
|
|
233
|
+
ts: 50,
|
|
234
|
+
rootRunId: route.rootRunId,
|
|
235
|
+
parentRunId: "root-run",
|
|
236
|
+
parentStepIndex: 1,
|
|
237
|
+
capabilityToken: route.capabilityToken,
|
|
238
|
+
child: child("partial-good", "running", 50),
|
|
239
|
+
})}\n{"type":"subagent.nested.started"`,
|
|
240
|
+
"utf-8",
|
|
241
|
+
);
|
|
242
|
+
writeNestedEvent(route, {
|
|
243
|
+
type: "subagent.nested.completed",
|
|
244
|
+
ts: 300,
|
|
245
|
+
parentRunId: "root-run",
|
|
246
|
+
parentStepIndex: 1,
|
|
247
|
+
child: child("nested-terminal", "complete", 300),
|
|
248
|
+
});
|
|
249
|
+
fs.writeFileSync(path.join(route.eventSink, "0000000000400-stale.json"), `${JSON.stringify({
|
|
250
|
+
type: "subagent.nested.updated",
|
|
251
|
+
ts: 400,
|
|
252
|
+
rootRunId: route.rootRunId,
|
|
253
|
+
parentRunId: "root-run",
|
|
254
|
+
parentStepIndex: 1,
|
|
255
|
+
capabilityToken: route.capabilityToken,
|
|
256
|
+
child: child("nested-terminal", "running", 100),
|
|
257
|
+
})}\n`, "utf-8");
|
|
258
|
+
fs.writeFileSync(path.join(route.eventSink, "0000000000500-wrong-token.json"), `${JSON.stringify({
|
|
259
|
+
type: "subagent.nested.started",
|
|
260
|
+
ts: 500,
|
|
261
|
+
rootRunId: route.rootRunId,
|
|
262
|
+
parentRunId: "root-run",
|
|
263
|
+
parentStepIndex: 1,
|
|
264
|
+
capabilityToken: "wrong",
|
|
265
|
+
child: child("wrong-token", "running", 500),
|
|
266
|
+
})}\n`, "utf-8");
|
|
267
|
+
|
|
268
|
+
const registry = projectNestedEvents(route);
|
|
269
|
+
assert.equal(registry.children.find((item) => item.id === "partial-good")?.state, "running");
|
|
270
|
+
assert.equal(registry.children.find((item) => item.id === "nested-terminal")?.state, "complete");
|
|
271
|
+
assert.equal(registry.children.some((item) => item.id === "wrong-token"), false);
|
|
272
|
+
assert.equal(hasLiveNestedDescendants(registry.children), true);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("detects live descendants attached to terminal step children", () => {
|
|
276
|
+
assert.equal(hasLiveNestedDescendants([{
|
|
277
|
+
...child("terminal-parent", "complete", 300),
|
|
278
|
+
steps: [{
|
|
279
|
+
agent: "owner-step",
|
|
280
|
+
status: "complete",
|
|
281
|
+
children: [{
|
|
282
|
+
...child("running-step-child", "running", 310, "terminal-parent"),
|
|
283
|
+
parentStepIndex: 0,
|
|
284
|
+
path: [{ runId: "terminal-parent", stepIndex: 0 }],
|
|
285
|
+
}],
|
|
286
|
+
}],
|
|
287
|
+
}]), true);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("accepts only complete numeric token usage at the nested event boundary", () => {
|
|
291
|
+
const route = trackRoute();
|
|
292
|
+
writeNestedEvent(route, {
|
|
293
|
+
type: "subagent.nested.updated",
|
|
294
|
+
ts: 100,
|
|
295
|
+
parentRunId: "root-run",
|
|
296
|
+
parentStepIndex: 1,
|
|
297
|
+
child: { ...child("nested-valid-tokens", "running", 100), totalTokens: { input: 10, output: 15, total: 25 } },
|
|
298
|
+
});
|
|
299
|
+
fs.writeFileSync(path.join(route.eventSink, "0000000000200-invalid-tokens.json"), `${JSON.stringify({
|
|
300
|
+
type: "subagent.nested.updated",
|
|
301
|
+
ts: 200,
|
|
302
|
+
rootRunId: route.rootRunId,
|
|
303
|
+
parentRunId: "root-run",
|
|
304
|
+
parentStepIndex: 1,
|
|
305
|
+
capabilityToken: route.capabilityToken,
|
|
306
|
+
child: { ...child("nested-invalid-tokens", "running", 200), totalTokens: { input: 1, output: "bad", total: 1 } },
|
|
307
|
+
})}\n`, "utf-8");
|
|
308
|
+
|
|
309
|
+
const registry = projectNestedEvents(route);
|
|
310
|
+
|
|
311
|
+
assert.deepEqual(registry.children.find((item) => item.id === "nested-valid-tokens")?.totalTokens, { input: 10, output: 15, total: 25 });
|
|
312
|
+
assert.equal(registry.children.find((item) => item.id === "nested-invalid-tokens")?.totalTokens, undefined);
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
it("parses only complete jsonl records", () => {
|
|
316
|
+
const route = trackRoute();
|
|
317
|
+
const records = parseNestedEventRecords(`${JSON.stringify({
|
|
318
|
+
type: "subagent.nested.started",
|
|
319
|
+
ts: 100,
|
|
320
|
+
rootRunId: route.rootRunId,
|
|
321
|
+
parentRunId: "root-run",
|
|
322
|
+
parentStepIndex: 1,
|
|
323
|
+
capabilityToken: route.capabilityToken,
|
|
324
|
+
child: child("jsonl-good", "running", 100),
|
|
325
|
+
})}\n{"type":"subagent.nested.started"`, route);
|
|
326
|
+
assert.equal(records.length, 1);
|
|
327
|
+
assert.equal(records[0]?.child.id, "jsonl-good");
|
|
328
|
+
});
|
|
329
|
+
});
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import { describe, it } from "node:test";
|
|
4
|
+
import registerSubagentNotify, {
|
|
5
|
+
buildCompletionDetails,
|
|
6
|
+
formatGroupedCompletion,
|
|
7
|
+
formatSingleCompletion,
|
|
8
|
+
type RegisterSubagentNotifyOptions,
|
|
9
|
+
type SubagentNotifyDetails,
|
|
10
|
+
} from "../../src/runs/background/notify.ts";
|
|
11
|
+
import { SUBAGENT_ASYNC_COMPLETE_EVENT } from "../../src/shared/types.ts";
|
|
12
|
+
|
|
13
|
+
function createPi(currentSessionId = "session-1", registerOptions: RegisterSubagentNotifyOptions = {}) {
|
|
14
|
+
const events = new EventEmitter();
|
|
15
|
+
const sent: Array<{ message: unknown; options: unknown }> = [];
|
|
16
|
+
const pi = {
|
|
17
|
+
events,
|
|
18
|
+
sendMessage(message: unknown, options: unknown) {
|
|
19
|
+
sent.push({ message, options });
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Formatting-focused tests run with batching disabled so single completions
|
|
24
|
+
// emit synchronously. Batching behavior is covered by the dedicated suite below.
|
|
25
|
+
registerSubagentNotify(pi as never, { currentSessionId }, { batchConfig: { enabled: false }, ...registerOptions });
|
|
26
|
+
|
|
27
|
+
return { events, sent };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function createBatchingPi(clock: ReturnType<typeof createFakeClock>, currentSessionId = "session-a") {
|
|
31
|
+
const events = new EventEmitter();
|
|
32
|
+
const sent: Array<{ message: unknown; options: unknown }> = [];
|
|
33
|
+
const pi = {
|
|
34
|
+
events,
|
|
35
|
+
sendMessage(message: unknown, options: unknown) {
|
|
36
|
+
sent.push({ message, options });
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
registerSubagentNotify(pi as never, { currentSessionId }, {
|
|
40
|
+
batchConfig: { enabled: true, debounceMs: 150, maxWaitMs: 1000, stragglerDebounceMs: 75, stragglerMaxWaitMs: 400, stragglerWindowMs: 2000 },
|
|
41
|
+
timers: clock.api,
|
|
42
|
+
now: clock.now,
|
|
43
|
+
});
|
|
44
|
+
return { events, sent };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface FakeJob {
|
|
48
|
+
id: number;
|
|
49
|
+
fireAt: number;
|
|
50
|
+
handler: () => void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function createFakeClock() {
|
|
54
|
+
let now = 0;
|
|
55
|
+
let nextId = 1;
|
|
56
|
+
const jobs = new Map<number, FakeJob>();
|
|
57
|
+
const api = {
|
|
58
|
+
setTimeout(handler: () => void, delayMs: number): unknown {
|
|
59
|
+
const id = nextId++;
|
|
60
|
+
jobs.set(id, { id, fireAt: now + delayMs, handler });
|
|
61
|
+
return id;
|
|
62
|
+
},
|
|
63
|
+
clearTimeout(handle: unknown): void {
|
|
64
|
+
if (typeof handle === "number") jobs.delete(handle);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
api,
|
|
69
|
+
now: () => now,
|
|
70
|
+
advance(ms: number): void {
|
|
71
|
+
now += ms;
|
|
72
|
+
const due = [...jobs.values()].filter((job) => job.fireAt <= now).sort((a, b) => a.fireAt - b.fireAt);
|
|
73
|
+
for (const job of due) {
|
|
74
|
+
if (!jobs.has(job.id)) continue;
|
|
75
|
+
jobs.delete(job.id);
|
|
76
|
+
job.handler();
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function completionResult(overrides: Record<string, unknown> = {}) {
|
|
83
|
+
return {
|
|
84
|
+
id: `notify-${Math.random().toString(36).slice(2)}`,
|
|
85
|
+
agent: "worker",
|
|
86
|
+
success: true,
|
|
87
|
+
summary: "Done",
|
|
88
|
+
exitCode: 0,
|
|
89
|
+
timestamp: 123,
|
|
90
|
+
sessionId: "session-a",
|
|
91
|
+
...overrides,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
describe("registerSubagentNotify", () => {
|
|
96
|
+
it("uses a fallback summary when a background completion is empty", () => {
|
|
97
|
+
const { events, sent } = createPi();
|
|
98
|
+
|
|
99
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, {
|
|
100
|
+
id: "notify-empty-1",
|
|
101
|
+
agent: "worker",
|
|
102
|
+
success: true,
|
|
103
|
+
summary: "",
|
|
104
|
+
exitCode: 0,
|
|
105
|
+
timestamp: 123,
|
|
106
|
+
sessionId: "session-1",
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
assert.equal(sent.length, 1);
|
|
110
|
+
assert.deepEqual(sent[0], {
|
|
111
|
+
message: {
|
|
112
|
+
customType: "subagent-notify",
|
|
113
|
+
content: "Background task completed: **worker**\n\n(no output)",
|
|
114
|
+
display: true,
|
|
115
|
+
},
|
|
116
|
+
options: { triggerTurn: true },
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("preserves non-empty completion summaries", () => {
|
|
121
|
+
const { events, sent } = createPi();
|
|
122
|
+
const summary = " Done streaming\nAll clear ";
|
|
123
|
+
|
|
124
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, {
|
|
125
|
+
id: "notify-summary-1",
|
|
126
|
+
agent: "worker",
|
|
127
|
+
success: true,
|
|
128
|
+
summary,
|
|
129
|
+
exitCode: 0,
|
|
130
|
+
timestamp: 456,
|
|
131
|
+
taskIndex: 1,
|
|
132
|
+
totalTasks: 3,
|
|
133
|
+
sessionId: "session-1",
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
assert.equal(sent.length, 1);
|
|
137
|
+
assert.deepEqual(sent[0], {
|
|
138
|
+
message: {
|
|
139
|
+
customType: "subagent-notify",
|
|
140
|
+
content: `Background task completed: **worker** (2/3)\n\n${summary}`,
|
|
141
|
+
display: true,
|
|
142
|
+
},
|
|
143
|
+
options: { triggerTurn: true },
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("preserves session paths in notification content", () => {
|
|
148
|
+
const { events, sent } = createPi();
|
|
149
|
+
|
|
150
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, {
|
|
151
|
+
id: "notify-path-1",
|
|
152
|
+
agent: "worker",
|
|
153
|
+
success: true,
|
|
154
|
+
summary: "Done",
|
|
155
|
+
exitCode: 0,
|
|
156
|
+
timestamp: 456,
|
|
157
|
+
sessionFile: "/tmp/session.jsonl",
|
|
158
|
+
sessionId: "session-1",
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
assert.deepEqual(sent, [{
|
|
162
|
+
message: {
|
|
163
|
+
customType: "subagent-notify",
|
|
164
|
+
content: "Background task completed: **worker**\n\nDone\n\nSession file: /tmp/session.jsonl",
|
|
165
|
+
display: true,
|
|
166
|
+
},
|
|
167
|
+
options: { triggerTurn: true },
|
|
168
|
+
}]);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("labels paused completions as paused even without an exit code", () => {
|
|
172
|
+
const { events, sent } = createPi();
|
|
173
|
+
|
|
174
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, {
|
|
175
|
+
id: "notify-paused-1",
|
|
176
|
+
agent: "worker",
|
|
177
|
+
success: false,
|
|
178
|
+
state: "paused",
|
|
179
|
+
summary: "Paused after interrupt. Waiting for explicit next action.",
|
|
180
|
+
timestamp: 789,
|
|
181
|
+
sessionId: "session-1",
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
assert.equal(sent.length, 1);
|
|
185
|
+
assert.deepEqual(sent[0], {
|
|
186
|
+
message: {
|
|
187
|
+
customType: "subagent-notify",
|
|
188
|
+
content: "Background task paused: **worker**\n\nPaused after interrupt. Waiting for explicit next action.",
|
|
189
|
+
display: true,
|
|
190
|
+
},
|
|
191
|
+
options: { triggerTurn: true },
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("ignores completions for other or missing session ids", () => {
|
|
196
|
+
const { events, sent } = createPi("session-owner");
|
|
197
|
+
|
|
198
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, {
|
|
199
|
+
id: "notify-other-session",
|
|
200
|
+
agent: "worker",
|
|
201
|
+
success: true,
|
|
202
|
+
summary: "Other done",
|
|
203
|
+
timestamp: 100,
|
|
204
|
+
sessionId: "session-other",
|
|
205
|
+
});
|
|
206
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, {
|
|
207
|
+
id: "notify-sessionless",
|
|
208
|
+
agent: "worker",
|
|
209
|
+
success: true,
|
|
210
|
+
summary: "Legacy cwd-scoped done",
|
|
211
|
+
timestamp: 101,
|
|
212
|
+
cwd: "/repo",
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
assert.deepEqual(sent, []);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("emits failed completions immediately even while successes are held", () => {
|
|
219
|
+
const clock = createFakeClock();
|
|
220
|
+
const { events, sent } = createBatchingPi(clock);
|
|
221
|
+
|
|
222
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, completionResult({ id: "ok-1", agent: "ok-1", summary: "ok-1 done" }));
|
|
223
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, completionResult({ id: "fail-1", agent: "fail-1", success: false, summary: "boom", exitCode: 1 }));
|
|
224
|
+
|
|
225
|
+
// The failure must arrive immediately, and the held success must be
|
|
226
|
+
// flushed ahead of it rather than waiting on the debounce timer.
|
|
227
|
+
assert.equal(sent.length, 2);
|
|
228
|
+
assert.match((sent[0]!.message as { content: string }).content, /Background task completed: \*\*ok-1\*\*/);
|
|
229
|
+
assert.match((sent[1]!.message as { content: string }).content, /Background task failed: \*\*fail-1\*\*/);
|
|
230
|
+
|
|
231
|
+
// No deferred emission should arrive later.
|
|
232
|
+
clock.advance(1000);
|
|
233
|
+
assert.equal(sent.length, 2);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("groups sibling successes into a single notification after the debounce window", () => {
|
|
237
|
+
const clock = createFakeClock();
|
|
238
|
+
const { events, sent } = createBatchingPi(clock);
|
|
239
|
+
|
|
240
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, completionResult({ id: "g-1", agent: "alpha", summary: "alpha done", sessionId: "session-a" }));
|
|
241
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, completionResult({ id: "g-2", agent: "beta", summary: "beta done", sessionId: "session-a" }));
|
|
242
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, completionResult({ id: "g-3", agent: "gamma", summary: "gamma done", sessionId: "session-a" }));
|
|
243
|
+
assert.equal(sent.length, 0);
|
|
244
|
+
|
|
245
|
+
clock.advance(150);
|
|
246
|
+
assert.equal(sent.length, 1);
|
|
247
|
+
const content = (sent[0]!.message as { content: string }).content;
|
|
248
|
+
assert.match(content, /^Background tasks completed \(3\): \*\*alpha\*\*, \*\*beta\*\*, \*\*gamma\*\*/);
|
|
249
|
+
assert.match(content, /1\. alpha\nalpha done/);
|
|
250
|
+
assert.match(content, /3\. gamma\ngamma done/);
|
|
251
|
+
assert.deepEqual(sent[0]!.options, { triggerTurn: true });
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("ignores successes from other sessions instead of grouping them", () => {
|
|
255
|
+
const clock = createFakeClock();
|
|
256
|
+
const { events, sent } = createBatchingPi(clock, "session-a");
|
|
257
|
+
|
|
258
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, completionResult({ id: "s-1", agent: "alpha", summary: "alpha done", sessionId: "session-a" }));
|
|
259
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, completionResult({ id: "s-2", agent: "beta", summary: "beta done", sessionId: "session-b" }));
|
|
260
|
+
clock.advance(150);
|
|
261
|
+
|
|
262
|
+
assert.equal(sent.length, 1);
|
|
263
|
+
assert.match((sent[0]!.message as { content: string }).content, /^Background task completed: \*\*alpha\*\*/);
|
|
264
|
+
assert.doesNotMatch((sent[0]!.message as { content: string }).content, /beta done/);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("does not let another session failure flush held successes", () => {
|
|
268
|
+
const clock = createFakeClock();
|
|
269
|
+
const { events, sent } = createBatchingPi(clock, "session-a");
|
|
270
|
+
|
|
271
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, completionResult({ id: "held-a-1", agent: "alpha", summary: "alpha done", sessionId: "session-a" }));
|
|
272
|
+
events.emit(SUBAGENT_ASYNC_COMPLETE_EVENT, completionResult({ id: "fail-b-1", agent: "beta", success: false, summary: "boom", exitCode: 1, sessionId: "session-b" }));
|
|
273
|
+
assert.equal(sent.length, 0);
|
|
274
|
+
|
|
275
|
+
clock.advance(150);
|
|
276
|
+
assert.equal(sent.length, 1);
|
|
277
|
+
assert.match((sent[0]!.message as { content: string }).content, /^Background task completed: \*\*alpha\*\*/);
|
|
278
|
+
assert.doesNotMatch((sent[0]!.message as { content: string }).content, /boom/);
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe("completion formatting helpers", () => {
|
|
283
|
+
it("formatSingleCompletion mirrors the in-handler single message shape", () => {
|
|
284
|
+
const content = formatSingleCompletion({
|
|
285
|
+
agent: "worker",
|
|
286
|
+
status: "completed",
|
|
287
|
+
taskInfo: " (2/3)",
|
|
288
|
+
resultPreview: "Done",
|
|
289
|
+
sessionLabel: "Session file",
|
|
290
|
+
sessionValue: "/tmp/session.jsonl",
|
|
291
|
+
});
|
|
292
|
+
assert.equal(content, "Background task completed: **worker** (2/3)\n\nDone\n\nSession file: /tmp/session.jsonl");
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("formatGroupedCompletion lists each agent with its summary and session", () => {
|
|
296
|
+
const content = formatGroupedCompletion([
|
|
297
|
+
{ agent: "alpha", status: "completed", resultPreview: "alpha done" },
|
|
298
|
+
{ agent: "beta", status: "completed", taskInfo: " (1/2)", resultPreview: "", sessionLabel: "Session", sessionValue: "https://share/abc" },
|
|
299
|
+
]);
|
|
300
|
+
assert.equal(
|
|
301
|
+
content,
|
|
302
|
+
"Background tasks completed (2): **alpha**, **beta** (1/2)\n\n"
|
|
303
|
+
+ "1. alpha\nalpha done\n\n"
|
|
304
|
+
+ "2. beta (1/2)\n(no output)\nSession: https://share/abc",
|
|
305
|
+
);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("buildCompletionDetails derives paused status from state and summary", () => {
|
|
309
|
+
assert.equal(buildCompletionDetails({ id: "x", agent: "w", success: false, state: "paused", summary: "Paused after interrupt.", timestamp: 1 }).status, "paused");
|
|
310
|
+
assert.equal(buildCompletionDetails({ id: "x", agent: "w", success: false, summary: "boom", exitCode: 1, timestamp: 1 }).status, "failed");
|
|
311
|
+
assert.equal(buildCompletionDetails({ id: "x", agent: "w", success: true, summary: "ok", exitCode: 0, timestamp: 1 }).status, "completed");
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("buildCompletionDetails falls back to the unknown agent label", () => {
|
|
315
|
+
const details: SubagentNotifyDetails = buildCompletionDetails({ id: "x", agent: null, success: true, summary: "ok", timestamp: 1 });
|
|
316
|
+
assert.equal(details.agent, "unknown");
|
|
317
|
+
assert.equal(details.status, "completed");
|
|
318
|
+
});
|
|
319
|
+
});
|