@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
|
@@ -38,6 +38,7 @@ export interface RunnerSubagentStep {
|
|
|
38
38
|
};
|
|
39
39
|
structuredOutputSchema?: import("../../shared/types.ts").JsonSchemaObject;
|
|
40
40
|
effectiveAcceptance?: import("../../shared/types.ts").ResolvedAcceptanceConfig;
|
|
41
|
+
toolBudget?: import("../../shared/types.ts").ResolvedToolBudget;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
export interface ParallelStepGroup {
|
|
@@ -55,6 +56,8 @@ export interface DynamicRunnerGroup {
|
|
|
55
56
|
failFast?: boolean;
|
|
56
57
|
phase?: string;
|
|
57
58
|
label?: string;
|
|
59
|
+
sessionFiles?: (string | undefined)[];
|
|
60
|
+
thinkingOverrides?: (string | undefined)[];
|
|
58
61
|
effectiveAcceptance?: import("../../shared/types.ts").ResolvedAcceptanceConfig;
|
|
59
62
|
}
|
|
60
63
|
|
|
@@ -82,10 +85,47 @@ export function flattenSteps(steps: RunnerStep[]): RunnerSubagentStep[] {
|
|
|
82
85
|
return flat;
|
|
83
86
|
}
|
|
84
87
|
|
|
88
|
+
export const DEFAULT_GLOBAL_CONCURRENCY_LIMIT = 20;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A promise-based semaphore for limiting concurrent access across multiple
|
|
92
|
+
* mapConcurrent calls within a single run. Enforces a global cap on the total
|
|
93
|
+
* number of subagent tasks executing simultaneously, regardless of each step's
|
|
94
|
+
* per-step concurrency limit.
|
|
95
|
+
*/
|
|
96
|
+
export class Semaphore {
|
|
97
|
+
private available: number;
|
|
98
|
+
private readonly queue: Array<() => void> = [];
|
|
99
|
+
|
|
100
|
+
constructor(limit: number) {
|
|
101
|
+
this.available = Math.max(1, Math.floor(limit) || 1);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
acquire(): Promise<void> {
|
|
105
|
+
if (this.available > 0) {
|
|
106
|
+
this.available--;
|
|
107
|
+
return Promise.resolve();
|
|
108
|
+
}
|
|
109
|
+
return new Promise<void>((resolve) => {
|
|
110
|
+
this.queue.push(resolve);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
release(): void {
|
|
115
|
+
const next = this.queue.shift();
|
|
116
|
+
if (next) {
|
|
117
|
+
next();
|
|
118
|
+
} else {
|
|
119
|
+
this.available++;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
85
124
|
export async function mapConcurrent<T, R>(
|
|
86
125
|
items: T[],
|
|
87
126
|
limit: number,
|
|
88
127
|
fn: (item: T, i: number) => Promise<R>,
|
|
128
|
+
globalSemaphore?: Semaphore,
|
|
89
129
|
): Promise<R[]> {
|
|
90
130
|
const safeLimit = Math.max(1, Math.floor(limit) || 1);
|
|
91
131
|
const results: R[] = new Array(items.length);
|
|
@@ -94,7 +134,16 @@ export async function mapConcurrent<T, R>(
|
|
|
94
134
|
async function worker(_workerIndex: number): Promise<void> {
|
|
95
135
|
while (next < items.length) {
|
|
96
136
|
const i = next++;
|
|
97
|
-
|
|
137
|
+
if (globalSemaphore) {
|
|
138
|
+
await globalSemaphore.acquire();
|
|
139
|
+
try {
|
|
140
|
+
results[i] = await fn(items[i], i);
|
|
141
|
+
} finally {
|
|
142
|
+
globalSemaphore.release();
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
results[i] = await fn(items[i], i);
|
|
146
|
+
}
|
|
98
147
|
}
|
|
99
148
|
}
|
|
100
149
|
|
|
@@ -5,7 +5,8 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
import { encodeNestedPathEnv, parseNestedPathEnv, type NestedPathEntry } from "./nested-path.ts";
|
|
6
6
|
import { resolveMcpDirectToolNames } from "./mcp-direct-tool-allowlist.ts";
|
|
7
7
|
import { STRUCTURED_OUTPUT_CAPTURE_ENV, STRUCTURED_OUTPUT_SCHEMA_ENV } from "./structured-output.ts";
|
|
8
|
-
import type
|
|
8
|
+
import { TEMP_ROOT_DIR, type JsonSchemaObject, type ResolvedToolBudget } from "../../shared/types.ts";
|
|
9
|
+
import { TOOL_BUDGET_ENV, encodeToolBudgetEnv } from "./tool-budget.ts";
|
|
9
10
|
|
|
10
11
|
const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh"];
|
|
11
12
|
const TASK_ARG_LIMIT = 8000;
|
|
@@ -13,6 +14,8 @@ const PROMPT_RUNTIME_EXTENSION_PATH = path.join(path.dirname(fileURLToPath(impor
|
|
|
13
14
|
const FANOUT_CHILD_EXTENSION_PATH = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "extension", "fanout-child.ts");
|
|
14
15
|
export const SUBAGENT_CHILD_ENV = "SELESAI_SUBAGENT_CHILD";
|
|
15
16
|
export const SUBAGENT_ORCHESTRATOR_TARGET_ENV = "SELESAI_SUBAGENT_ORCHESTRATOR_TARGET";
|
|
17
|
+
export const SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV = "SELESAI_SUBAGENT_ORCHESTRATOR_SESSION_ID";
|
|
18
|
+
export const SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV = "SELESAI_SUBAGENT_SUPERVISOR_CHANNEL_DIR";
|
|
16
19
|
export const SUBAGENT_RUN_ID_ENV = "SELESAI_SUBAGENT_RUN_ID";
|
|
17
20
|
export const SUBAGENT_CHILD_AGENT_ENV = "SELESAI_SUBAGENT_CHILD_AGENT";
|
|
18
21
|
export const SUBAGENT_CHILD_INDEX_ENV = "SELESAI_SUBAGENT_CHILD_INDEX";
|
|
@@ -26,6 +29,7 @@ export const SUBAGENT_PARENT_DEPTH_ENV = "SELESAI_SUBAGENT_PARENT_DEPTH";
|
|
|
26
29
|
export const SUBAGENT_PARENT_PATH_ENV = "SELESAI_SUBAGENT_PARENT_PATH";
|
|
27
30
|
export const SUBAGENT_PARENT_CAPABILITY_TOKEN_ENV = "SELESAI_SUBAGENT_PARENT_CAPABILITY_TOKEN";
|
|
28
31
|
export const SUBAGENT_PARENT_SESSION_ENV = "SELESAI_SUBAGENT_PARENT_SESSION";
|
|
32
|
+
export const SUBAGENT_STEER_INBOX_ENV = "SELESAI_SUBAGENT_STEER_INBOX";
|
|
29
33
|
|
|
30
34
|
interface BuildPiArgsInput {
|
|
31
35
|
parentSessionId?: string;
|
|
@@ -60,11 +64,13 @@ interface BuildPiArgsInput {
|
|
|
60
64
|
parentDepth?: number;
|
|
61
65
|
parentPath?: NestedPathEntry[];
|
|
62
66
|
parentCapabilityToken?: string;
|
|
67
|
+
steerInboxDir?: string;
|
|
63
68
|
structuredOutput?: {
|
|
64
69
|
schema: JsonSchemaObject;
|
|
65
70
|
schemaPath: string;
|
|
66
71
|
outputPath: string;
|
|
67
72
|
};
|
|
73
|
+
toolBudget?: ResolvedToolBudget;
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
interface BuildPiArgsResult {
|
|
@@ -73,10 +79,20 @@ interface BuildPiArgsResult {
|
|
|
73
79
|
tempDir?: string;
|
|
74
80
|
}
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
|
|
82
|
+
function sanitizeSupervisorChannelSegment(value: string): string {
|
|
83
|
+
return value.trim().replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "unknown";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function supervisorChannelDir(runId: string, agent: string, childIndex: number): string {
|
|
87
|
+
return path.join(TEMP_ROOT_DIR, "supervisor-channels", `${sanitizeSupervisorChannelSegment(runId)}-${sanitizeSupervisorChannelSegment(agent)}-${childIndex}`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function applyThinkingSuffix(model: string | undefined, thinking: string | undefined, replaceExisting = false): string | undefined {
|
|
91
|
+
if (!model || !thinking) return model;
|
|
78
92
|
const colonIdx = model.lastIndexOf(":");
|
|
79
|
-
if (colonIdx !== -1 && THINKING_LEVELS.includes(model.substring(colonIdx + 1)))
|
|
93
|
+
if (colonIdx !== -1 && THINKING_LEVELS.includes(model.substring(colonIdx + 1))) {
|
|
94
|
+
return replaceExisting ? `${model.slice(0, colonIdx)}:${thinking}` : model;
|
|
95
|
+
}
|
|
80
96
|
return `${model}:${thinking}`;
|
|
81
97
|
}
|
|
82
98
|
|
|
@@ -204,6 +220,16 @@ export function buildPiArgs(input: BuildPiArgsInput): BuildPiArgsResult {
|
|
|
204
220
|
if (input.orchestratorIntercomTarget) {
|
|
205
221
|
env[SUBAGENT_ORCHESTRATOR_TARGET_ENV] = input.orchestratorIntercomTarget;
|
|
206
222
|
}
|
|
223
|
+
if (input.parentSessionId) {
|
|
224
|
+
env[SUBAGENT_ORCHESTRATOR_SESSION_ID_ENV] = input.parentSessionId;
|
|
225
|
+
}
|
|
226
|
+
if (input.orchestratorIntercomTarget && input.parentSessionId && input.runId && input.childAgentName) {
|
|
227
|
+
const childIndex = input.childIndex ?? 0;
|
|
228
|
+
const channelDir = supervisorChannelDir(input.runId, input.childAgentName, childIndex);
|
|
229
|
+
fs.mkdirSync(path.join(channelDir, "requests"), { recursive: true });
|
|
230
|
+
fs.mkdirSync(path.join(channelDir, "replies"), { recursive: true });
|
|
231
|
+
env[SUBAGENT_SUPERVISOR_CHANNEL_DIR_ENV] = channelDir;
|
|
232
|
+
}
|
|
207
233
|
if (input.runId) {
|
|
208
234
|
env[SUBAGENT_RUN_ID_ENV] = input.runId;
|
|
209
235
|
}
|
|
@@ -222,6 +248,11 @@ export function buildPiArgs(input: BuildPiArgsInput): BuildPiArgsResult {
|
|
|
222
248
|
env[STRUCTURED_OUTPUT_CAPTURE_ENV] = input.structuredOutput.outputPath;
|
|
223
249
|
env[STRUCTURED_OUTPUT_SCHEMA_ENV] = input.structuredOutput.schemaPath;
|
|
224
250
|
}
|
|
251
|
+
if (input.steerInboxDir) {
|
|
252
|
+
env[SUBAGENT_STEER_INBOX_ENV] = input.steerInboxDir;
|
|
253
|
+
}
|
|
254
|
+
const encodedToolBudget = encodeToolBudgetEnv(input.toolBudget);
|
|
255
|
+
if (encodedToolBudget) env[TOOL_BUDGET_ENV] = encodedToolBudget;
|
|
225
256
|
|
|
226
257
|
env[SUBAGENT_PARENT_SESSION_ENV] = input.parentSessionId ?? process.env[SUBAGENT_PARENT_SESSION_ENV] ?? "";
|
|
227
258
|
|
|
@@ -3,13 +3,18 @@ import * as path from "node:path";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
|
|
5
5
|
export const SELESAI_PACKAGE = "@selesai/code";
|
|
6
|
+
export const SELESAI_SUBAGENT_PI_BINARY_ENV = "SELESAI_SUBAGENT_PI_BINARY";
|
|
6
7
|
|
|
7
|
-
export function findSelesaiPackageRootFromEntry(
|
|
8
|
+
export function findSelesaiPackageRootFromEntry(
|
|
9
|
+
entryPoint: string,
|
|
10
|
+
): string | undefined {
|
|
8
11
|
let dir = path.dirname(entryPoint);
|
|
9
12
|
while (dir !== path.dirname(dir)) {
|
|
10
13
|
const packageJsonPath = path.join(dir, "package.json");
|
|
11
14
|
if (fs.existsSync(packageJsonPath)) {
|
|
12
|
-
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")) as {
|
|
15
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8")) as {
|
|
16
|
+
name?: unknown;
|
|
17
|
+
};
|
|
13
18
|
if (pkg.name === SELESAI_PACKAGE) return dir;
|
|
14
19
|
}
|
|
15
20
|
dir = path.dirname(dir);
|
|
@@ -18,13 +23,17 @@ export function findSelesaiPackageRootFromEntry(entryPoint: string): string | un
|
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
export function resolveInstalledSelesaiPackageRoot(): string | undefined {
|
|
21
|
-
return findSelesaiPackageRootFromEntry(
|
|
26
|
+
return findSelesaiPackageRootFromEntry(
|
|
27
|
+
fileURLToPath(import.meta.resolve(SELESAI_PACKAGE)),
|
|
28
|
+
);
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
export function resolveSelesaiPackageRoot(): string | undefined {
|
|
25
32
|
try {
|
|
26
33
|
const entry = process.argv[1];
|
|
27
|
-
return entry
|
|
34
|
+
return entry
|
|
35
|
+
? findSelesaiPackageRootFromEntry(fs.realpathSync(entry))
|
|
36
|
+
: undefined;
|
|
28
37
|
} catch {
|
|
29
38
|
// process.argv[1] probing is best-effort; callers can fall back to PATH/package resolution.
|
|
30
39
|
return undefined;
|
|
@@ -40,6 +49,7 @@ export interface SelesaiSpawnDeps {
|
|
|
40
49
|
resolvePackageJson?: () => string;
|
|
41
50
|
resolvePackageEntry?: () => string;
|
|
42
51
|
piPackageRoot?: string;
|
|
52
|
+
env?: NodeJS.ProcessEnv;
|
|
43
53
|
}
|
|
44
54
|
|
|
45
55
|
interface SelesaiSpawnCommand {
|
|
@@ -47,7 +57,10 @@ interface SelesaiSpawnCommand {
|
|
|
47
57
|
args: string[];
|
|
48
58
|
}
|
|
49
59
|
|
|
50
|
-
function isRunnableNodeScript(
|
|
60
|
+
function isRunnableNodeScript(
|
|
61
|
+
filePath: string,
|
|
62
|
+
existsSync: (filePath: string) => boolean,
|
|
63
|
+
): boolean {
|
|
51
64
|
if (!existsSync(filePath)) return false;
|
|
52
65
|
return /\.(?:mjs|cjs|js)$/i.test(filePath);
|
|
53
66
|
}
|
|
@@ -56,74 +69,79 @@ function normalizePath(filePath: string): string {
|
|
|
56
69
|
return path.isAbsolute(filePath) ? filePath : path.resolve(filePath);
|
|
57
70
|
}
|
|
58
71
|
|
|
59
|
-
export function resolveWindowsSelesaiCliScript(
|
|
72
|
+
export function resolveWindowsSelesaiCliScript(
|
|
73
|
+
deps: SelesaiSpawnDeps = {},
|
|
74
|
+
): string | undefined {
|
|
60
75
|
const existsSync = deps.existsSync ?? fs.existsSync;
|
|
61
|
-
const readFileSync =
|
|
76
|
+
const readFileSync =
|
|
77
|
+
deps.readFileSync ??
|
|
78
|
+
((filePath, encoding) => fs.readFileSync(filePath, encoding));
|
|
62
79
|
const argv1 = deps.argv1 ?? process.argv[1];
|
|
63
80
|
|
|
64
81
|
if (argv1) {
|
|
65
82
|
const argvPath = normalizePath(argv1);
|
|
66
|
-
// Resolve symlinks before checking the extension: a renamed fork like
|
|
67
|
-
// "selesai" is typically a symlink to dist/cli.js, so the raw argv1 has
|
|
68
|
-
// no .js extension and would otherwise fail the runnable-script check.
|
|
69
|
-
let resolved = argvPath;
|
|
70
|
-
try {
|
|
71
|
-
resolved = fs.realpathSync(argvPath);
|
|
72
|
-
} catch {
|
|
73
|
-
// realpath is best-effort; fall back to the raw path.
|
|
74
|
-
}
|
|
75
|
-
if (isRunnableNodeScript(resolved, existsSync)) {
|
|
76
|
-
return resolved;
|
|
77
|
-
}
|
|
78
83
|
if (isRunnableNodeScript(argvPath, existsSync)) {
|
|
79
84
|
return argvPath;
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
try {
|
|
84
|
-
const resolvePackageJson =
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
const resolvePackageJson =
|
|
90
|
+
deps.resolvePackageJson ??
|
|
91
|
+
(() => {
|
|
92
|
+
const root = deps.piPackageRoot ?? resolveSelesaiPackageRoot();
|
|
93
|
+
if (root) return path.join(root, "package.json");
|
|
94
|
+
const packageRoot = deps.resolvePackageEntry
|
|
95
|
+
? findSelesaiPackageRootFromEntry(deps.resolvePackageEntry())
|
|
96
|
+
: resolveInstalledSelesaiPackageRoot();
|
|
97
|
+
if (!packageRoot)
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Could not resolve ${SELESAI_PACKAGE} package root`,
|
|
100
|
+
);
|
|
101
|
+
return path.join(packageRoot, "package.json");
|
|
102
|
+
});
|
|
93
103
|
const packageJsonPath = resolvePackageJson();
|
|
94
104
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as {
|
|
95
105
|
bin?: string | Record<string, string>;
|
|
96
106
|
};
|
|
97
107
|
const binField = packageJson.bin;
|
|
98
|
-
const binPath =
|
|
99
|
-
|
|
100
|
-
|
|
108
|
+
const binPath =
|
|
109
|
+
typeof binField === "string"
|
|
110
|
+
? binField
|
|
111
|
+
: (binField?.selesai ?? Object.values(binField ?? {})[0]);
|
|
101
112
|
if (!binPath) return undefined;
|
|
102
113
|
const candidate = path.resolve(path.dirname(packageJsonPath), binPath);
|
|
103
114
|
if (isRunnableNodeScript(candidate, existsSync)) {
|
|
104
115
|
return candidate;
|
|
105
116
|
}
|
|
106
117
|
} catch {
|
|
107
|
-
// Windows CLI resolution is optional; falling back to `
|
|
118
|
+
// Windows CLI resolution is optional; falling back to `pi` lets PATH handle execution.
|
|
108
119
|
return undefined;
|
|
109
120
|
}
|
|
110
121
|
|
|
111
122
|
return undefined;
|
|
112
123
|
}
|
|
113
124
|
|
|
114
|
-
export function getSelesaiSpawnCommand(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
export function getSelesaiSpawnCommand(
|
|
126
|
+
args: string[],
|
|
127
|
+
deps: SelesaiSpawnDeps = {},
|
|
128
|
+
): SelesaiSpawnCommand {
|
|
129
|
+
const env = deps.env ?? process.env;
|
|
130
|
+
const piBinary = env[SELESAI_SUBAGENT_PI_BINARY_ENV]?.trim();
|
|
131
|
+
if (piBinary) {
|
|
132
|
+
return { command: piBinary, args };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const platform = deps.platform ?? process.platform;
|
|
136
|
+
if (platform === "win32") {
|
|
137
|
+
const piCliPath = resolveWindowsSelesaiCliScript(deps);
|
|
138
|
+
if (piCliPath) {
|
|
139
|
+
return {
|
|
140
|
+
command: deps.execPath ?? process.execPath,
|
|
141
|
+
args: [piCliPath, ...args],
|
|
142
|
+
};
|
|
143
|
+
}
|
|
124
144
|
}
|
|
125
145
|
|
|
126
|
-
// Fall back to the upstream binary name only if the CLI script could not be
|
|
127
|
-
// resolved. "selesai" is the default for selesai installs.
|
|
128
146
|
return { command: "selesai", args };
|
|
129
|
-
}
|
|
147
|
+
}
|
|
@@ -22,9 +22,11 @@ export function resolveSingleOutputPath(
|
|
|
22
22
|
output: string | boolean | undefined,
|
|
23
23
|
runtimeCwd: string,
|
|
24
24
|
requestedCwd?: string,
|
|
25
|
+
relativeBaseDir?: string,
|
|
25
26
|
): string | undefined {
|
|
26
27
|
if (typeof output !== "string" || !output || output === "false" || output === "true") return undefined;
|
|
27
28
|
if (path.isAbsolute(output)) return output;
|
|
29
|
+
if (relativeBaseDir) return path.resolve(relativeBaseDir, output);
|
|
28
30
|
const baseCwd = requestedCwd
|
|
29
31
|
? (path.isAbsolute(requestedCwd) ? requestedCwd : path.resolve(runtimeCwd, requestedCwd))
|
|
30
32
|
: runtimeCwd;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import type { ExtensionAPI } from "@selesai/code";
|
|
4
|
-
import {
|
|
4
|
+
import { registerNativeSupervisorClient } from "../../intercom/native-supervisor-channel.ts";
|
|
5
|
+
import { consumeSteerRequestsFromDir, writeSteerRequestToDir, type SteerRequest } from "../background/control-channel.ts";
|
|
6
|
+
import { SUBAGENT_FANOUT_CHILD_ENV, SUBAGENT_STEER_INBOX_ENV } from "./pi-args.ts";
|
|
5
7
|
import { STRUCTURED_OUTPUT_CAPTURE_ENV, STRUCTURED_OUTPUT_SCHEMA_ENV, validateStructuredOutputValue } from "./structured-output.ts";
|
|
6
|
-
import
|
|
8
|
+
import { TOOL_BUDGET_ENV, decodeToolBudgetEnv, shouldBlockToolForBudget, toolBudgetBlockedMessage, toolBudgetSoftNudge } from "./tool-budget.ts";
|
|
9
|
+
import type { JsonSchemaObject, ResolvedToolBudget } from "../../shared/types.ts";
|
|
7
10
|
|
|
8
11
|
const SUBAGENT_INHERIT_PROJECT_CONTEXT_ENV = "SELESAI_SUBAGENT_INHERIT_PROJECT_CONTEXT";
|
|
9
12
|
const SUBAGENT_INHERIT_SKILLS_ENV = "SELESAI_SUBAGENT_INHERIT_SKILLS";
|
|
@@ -20,7 +23,7 @@ export const CHILD_SUBAGENT_BOUNDARY_INSTRUCTIONS = [
|
|
|
20
23
|
"The parent session owns delegation, orchestration, review fanout, and follow-up worker launches.",
|
|
21
24
|
"Ignore prior parent-only orchestration instructions in inherited conversation history.",
|
|
22
25
|
"Do not propose or run subagents. Complete only your assigned role-specific task with the tools available to you.",
|
|
23
|
-
"If you need to edit files,
|
|
26
|
+
"If you need to edit files, use the available editing tools. Do not print tool-call syntax, patches, or pseudo-tool calls as text.",
|
|
24
27
|
].join("\n");
|
|
25
28
|
|
|
26
29
|
export const CHILD_FANOUT_BOUNDARY_INSTRUCTIONS = [
|
|
@@ -29,7 +32,7 @@ export const CHILD_FANOUT_BOUNDARY_INSTRUCTIONS = [
|
|
|
29
32
|
"You may use the `subagent` tool only for the fanout work explicitly requested in this task.",
|
|
30
33
|
"Do not broaden yourself into general parent orchestration. Do not launch follow-up workers unless the task explicitly asks for that.",
|
|
31
34
|
"The maxSubagentDepth cap still applies and may block further fanout.",
|
|
32
|
-
"If you need to edit files,
|
|
35
|
+
"If you need to edit files, use the available editing tools. Do not print tool-call syntax, patches, or pseudo-tool calls as text.",
|
|
33
36
|
].join("\n");
|
|
34
37
|
|
|
35
38
|
const PARENT_ONLY_CUSTOM_MESSAGE_TYPES = new Set([
|
|
@@ -155,7 +158,124 @@ export function stripParentOnlySubagentMessages(messages: unknown[]): unknown[]
|
|
|
155
158
|
return changed ? filtered : messages;
|
|
156
159
|
}
|
|
157
160
|
|
|
161
|
+
export function formatSteerMessage(request: SteerRequest): string {
|
|
162
|
+
return [
|
|
163
|
+
"Mid-run steering from the parent orchestrator:",
|
|
164
|
+
"",
|
|
165
|
+
request.message,
|
|
166
|
+
"",
|
|
167
|
+
"Incorporate this guidance at the next safe point. Do not restart the task unless the guidance explicitly asks you to.",
|
|
168
|
+
].join("\n");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function registerToolBudget(pi: ExtensionAPI, budget: ResolvedToolBudget | undefined): void {
|
|
172
|
+
if (!budget) return;
|
|
173
|
+
let toolCount = 0;
|
|
174
|
+
let softNudged = false;
|
|
175
|
+
const sendUserMessage = (pi as { sendUserMessage?: (content: string, options: { deliverAs: "steer" }) => unknown }).sendUserMessage;
|
|
176
|
+
const onRuntimeEvent = pi.on as unknown as (event: string, handler: (event: { toolName?: string }) => unknown) => void;
|
|
177
|
+
onRuntimeEvent("tool_call", (event) => {
|
|
178
|
+
const toolName = typeof event.toolName === "string" ? event.toolName : "tool";
|
|
179
|
+
toolCount++;
|
|
180
|
+
if (budget.soft !== undefined && toolCount >= budget.soft && !softNudged) {
|
|
181
|
+
softNudged = true;
|
|
182
|
+
try {
|
|
183
|
+
sendUserMessage?.(toolBudgetSoftNudge(budget, toolCount), { deliverAs: "steer" });
|
|
184
|
+
} catch {
|
|
185
|
+
// Budget nudges are advisory; blocking below remains authoritative.
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (!shouldBlockToolForBudget(budget, toolName, toolCount)) return undefined;
|
|
189
|
+
return { block: true, reason: toolBudgetBlockedMessage(budget, toolName, toolCount) };
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function registerSteeringInbox(pi: ExtensionAPI): void {
|
|
194
|
+
const steerInbox = process.env[SUBAGENT_STEER_INBOX_ENV]?.trim();
|
|
195
|
+
if (!steerInbox) return;
|
|
196
|
+
const sendUserMessage = (pi as { sendUserMessage?: (content: string, options: { deliverAs: "steer" }) => unknown }).sendUserMessage;
|
|
197
|
+
if (typeof sendUserMessage !== "function") return;
|
|
198
|
+
|
|
199
|
+
let canSteer = false;
|
|
200
|
+
let disposed = false;
|
|
201
|
+
let flushing = false;
|
|
202
|
+
let started = false;
|
|
203
|
+
let watcher: fs.FSWatcher | undefined;
|
|
204
|
+
let interval: NodeJS.Timeout | undefined;
|
|
205
|
+
const flush = (): void => {
|
|
206
|
+
if (disposed || flushing || !canSteer) return;
|
|
207
|
+
flushing = true;
|
|
208
|
+
try {
|
|
209
|
+
const requests = consumeSteerRequestsFromDir(steerInbox);
|
|
210
|
+
for (let index = 0; index < requests.length; index++) {
|
|
211
|
+
const request = requests[index]!;
|
|
212
|
+
try {
|
|
213
|
+
sendUserMessage(formatSteerMessage(request), { deliverAs: "steer" });
|
|
214
|
+
} catch {
|
|
215
|
+
for (const pending of requests.slice(index)) writeSteerRequestToDir(steerInbox, pending);
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
} finally {
|
|
220
|
+
flushing = false;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
const start = (): void => {
|
|
224
|
+
if (started || disposed) return;
|
|
225
|
+
try {
|
|
226
|
+
fs.mkdirSync(steerInbox, { recursive: true });
|
|
227
|
+
} catch {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
started = true;
|
|
231
|
+
try {
|
|
232
|
+
watcher = fs.watch(steerInbox, () => flush());
|
|
233
|
+
watcher.on("error", () => {});
|
|
234
|
+
} catch {
|
|
235
|
+
watcher = undefined;
|
|
236
|
+
}
|
|
237
|
+
interval = setInterval(flush, 250);
|
|
238
|
+
interval.unref?.();
|
|
239
|
+
};
|
|
240
|
+
const activate = (): undefined => {
|
|
241
|
+
start();
|
|
242
|
+
canSteer = true;
|
|
243
|
+
flush();
|
|
244
|
+
return undefined;
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const onRuntimeEvent = pi.on as unknown as (event: string, handler: (event: unknown) => unknown) => void;
|
|
248
|
+
onRuntimeEvent("session_start", () => start());
|
|
249
|
+
for (const eventName of ["message_start", "message_update", "message_end", "tool_execution_start", "tool_execution_end", "turn_end"] as const) {
|
|
250
|
+
onRuntimeEvent(eventName, activate);
|
|
251
|
+
}
|
|
252
|
+
onRuntimeEvent("session_shutdown", () => {
|
|
253
|
+
disposed = true;
|
|
254
|
+
try {
|
|
255
|
+
watcher?.close();
|
|
256
|
+
} catch {}
|
|
257
|
+
if (interval) clearInterval(interval);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
158
261
|
export default function registerSubagentPromptRuntime(pi: ExtensionAPI): void {
|
|
262
|
+
registerSteeringInbox(pi);
|
|
263
|
+
registerToolBudget(pi, decodeToolBudgetEnv(process.env[TOOL_BUDGET_ENV]));
|
|
264
|
+
let nativeSupervisorClientRegistered = false;
|
|
265
|
+
let nativeSupervisorFallbackRegistered = false;
|
|
266
|
+
const registerNativeSupervisorClientOnce = (): void => {
|
|
267
|
+
if (nativeSupervisorClientRegistered) return;
|
|
268
|
+
nativeSupervisorClientRegistered = true;
|
|
269
|
+
registerNativeSupervisorClient(pi, { includeIntercomFallback: false });
|
|
270
|
+
};
|
|
271
|
+
const registerNativeSupervisorFallbackOnce = (): void => {
|
|
272
|
+
registerNativeSupervisorClientOnce();
|
|
273
|
+
if (nativeSupervisorFallbackRegistered) return;
|
|
274
|
+
nativeSupervisorFallbackRegistered = true;
|
|
275
|
+
registerNativeSupervisorClient(pi);
|
|
276
|
+
};
|
|
277
|
+
const onRuntimeEvent = pi.on as unknown as (event: string, handler: (event: unknown) => unknown) => void;
|
|
278
|
+
onRuntimeEvent("session_start", registerNativeSupervisorClientOnce);
|
|
159
279
|
const structuredOutputPath = process.env[STRUCTURED_OUTPUT_CAPTURE_ENV];
|
|
160
280
|
const structuredSchemaPath = process.env[STRUCTURED_OUTPUT_SCHEMA_ENV];
|
|
161
281
|
if (structuredOutputPath && structuredSchemaPath) {
|
|
@@ -194,7 +314,6 @@ export default function registerSubagentPromptRuntime(pi: ExtensionAPI): void {
|
|
|
194
314
|
});
|
|
195
315
|
}
|
|
196
316
|
|
|
197
|
-
const onRuntimeEvent = pi.on as unknown as (event: string, handler: (event: unknown) => unknown) => void;
|
|
198
317
|
onRuntimeEvent("context", (event: { messages: unknown[] }) => {
|
|
199
318
|
const messages = stripParentOnlySubagentMessages(event.messages);
|
|
200
319
|
if (messages === event.messages) return undefined;
|
|
@@ -202,6 +321,7 @@ export default function registerSubagentPromptRuntime(pi: ExtensionAPI): void {
|
|
|
202
321
|
});
|
|
203
322
|
|
|
204
323
|
onRuntimeEvent("before_agent_start", async (event: { systemPrompt: string }) => {
|
|
324
|
+
registerNativeSupervisorFallbackOnce();
|
|
205
325
|
const intercomSessionName = process.env[SUBAGENT_INTERCOM_SESSION_NAME_ENV]?.trim();
|
|
206
326
|
if (intercomSessionName && typeof pi.setSessionName === "function") {
|
|
207
327
|
pi.setSessionName(intercomSessionName);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { ResolvedToolBudget, ToolBudgetConfig, ToolBudgetState } from "../../shared/types.ts";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_TOOL_BUDGET_BLOCK = ["read", "grep", "find", "ls"] as const;
|
|
4
|
+
export const TOOL_BUDGET_ENV = "SELESAI_SUBAGENT_TOOL_BUDGET";
|
|
5
|
+
|
|
6
|
+
export function normalizeToolBudgetBlock(block: ToolBudgetConfig["block"] | undefined): "*" | string[] {
|
|
7
|
+
if (block === "*") return "*";
|
|
8
|
+
if (block === undefined) return [...DEFAULT_TOOL_BUDGET_BLOCK];
|
|
9
|
+
return [...new Set(block.map((tool) => tool.trim()).filter(Boolean))];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function validateToolBudgetConfig(raw: unknown, label = "toolBudget"): { budget?: ResolvedToolBudget; error?: string } {
|
|
13
|
+
if (raw === undefined) return {};
|
|
14
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { error: `${label} must be an object with hard and optional soft/block.` };
|
|
15
|
+
const value = raw as ToolBudgetConfig;
|
|
16
|
+
if (typeof value.hard !== "number" || !Number.isInteger(value.hard) || value.hard < 1) {
|
|
17
|
+
return { error: `${label}.hard must be an integer >= 1.` };
|
|
18
|
+
}
|
|
19
|
+
if (value.soft !== undefined && (typeof value.soft !== "number" || !Number.isInteger(value.soft) || value.soft < 1)) {
|
|
20
|
+
return { error: `${label}.soft must be an integer >= 1 when provided.` };
|
|
21
|
+
}
|
|
22
|
+
if (value.soft !== undefined && value.soft > value.hard) {
|
|
23
|
+
return { error: `${label}.soft must be <= ${label}.hard.` };
|
|
24
|
+
}
|
|
25
|
+
if (value.block !== undefined && value.block !== "*") {
|
|
26
|
+
if (!Array.isArray(value.block)) return { error: `${label}.block must be "*" or an array of tool names.` };
|
|
27
|
+
if (value.block.length === 0) return { error: `${label}.block must contain at least one tool name.` };
|
|
28
|
+
for (const item of value.block) {
|
|
29
|
+
if (typeof item !== "string" || !item.trim()) return { error: `${label}.block must contain non-empty tool names.` };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return { budget: { hard: value.hard, ...(value.soft !== undefined ? { soft: value.soft } : {}), block: normalizeToolBudgetBlock(value.block) } };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function initialToolBudgetState(budget: ResolvedToolBudget): ToolBudgetState {
|
|
36
|
+
return { ...budget, toolCount: 0, outcome: "within-budget" };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function toolBudgetState(budget: ResolvedToolBudget, toolCount: number, blockedTool?: string): ToolBudgetState {
|
|
40
|
+
const overHard = toolCount > budget.hard;
|
|
41
|
+
const overSoft = budget.soft !== undefined && toolCount >= budget.soft;
|
|
42
|
+
return {
|
|
43
|
+
...budget,
|
|
44
|
+
toolCount,
|
|
45
|
+
outcome: overHard ? "hard-blocked" : overSoft ? "soft-reached" : "within-budget",
|
|
46
|
+
...(overSoft ? { softReachedAt: budget.soft } : {}),
|
|
47
|
+
...(overHard ? { hardReachedAt: budget.hard, blockedTool } : {}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function shouldBlockToolForBudget(budget: ResolvedToolBudget, toolName: string, nextToolCount: number): boolean {
|
|
52
|
+
if (nextToolCount <= budget.hard) return false;
|
|
53
|
+
return budget.block === "*" || budget.block.includes(toolName);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function toolBudgetSoftNudge(budget: ResolvedToolBudget, toolCount: number): string {
|
|
57
|
+
return `Tool budget soft limit reached after ${toolCount} tool call${toolCount === 1 ? "" : "s"} (soft ${budget.soft}, hard ${budget.hard}). Stop starting new browsing/search work and finalize from the context you already have.`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function toolBudgetBlockedMessage(budget: ResolvedToolBudget, toolName: string, toolCount: number): string {
|
|
61
|
+
return `Tool budget hard limit reached after ${toolCount} tool call${toolCount === 1 ? "" : "s"} (hard ${budget.hard}). The '${toolName}' tool is blocked so you can finalize from the context you already have.`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function encodeToolBudgetEnv(budget: ResolvedToolBudget | undefined): string | undefined {
|
|
65
|
+
return budget ? JSON.stringify(budget) : undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function decodeToolBudgetEnv(value: string | undefined): ResolvedToolBudget | undefined {
|
|
69
|
+
if (!value?.trim()) return undefined;
|
|
70
|
+
const parsed = JSON.parse(value) as unknown;
|
|
71
|
+
const normalized = validateToolBudgetConfig(parsed, TOOL_BUDGET_ENV);
|
|
72
|
+
if (normalized.error) throw new Error(normalized.error);
|
|
73
|
+
return normalized.budget;
|
|
74
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ResolvedTurnBudget, TurnBudgetState } from "../../shared/types.ts";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_TURN_BUDGET_GRACE_TURNS = 1;
|
|
4
|
+
|
|
5
|
+
export function appendTurnBudgetSystemPrompt(systemPrompt: string, budget: ResolvedTurnBudget | undefined): string {
|
|
6
|
+
if (!budget) return systemPrompt;
|
|
7
|
+
const grace = budget.graceTurns === 1 ? "1 additional assistant turn" : `${budget.graceTurns} additional assistant turns`;
|
|
8
|
+
const block = [
|
|
9
|
+
"## Turn budget",
|
|
10
|
+
`This child run has a soft budget of ${budget.maxTurns} assistant turn${budget.maxTurns === 1 ? "" : "s"}.`,
|
|
11
|
+
`After that, ${grace} may be allowed only for a final wrap-up.`,
|
|
12
|
+
"When you approach or reach the soft budget, stop starting new tool work and return the final answer immediately.",
|
|
13
|
+
"This runner uses process-mode execution, so live steering after launch may be unavailable; treat this instruction as the wrap-up request.",
|
|
14
|
+
"If you continue past the soft budget plus grace turns, the supervisor may abort the process and return only partial output.",
|
|
15
|
+
].join("\n");
|
|
16
|
+
return systemPrompt.trim() ? `${systemPrompt.trim()}\n\n${block}` : block;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function turnBudgetSoftNote(budget: ResolvedTurnBudget, turnCount: number): string {
|
|
20
|
+
return `Turn budget wrap-up was requested after ${turnCount} assistant turn${turnCount === 1 ? "" : "s"} (soft limit ${budget.maxTurns}, grace ${budget.graceTurns}). Process-mode live steering is unavailable, so the child was warned at launch to wrap up by this budget. Output may be partial.`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function turnBudgetExceededMessage(budget: ResolvedTurnBudget, turnCount: number): string {
|
|
24
|
+
return `Subagent exceeded turn budget after ${turnCount} assistant turn${turnCount === 1 ? "" : "s"} (soft limit ${budget.maxTurns} + grace ${budget.graceTurns}).`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function formatTurnBudgetOutput(message: string, output: string): string {
|
|
28
|
+
return output.trim()
|
|
29
|
+
? `${message}\n\nPartial output before turn-budget abort:\n${output}`
|
|
30
|
+
: message;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function initialTurnBudgetState(budget: ResolvedTurnBudget): TurnBudgetState {
|
|
34
|
+
return { ...budget, outcome: "within-budget", turnCount: 0 };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function turnBudgetState(budget: ResolvedTurnBudget, turnCount: number, exceeded: boolean): TurnBudgetState {
|
|
38
|
+
return {
|
|
39
|
+
...budget,
|
|
40
|
+
turnCount,
|
|
41
|
+
outcome: exceeded ? "exceeded" : "wrap-up-requested",
|
|
42
|
+
wrapUpRequestedAtTurn: budget.maxTurns,
|
|
43
|
+
...(exceeded ? { exceededAtTurn: turnCount } : {}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function shouldAbortForTurnBudget(budget: ResolvedTurnBudget, turnCount: number, terminalAssistantStop: boolean): boolean {
|
|
48
|
+
const hardLimit = budget.maxTurns + budget.graceTurns;
|
|
49
|
+
if (turnCount < hardLimit) return false;
|
|
50
|
+
if (turnCount > hardLimit) return true;
|
|
51
|
+
return !terminalAssistantStop;
|
|
52
|
+
}
|