@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,145 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
checkModelScope,
|
|
5
|
+
matchesScopePattern,
|
|
6
|
+
parseModelScopeConfig,
|
|
7
|
+
type ModelScopeConfig,
|
|
8
|
+
} from "../../src/runs/shared/model-scope.ts";
|
|
9
|
+
|
|
10
|
+
describe("matchesScopePattern", () => {
|
|
11
|
+
it("matches an exact provider/id", () => {
|
|
12
|
+
assert.equal(matchesScopePattern("anthropic/claude-sonnet-4", "anthropic/claude-sonnet-4"), true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("matches a provider wildcard", () => {
|
|
16
|
+
assert.equal(matchesScopePattern("anthropic/claude-sonnet-4", "anthropic/*"), true);
|
|
17
|
+
assert.equal(matchesScopePattern("anthropic/claude-haiku-4-5", "anthropic/*"), true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("matches a model-prefix wildcard", () => {
|
|
21
|
+
assert.equal(matchesScopePattern("openai/gpt-5-mini", "openai/gpt-5-*"), true);
|
|
22
|
+
// The dash in the pattern is literal, so the bare id without a trailing part does not match.
|
|
23
|
+
assert.equal(matchesScopePattern("openai/gpt-5", "openai/gpt-5-*"), false);
|
|
24
|
+
assert.equal(matchesScopePattern("openai/gpt-5", "openai/gpt-5*"), true);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("does not match across providers", () => {
|
|
28
|
+
assert.equal(matchesScopePattern("deepseek/deepseek-v4", "anthropic/*"), false);
|
|
29
|
+
assert.equal(matchesScopePattern("openai/gpt-5-mini", "anthropic/*"), false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("ignores case on both sides", () => {
|
|
33
|
+
assert.equal(matchesScopePattern("Anthropic/Claude-Sonnet-4", "anthropic/*"), true);
|
|
34
|
+
assert.equal(matchesScopePattern("anthropic/claude-sonnet-4", "ANTHROPIC/CLAUDE-*"), true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("strips a thinking suffix before matching", () => {
|
|
38
|
+
assert.equal(matchesScopePattern("anthropic/claude-sonnet-4:high", "anthropic/claude-sonnet-4"), true);
|
|
39
|
+
assert.equal(matchesScopePattern("anthropic/claude-sonnet-4:high", "anthropic/*"), true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("does not treat arbitrary colon text as a thinking suffix", () => {
|
|
43
|
+
assert.equal(matchesScopePattern("anthropic:claude-opus", "anthropic"), false);
|
|
44
|
+
assert.equal(matchesScopePattern("anthropic/claude-sonnet-4:experimental", "anthropic/claude-sonnet-4"), false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("requires a full match, not a substring", () => {
|
|
48
|
+
assert.equal(matchesScopePattern("anthropic/claude-sonnet-4", "anthropic/claude"), false);
|
|
49
|
+
assert.equal(matchesScopePattern("anthropic/claude-sonnet-4", "*claude*"), true);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("checkModelScope", () => {
|
|
54
|
+
const scope: ModelScopeConfig = { enforce: true, allow: ["anthropic/*", "openai/gpt-5-*"] };
|
|
55
|
+
|
|
56
|
+
it("returns undefined when enforcement is off", () => {
|
|
57
|
+
assert.equal(checkModelScope("deepseek/deepseek-v4", { enforce: false, allow: ["anthropic/*"] }, "explicit"), undefined);
|
|
58
|
+
assert.equal(checkModelScope("deepseek/deepseek-v4", undefined, "explicit"), undefined);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("returns undefined when no allow list is configured", () => {
|
|
62
|
+
assert.equal(checkModelScope("deepseek/deepseek-v4", { enforce: true }, "explicit"), undefined);
|
|
63
|
+
assert.equal(checkModelScope("deepseek/deepseek-v4", { enforce: true, allow: [] }, "explicit"), undefined);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("returns undefined when the model is in scope", () => {
|
|
67
|
+
assert.equal(checkModelScope("anthropic/claude-sonnet-4", scope, "explicit"), undefined);
|
|
68
|
+
assert.equal(checkModelScope("openai/gpt-5-mini:high", scope, "inherited"), undefined);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("returns an error violation for an explicit out-of-scope model", () => {
|
|
72
|
+
const violation = checkModelScope("deepseek/deepseek-v4", scope, "explicit");
|
|
73
|
+
assert.equal(violation?.severity, "error");
|
|
74
|
+
assert.equal(violation?.model, "deepseek/deepseek-v4");
|
|
75
|
+
assert.deepEqual(violation?.allowedPatterns, ["anthropic/*", "openai/gpt-5-*"]);
|
|
76
|
+
assert.match(violation?.message ?? "", /outside the configured subagent model scope/);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("returns a warn violation for an inherited out-of-scope model", () => {
|
|
80
|
+
const violation = checkModelScope("deepseek/deepseek-v4", scope, "inherited");
|
|
81
|
+
assert.equal(violation?.severity, "warn");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("defaults to inherited (warn) severity when source is omitted-ish via inherited", () => {
|
|
85
|
+
// Caller passes "inherited" for frontmatter/parent-inherited models.
|
|
86
|
+
assert.equal(checkModelScope("meta/llama-4", scope, "inherited")?.severity, "warn");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("strips the thinking suffix from the reported model", () => {
|
|
90
|
+
const violation = checkModelScope("deepseek/deepseek-v4:high", scope, "explicit");
|
|
91
|
+
assert.equal(violation?.model, "deepseek/deepseek-v4");
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("returns undefined for an undefined model", () => {
|
|
95
|
+
assert.equal(checkModelScope(undefined, scope, "explicit"), undefined);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("parseModelScopeConfig", () => {
|
|
100
|
+
const meta = { filePath: "~/.pi/agent/settings.json" };
|
|
101
|
+
|
|
102
|
+
it("returns undefined when the field is absent", () => {
|
|
103
|
+
assert.equal(parseModelScopeConfig(undefined, meta), undefined);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("parses a well-formed config", () => {
|
|
107
|
+
assert.deepEqual(
|
|
108
|
+
parseModelScopeConfig({ enforce: true, allow: ["anthropic/*", "openai/gpt-5-*"] }, meta),
|
|
109
|
+
{ enforce: true, allow: ["anthropic/*", "openai/gpt-5-*"] },
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("parses enforce alone", () => {
|
|
114
|
+
assert.deepEqual(parseModelScopeConfig({ enforce: false }, meta), { enforce: false });
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("trims allow patterns and drops empties", () => {
|
|
118
|
+
assert.deepEqual(
|
|
119
|
+
parseModelScopeConfig({ enforce: true, allow: [" anthropic/* ", "", " "] }, meta),
|
|
120
|
+
{ enforce: true, allow: ["anthropic/*"] },
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("rejects a non-object value", () => {
|
|
125
|
+
assert.throws(() => parseModelScopeConfig("anthropic/*", meta), /invalid 'modelScope'/);
|
|
126
|
+
assert.throws(() => parseModelScopeConfig([], meta), /invalid 'modelScope'/);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("rejects a non-boolean enforce", () => {
|
|
130
|
+
assert.throws(() => parseModelScopeConfig({ enforce: "yes" }, meta), /invalid 'modelScope.enforce'/);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("rejects a non-array allow", () => {
|
|
134
|
+
assert.throws(() => parseModelScopeConfig({ allow: "anthropic/*" }, meta), /invalid 'modelScope.allow'/);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("rejects an allow array with non-string entries", () => {
|
|
138
|
+
assert.throws(() => parseModelScopeConfig({ enforce: true, allow: ["anthropic/*", 42] }, meta), /invalid 'modelScope.allow'/);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("rejects enforce without a non-empty allow list", () => {
|
|
142
|
+
assert.throws(() => parseModelScopeConfig({ enforce: true }, meta), /without a non-empty 'allow'/);
|
|
143
|
+
assert.throws(() => parseModelScopeConfig({ enforce: true, allow: [] }, meta), /non-empty array of patterns/);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as os from "node:os";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { afterEach, describe, it } from "node:test";
|
|
7
|
+
import {
|
|
8
|
+
NATIVE_SUPERVISOR_TOOL_NAME,
|
|
9
|
+
createNativeSupervisorChannel,
|
|
10
|
+
ensureSupervisorChannelDir,
|
|
11
|
+
resolveSupervisorChannelDir,
|
|
12
|
+
} from "../../src/intercom/native-supervisor-channel.ts";
|
|
13
|
+
import type { SubagentState } from "../../src/shared/types.ts";
|
|
14
|
+
|
|
15
|
+
const createdChannels: string[] = [];
|
|
16
|
+
|
|
17
|
+
function makeState(sessionId: string | null, ctx: unknown): SubagentState {
|
|
18
|
+
return {
|
|
19
|
+
baseCwd: process.cwd(),
|
|
20
|
+
currentSessionId: sessionId,
|
|
21
|
+
asyncJobs: new Map(),
|
|
22
|
+
foregroundControls: new Map(),
|
|
23
|
+
lastForegroundControlId: null,
|
|
24
|
+
cleanupTimers: new Map(),
|
|
25
|
+
lastUiContext: ctx as SubagentState["lastUiContext"],
|
|
26
|
+
poller: null,
|
|
27
|
+
completionSeen: new Map(),
|
|
28
|
+
watcher: null,
|
|
29
|
+
watcherRestartTimer: null,
|
|
30
|
+
resultFileCoalescer: { schedule: () => false, clear: () => {} },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function writeRequest(input: { sessionId: string; runId: string; agent?: string; index?: number; message?: string }): string {
|
|
35
|
+
const agent = input.agent ?? "worker";
|
|
36
|
+
const index = input.index ?? 0;
|
|
37
|
+
const channelDir = resolveSupervisorChannelDir(input.runId, agent, index);
|
|
38
|
+
createdChannels.push(channelDir);
|
|
39
|
+
ensureSupervisorChannelDir(channelDir);
|
|
40
|
+
const requestId = randomUUID();
|
|
41
|
+
fs.writeFileSync(path.join(channelDir, "requests", `${requestId}.json`), JSON.stringify({
|
|
42
|
+
type: "subagent.supervisor.request",
|
|
43
|
+
id: requestId,
|
|
44
|
+
createdAt: Date.now(),
|
|
45
|
+
reason: "need_decision",
|
|
46
|
+
message: input.message ?? "Need a decision",
|
|
47
|
+
expectsReply: true,
|
|
48
|
+
orchestratorSessionId: input.sessionId,
|
|
49
|
+
orchestratorTarget: "shared-name",
|
|
50
|
+
runId: input.runId,
|
|
51
|
+
agent,
|
|
52
|
+
childIndex: index,
|
|
53
|
+
}, null, "\t"));
|
|
54
|
+
return requestId;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
afterEach(() => {
|
|
58
|
+
for (const channel of createdChannels.splice(0)) fs.rmSync(channel, { recursive: true, force: true });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
describe("native supervisor channel", () => {
|
|
62
|
+
it("delivers requests only to the exact current session id", () => {
|
|
63
|
+
const currentSessionId = `session-${randomUUID()}`;
|
|
64
|
+
const otherSessionId = `session-${randomUUID()}`;
|
|
65
|
+
const matchingId = writeRequest({ sessionId: currentSessionId, runId: `run-${randomUUID()}` });
|
|
66
|
+
const otherId = writeRequest({ sessionId: otherSessionId, runId: `run-${randomUUID()}` });
|
|
67
|
+
const sent: Array<{ content?: string; details?: { id?: string } }> = [];
|
|
68
|
+
const registeredTools: string[] = [];
|
|
69
|
+
const ctx = {
|
|
70
|
+
cwd: process.cwd(),
|
|
71
|
+
hasUI: false,
|
|
72
|
+
sessionManager: {
|
|
73
|
+
getSessionId: () => currentSessionId,
|
|
74
|
+
getSessionFile: () => null,
|
|
75
|
+
getEntries: () => [],
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
const pi = {
|
|
79
|
+
getAllTools: () => [],
|
|
80
|
+
registerTool: (tool: { name: string }) => { registeredTools.push(tool.name); },
|
|
81
|
+
sendMessage: (message: { content?: string; details?: { id?: string } }) => { sent.push(message); },
|
|
82
|
+
getSessionName: () => "shared-name",
|
|
83
|
+
};
|
|
84
|
+
const channel = createNativeSupervisorChannel(pi as never, makeState(currentSessionId, ctx));
|
|
85
|
+
|
|
86
|
+
assert.deepEqual(registeredTools, []);
|
|
87
|
+
channel.start();
|
|
88
|
+
channel.dispose();
|
|
89
|
+
|
|
90
|
+
assert.deepEqual(registeredTools, [NATIVE_SUPERVISOR_TOOL_NAME, "intercom"]);
|
|
91
|
+
assert.deepEqual(sent.map((message) => message.details?.id), [matchingId]);
|
|
92
|
+
assert.equal(channel.pending.has(matchingId), false, "disposed channel clears pending requests");
|
|
93
|
+
assert.equal(sent.some((message) => message.details?.id === otherId), false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("matches supervisor requests against the runtime session id instead of persisted session file path", () => {
|
|
97
|
+
const currentSessionId = `session-${randomUUID()}`;
|
|
98
|
+
const persistedSessionFile = path.join(os.tmpdir(), `${currentSessionId}.jsonl`);
|
|
99
|
+
const matchingId = writeRequest({ sessionId: currentSessionId, runId: `run-${randomUUID()}` });
|
|
100
|
+
const sent: Array<{ details?: { id?: string } }> = [];
|
|
101
|
+
const ctx = {
|
|
102
|
+
cwd: process.cwd(),
|
|
103
|
+
hasUI: false,
|
|
104
|
+
sessionManager: {
|
|
105
|
+
getSessionId: () => currentSessionId,
|
|
106
|
+
getSessionFile: () => persistedSessionFile,
|
|
107
|
+
getEntries: () => [],
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
const pi = {
|
|
111
|
+
getAllTools: () => [],
|
|
112
|
+
registerTool: () => {},
|
|
113
|
+
sendMessage: (message: { details?: { id?: string } }) => { sent.push(message); },
|
|
114
|
+
getSessionName: () => "shared-name",
|
|
115
|
+
};
|
|
116
|
+
const channel = createNativeSupervisorChannel(pi as never, makeState(persistedSessionFile, ctx));
|
|
117
|
+
|
|
118
|
+
channel.start();
|
|
119
|
+
channel.dispose();
|
|
120
|
+
|
|
121
|
+
assert.deepEqual(sent.map((message) => message.details?.id), [matchingId]);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("keeps an installed intercom tool and still exposes a native supervisor reply path", async () => {
|
|
125
|
+
const currentSessionId = `session-${randomUUID()}`;
|
|
126
|
+
const runId = `run-${randomUUID()}`;
|
|
127
|
+
const requestId = writeRequest({ sessionId: currentSessionId, runId });
|
|
128
|
+
const registeredTools = new Map<string, { execute: (_id: string, params: { action: string; replyTo?: string; message?: string }) => Promise<unknown> }>();
|
|
129
|
+
const ctx = {
|
|
130
|
+
cwd: process.cwd(),
|
|
131
|
+
hasUI: false,
|
|
132
|
+
sessionManager: {
|
|
133
|
+
getSessionId: () => currentSessionId,
|
|
134
|
+
getSessionFile: () => null,
|
|
135
|
+
getEntries: () => [],
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
const pi = {
|
|
139
|
+
getAllTools: () => [{ name: "intercom" }, ...[...registeredTools.keys()].map((name) => ({ name }))],
|
|
140
|
+
registerTool: (tool: { name: string; execute: (_id: string, params: { action: string; replyTo?: string; message?: string }) => Promise<unknown> }) => {
|
|
141
|
+
registeredTools.set(tool.name, tool);
|
|
142
|
+
},
|
|
143
|
+
sendMessage: () => {},
|
|
144
|
+
getSessionName: () => "shared-name",
|
|
145
|
+
};
|
|
146
|
+
const channel = createNativeSupervisorChannel(pi as never, makeState(currentSessionId, ctx));
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
assert.deepEqual([...registeredTools.keys()], []);
|
|
150
|
+
channel.start();
|
|
151
|
+
|
|
152
|
+
assert.deepEqual([...registeredTools.keys()], [NATIVE_SUPERVISOR_TOOL_NAME]);
|
|
153
|
+
await registeredTools.get(NATIVE_SUPERVISOR_TOOL_NAME)?.execute("reply", { action: "reply", replyTo: requestId, message: "Approved" });
|
|
154
|
+
const replyFile = path.join(resolveSupervisorChannelDir(runId, "worker", 0), "replies", `${requestId}.json`);
|
|
155
|
+
const reply = JSON.parse(fs.readFileSync(replyFile, "utf-8")) as { message?: string; requestId?: string };
|
|
156
|
+
assert.equal(reply.requestId, requestId);
|
|
157
|
+
assert.equal(reply.message, "Approved");
|
|
158
|
+
} finally {
|
|
159
|
+
channel.dispose();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
});
|