@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,209 @@
|
|
|
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 { afterEach, beforeEach, describe, it } from "node:test";
|
|
6
|
+
import { discoverAgentsAll } from "../../src/agents/agents.ts";
|
|
7
|
+
import { handleCreate } from "../../src/agents/agent-management.ts";
|
|
8
|
+
import { clearSkillCache, discoverAvailableSkills, resolveSkillPath } from "../../src/agents/skills.ts";
|
|
9
|
+
import { loadConfig } from "../../src/extension/config.ts";
|
|
10
|
+
import { diagnoseIntercomBridge, resolveIntercomBridge } from "../../src/intercom/intercom-bridge.ts";
|
|
11
|
+
import { loadRunsForAgent, recordRun } from "../../src/runs/shared/run-history.ts";
|
|
12
|
+
import { cleanupAllArtifactDirs } from "../../src/shared/artifacts.ts";
|
|
13
|
+
import { getAgentDir, getConfigDirName, getProjectConfigDir, resolveConfigDirName } from "../../src/shared/utils.ts";
|
|
14
|
+
|
|
15
|
+
let tempDir = "";
|
|
16
|
+
let agentDir = "";
|
|
17
|
+
let tempHome = "";
|
|
18
|
+
let cwd = "";
|
|
19
|
+
let oldAgentDir: string | undefined;
|
|
20
|
+
let oldHome: string | undefined;
|
|
21
|
+
let oldUserProfile: string | undefined;
|
|
22
|
+
|
|
23
|
+
function writeFile(filePath: string, content: string): void {
|
|
24
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
25
|
+
fs.writeFileSync(filePath, content, "utf-8");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function readText(result: { content: Array<{ type: string; text?: string }> }): string {
|
|
29
|
+
const first = result.content[0];
|
|
30
|
+
assert.ok(first);
|
|
31
|
+
assert.equal(first.type, "text");
|
|
32
|
+
assert.equal(typeof first.text, "string");
|
|
33
|
+
return first.text;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe("SELESAI_CODING_AGENT_DIR runtime paths", () => {
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
oldAgentDir = process.env.SELESAI_CODING_AGENT_DIR;
|
|
39
|
+
oldHome = process.env.HOME;
|
|
40
|
+
oldUserProfile = process.env.USERPROFILE;
|
|
41
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "pi-coding-agent-dir-"));
|
|
42
|
+
tempHome = path.join(tempDir, "home");
|
|
43
|
+
agentDir = path.join(tempDir, "agent");
|
|
44
|
+
cwd = path.join(tempDir, "workspace");
|
|
45
|
+
fs.mkdirSync(cwd, { recursive: true });
|
|
46
|
+
fs.mkdirSync(tempHome, { recursive: true });
|
|
47
|
+
process.env.HOME = tempHome;
|
|
48
|
+
process.env.USERPROFILE = tempHome;
|
|
49
|
+
process.env.SELESAI_CODING_AGENT_DIR = agentDir;
|
|
50
|
+
clearSkillCache();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
if (oldAgentDir === undefined) delete process.env.SELESAI_CODING_AGENT_DIR;
|
|
55
|
+
else process.env.SELESAI_CODING_AGENT_DIR = oldAgentDir;
|
|
56
|
+
if (oldHome === undefined) delete process.env.HOME;
|
|
57
|
+
else process.env.HOME = oldHome;
|
|
58
|
+
if (oldUserProfile === undefined) delete process.env.USERPROFILE;
|
|
59
|
+
else process.env.USERPROFILE = oldUserProfile;
|
|
60
|
+
clearSkillCache();
|
|
61
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("resolves the agent dir dynamically and loads extension config from it", () => {
|
|
65
|
+
assert.equal(resolveConfigDirName({ CONFIG_DIR_NAME: ".custom-pi" }), ".custom-pi");
|
|
66
|
+
assert.equal(resolveConfigDirName({ CONFIG_DIR_NAME: "" }), ".selesai");
|
|
67
|
+
assert.equal(getConfigDirName(), ".selesai");
|
|
68
|
+
assert.equal(getProjectConfigDir(cwd), path.join(cwd, ".selesai"));
|
|
69
|
+
assert.equal(getAgentDir(), agentDir);
|
|
70
|
+
|
|
71
|
+
process.env.SELESAI_CODING_AGENT_DIR = "~";
|
|
72
|
+
assert.equal(getAgentDir(), tempHome);
|
|
73
|
+
|
|
74
|
+
process.env.SELESAI_CODING_AGENT_DIR = "~/custom-agent-dir";
|
|
75
|
+
assert.equal(getAgentDir(), path.join(tempHome, "custom-agent-dir"));
|
|
76
|
+
|
|
77
|
+
delete process.env.SELESAI_CODING_AGENT_DIR;
|
|
78
|
+
assert.equal(getAgentDir(), path.join(tempHome, ".selesai", "agent"));
|
|
79
|
+
|
|
80
|
+
process.env.SELESAI_CODING_AGENT_DIR = agentDir;
|
|
81
|
+
const configPath = path.join(agentDir, "extensions", "subagent", "config.json");
|
|
82
|
+
writeFile(configPath, JSON.stringify({ asyncByDefault: true, maxSubagentDepth: 3 }));
|
|
83
|
+
|
|
84
|
+
const config = loadConfig();
|
|
85
|
+
assert.equal(config.asyncByDefault, true);
|
|
86
|
+
assert.equal(config.maxSubagentDepth, 3);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("discovers user agents, chains, and settings under the configured agent dir", () => {
|
|
90
|
+
const settingsPath = path.join(agentDir, "settings.json");
|
|
91
|
+
writeFile(path.join(agentDir, "agents", "env-agent.md"), `---
|
|
92
|
+
name: env-agent
|
|
93
|
+
description: Env agent
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
Use env agent.
|
|
97
|
+
`);
|
|
98
|
+
writeFile(path.join(agentDir, "chains", "env-chain.chain.md"), `---
|
|
99
|
+
name: env-chain
|
|
100
|
+
description: Env chain
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## env-agent
|
|
104
|
+
|
|
105
|
+
Inspect env.
|
|
106
|
+
`);
|
|
107
|
+
writeFile(settingsPath, JSON.stringify({
|
|
108
|
+
subagents: {
|
|
109
|
+
agentOverrides: {
|
|
110
|
+
worker: { systemPrompt: "Use env-rooted settings." },
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
}, null, 2));
|
|
114
|
+
|
|
115
|
+
const discovered = discoverAgentsAll(cwd);
|
|
116
|
+
assert.equal(discovered.userDir, path.join(agentDir, "agents"));
|
|
117
|
+
assert.equal(discovered.userChainDir, path.join(agentDir, "chains"));
|
|
118
|
+
assert.equal(discovered.userSettingsPath, settingsPath);
|
|
119
|
+
assert.ok(discovered.user.find((agent) => agent.name === "env-agent" && agent.filePath === path.join(agentDir, "agents", "env-agent.md")));
|
|
120
|
+
assert.ok(discovered.chains.find((chain) => chain.name === "env-chain" && chain.filePath === path.join(agentDir, "chains", "env-chain.chain.md")));
|
|
121
|
+
|
|
122
|
+
const worker = discovered.builtin.find((agent) => agent.name === "worker");
|
|
123
|
+
assert.equal(worker?.systemPrompt, "Use env-rooted settings.");
|
|
124
|
+
assert.equal(worker?.override?.path, settingsPath);
|
|
125
|
+
assert.equal(worker?.override?.scope, "user");
|
|
126
|
+
|
|
127
|
+
const createdName = "created-env-agent";
|
|
128
|
+
const created = handleCreate(
|
|
129
|
+
{ config: { name: createdName, description: "Created in env dir", scope: "user" } },
|
|
130
|
+
{ cwd, modelRegistry: { getAvailable: () => [] } },
|
|
131
|
+
);
|
|
132
|
+
assert.equal(created.isError, false, readText(created));
|
|
133
|
+
assert.equal(fs.existsSync(path.join(agentDir, "agents", `${createdName}.md`)), true);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("resolves user skills, settings skills, and package skills from the configured agent dir", () => {
|
|
137
|
+
writeFile(path.join(agentDir, "skills", "env-skill", "SKILL.md"), `---
|
|
138
|
+
description: Env skill
|
|
139
|
+
---
|
|
140
|
+
Env skill content.
|
|
141
|
+
`);
|
|
142
|
+
writeFile(path.join(agentDir, "settings-skill.md"), `---
|
|
143
|
+
description: Settings skill
|
|
144
|
+
---
|
|
145
|
+
Settings skill content.
|
|
146
|
+
`);
|
|
147
|
+
const packageRoot = path.join(agentDir, "packages", "env-package");
|
|
148
|
+
writeFile(path.join(packageRoot, "package.json"), JSON.stringify({ name: "env-package", pi: { skills: ["./skills/package-skill.md"] } }, null, 2));
|
|
149
|
+
writeFile(path.join(packageRoot, "skills", "package-skill.md"), `---
|
|
150
|
+
description: Package skill
|
|
151
|
+
---
|
|
152
|
+
Package skill content.
|
|
153
|
+
`);
|
|
154
|
+
writeFile(path.join(agentDir, "settings.json"), JSON.stringify({
|
|
155
|
+
skills: ["./settings-skill.md"],
|
|
156
|
+
packages: ["file:./packages/env-package"],
|
|
157
|
+
}, null, 2));
|
|
158
|
+
|
|
159
|
+
clearSkillCache();
|
|
160
|
+
assert.deepEqual(resolveSkillPath("env-skill", cwd), { path: path.join(agentDir, "skills", "env-skill", "SKILL.md"), source: "user" });
|
|
161
|
+
assert.deepEqual(resolveSkillPath("settings-skill", cwd), { path: path.join(agentDir, "settings-skill.md"), source: "user-settings" });
|
|
162
|
+
assert.deepEqual(resolveSkillPath("package-skill", cwd), { path: path.join(packageRoot, "skills", "package-skill.md"), source: "user-package" });
|
|
163
|
+
|
|
164
|
+
const available = discoverAvailableSkills(cwd);
|
|
165
|
+
assert.ok(available.find((skill) => skill.name === "env-skill" && skill.source === "user"));
|
|
166
|
+
assert.ok(available.find((skill) => skill.name === "settings-skill" && skill.source === "user-settings"));
|
|
167
|
+
assert.ok(available.find((skill) => skill.name === "package-skill" && skill.source === "user-package"));
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("records run history and cleans session artifacts under the configured agent dir", () => {
|
|
171
|
+
recordRun("env-agent", "Inspect", 0, 42);
|
|
172
|
+
const historyPath = path.join(agentDir, "run-history.jsonl");
|
|
173
|
+
assert.equal(fs.existsSync(historyPath), true);
|
|
174
|
+
const history = loadRunsForAgent("env-agent");
|
|
175
|
+
assert.equal(history.length, 1);
|
|
176
|
+
assert.equal(history[0]?.task, "Inspect");
|
|
177
|
+
assert.equal(history[0]?.status, "ok");
|
|
178
|
+
|
|
179
|
+
const artifactPath = path.join(agentDir, "sessions", "session-1", "subagent-artifacts", "old_output.md");
|
|
180
|
+
writeFile(artifactPath, "old output");
|
|
181
|
+
const oldTime = new Date(Date.now() - 60_000);
|
|
182
|
+
fs.utimesSync(artifactPath, oldTime, oldTime);
|
|
183
|
+
|
|
184
|
+
cleanupAllArtifactDirs(0);
|
|
185
|
+
assert.equal(fs.existsSync(artifactPath), false);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("uses the configured agent dir for subagent bridge instruction files", () => {
|
|
189
|
+
const instructionPath = path.join(agentDir, "extensions", "subagent", "bridge.md");
|
|
190
|
+
writeFile(instructionPath, "Native bridge for {orchestratorTarget}");
|
|
191
|
+
|
|
192
|
+
const diagnostic = diagnoseIntercomBridge({
|
|
193
|
+
config: { mode: "always" },
|
|
194
|
+
context: "fresh",
|
|
195
|
+
orchestratorTarget: "main",
|
|
196
|
+
});
|
|
197
|
+
assert.equal(diagnostic.active, true);
|
|
198
|
+
assert.equal(diagnostic.extensionDir, "native:pi-subagents-supervisor-channel");
|
|
199
|
+
|
|
200
|
+
const bridge = resolveIntercomBridge({
|
|
201
|
+
config: { mode: "always", instructionFile: "bridge.md" },
|
|
202
|
+
context: "fresh",
|
|
203
|
+
orchestratorTarget: "main",
|
|
204
|
+
});
|
|
205
|
+
assert.equal(bridge.active, true);
|
|
206
|
+
assert.equal(bridge.extensionDir, "native:pi-subagents-supervisor-channel");
|
|
207
|
+
assert.match(bridge.instruction, /Native bridge for main/);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -0,0 +1,238 @@
|
|
|
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 { describe, it } from "node:test";
|
|
6
|
+
import {
|
|
7
|
+
getSelesaiSpawnCommand,
|
|
8
|
+
resolveWindowsSelesaiCliScript,
|
|
9
|
+
type SelesaiSpawnDeps,
|
|
10
|
+
} from "../../src/runs/shared/pi-spawn.ts";
|
|
11
|
+
|
|
12
|
+
function makeDeps(input: {
|
|
13
|
+
platform?: NodeJS.Platform;
|
|
14
|
+
execPath?: string;
|
|
15
|
+
argv1?: string;
|
|
16
|
+
existing?: string[];
|
|
17
|
+
packageJsonPath?: string;
|
|
18
|
+
packageJsonContent?: string;
|
|
19
|
+
packageEntry?: string;
|
|
20
|
+
env?: NodeJS.ProcessEnv;
|
|
21
|
+
}): SelesaiSpawnDeps {
|
|
22
|
+
const existing = new Set(input.existing ?? []);
|
|
23
|
+
const packageJsonPath = input.packageJsonPath;
|
|
24
|
+
const packageJsonContent = input.packageJsonContent;
|
|
25
|
+
return {
|
|
26
|
+
platform: input.platform,
|
|
27
|
+
execPath: input.execPath,
|
|
28
|
+
argv1: input.argv1,
|
|
29
|
+
existsSync: (filePath) => existing.has(filePath),
|
|
30
|
+
readFileSync: (_filePath, _encoding) => {
|
|
31
|
+
if (!packageJsonPath || !packageJsonContent) {
|
|
32
|
+
throw new Error("package json not configured");
|
|
33
|
+
}
|
|
34
|
+
return packageJsonContent;
|
|
35
|
+
},
|
|
36
|
+
resolvePackageJson: packageJsonPath ? () => packageJsonPath : undefined,
|
|
37
|
+
resolvePackageEntry: input.packageEntry
|
|
38
|
+
? () => input.packageEntry!
|
|
39
|
+
: undefined,
|
|
40
|
+
env: input.env ?? {},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe("getSelesaiSpawnCommand", () => {
|
|
45
|
+
it("honors explicit SELESAI_SUBAGENT_PI_BINARY override on any platform", () => {
|
|
46
|
+
const args = ["--mode", "json", "Task: check output"];
|
|
47
|
+
const result = getSelesaiSpawnCommand(args, {
|
|
48
|
+
platform: "win32",
|
|
49
|
+
execPath: "/usr/local/bin/node",
|
|
50
|
+
argv1: "/tmp/pi-entry.mjs",
|
|
51
|
+
env: {
|
|
52
|
+
SELESAI_SUBAGENT_PI_BINARY: "/nix/store/pi-wrapper/bin/nhost-code-agent",
|
|
53
|
+
},
|
|
54
|
+
existsSync: () => true,
|
|
55
|
+
});
|
|
56
|
+
assert.deepEqual(result, {
|
|
57
|
+
command: "/nix/store/pi-wrapper/bin/nhost-code-agent",
|
|
58
|
+
args,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("ignores a blank SELESAI_SUBAGENT_PI_BINARY override", () => {
|
|
63
|
+
const args = ["--mode", "json", "Task: check output"];
|
|
64
|
+
const result = getSelesaiSpawnCommand(args, {
|
|
65
|
+
platform: "darwin",
|
|
66
|
+
env: { SELESAI_SUBAGENT_PI_BINARY: " " },
|
|
67
|
+
});
|
|
68
|
+
assert.deepEqual(result, { command: "selesai", args });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("uses plain pi on non-Windows even when argv1 is a runnable JS file", () => {
|
|
72
|
+
const argv1 = "/tmp/pi-entry.mjs";
|
|
73
|
+
const deps = makeDeps({
|
|
74
|
+
platform: "darwin",
|
|
75
|
+
execPath: "/usr/local/bin/node",
|
|
76
|
+
argv1,
|
|
77
|
+
existing: [argv1],
|
|
78
|
+
});
|
|
79
|
+
const args = ["--mode", "json", "Task: check output"];
|
|
80
|
+
const result = getSelesaiSpawnCommand(args, deps);
|
|
81
|
+
assert.deepEqual(result, { command: "selesai", args });
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("uses plain pi on non-Windows even when the CLI script can be resolved from package bin", () => {
|
|
85
|
+
const packageJsonPath = "/opt/pi/package.json";
|
|
86
|
+
const cliPath = path.resolve(
|
|
87
|
+
path.dirname(packageJsonPath),
|
|
88
|
+
"dist/cli/index.js",
|
|
89
|
+
);
|
|
90
|
+
const deps = makeDeps({
|
|
91
|
+
platform: "darwin",
|
|
92
|
+
execPath: "/usr/local/bin/node",
|
|
93
|
+
argv1: "/opt/pi/subagent-runner.ts",
|
|
94
|
+
packageJsonPath,
|
|
95
|
+
packageJsonContent: JSON.stringify({ bin: { selesai: "dist/cli/index.js" } }),
|
|
96
|
+
existing: [packageJsonPath, cliPath],
|
|
97
|
+
});
|
|
98
|
+
const args = ["-p", "Task: hello"];
|
|
99
|
+
const result = getSelesaiSpawnCommand(args, deps);
|
|
100
|
+
assert.deepEqual(result, { command: "selesai", args });
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("falls back to plain pi command on non-Windows when CLI script cannot be resolved", () => {
|
|
104
|
+
const args = ["--mode", "json", "Task: check output"];
|
|
105
|
+
const result = getSelesaiSpawnCommand(args, { platform: "darwin", env: {} });
|
|
106
|
+
assert.deepEqual(result, { command: "selesai", args });
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("uses node + argv1 script on Windows when argv1 is runnable JS", () => {
|
|
110
|
+
const argv1 = "/tmp/pi-entry.mjs";
|
|
111
|
+
const deps = makeDeps({
|
|
112
|
+
platform: "win32",
|
|
113
|
+
execPath: "/usr/local/bin/node",
|
|
114
|
+
argv1,
|
|
115
|
+
existing: [argv1],
|
|
116
|
+
});
|
|
117
|
+
const args = [
|
|
118
|
+
"--mode",
|
|
119
|
+
"json",
|
|
120
|
+
'Task: Read C:/dev/file.md and review "quotes" & pipes | too',
|
|
121
|
+
];
|
|
122
|
+
const result = getSelesaiSpawnCommand(args, deps);
|
|
123
|
+
assert.equal(result.command, "/usr/local/bin/node");
|
|
124
|
+
assert.equal(result.args[0], argv1);
|
|
125
|
+
assert.equal(result.args[3], args[2]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("resolves CLI script from package bin when argv1 is not runnable JS", () => {
|
|
129
|
+
const packageJsonPath = "/opt/pi/package.json";
|
|
130
|
+
// Compute expected path the same way the production code does:
|
|
131
|
+
// path.resolve(path.dirname(packageJsonPath), binPath) — which on Windows
|
|
132
|
+
// prepends the current drive letter to POSIX absolute paths.
|
|
133
|
+
const cliPath = path.resolve(
|
|
134
|
+
path.dirname(packageJsonPath),
|
|
135
|
+
"dist/cli/index.js",
|
|
136
|
+
);
|
|
137
|
+
const deps = makeDeps({
|
|
138
|
+
platform: "win32",
|
|
139
|
+
execPath: "/usr/local/bin/node",
|
|
140
|
+
argv1: "/opt/pi/subagent-runner.ts",
|
|
141
|
+
packageJsonPath,
|
|
142
|
+
packageJsonContent: JSON.stringify({ bin: { selesai: "dist/cli/index.js" } }),
|
|
143
|
+
existing: [packageJsonPath, cliPath],
|
|
144
|
+
});
|
|
145
|
+
const result = getSelesaiSpawnCommand(["-p", "Task: hello"], deps);
|
|
146
|
+
assert.equal(result.command, "/usr/local/bin/node");
|
|
147
|
+
assert.equal(result.args[0], cliPath);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("falls back to pi when Windows CLI script cannot be resolved", () => {
|
|
151
|
+
const deps = makeDeps({
|
|
152
|
+
platform: "win32",
|
|
153
|
+
argv1: "/opt/pi/subagent-runner.ts",
|
|
154
|
+
existing: [],
|
|
155
|
+
});
|
|
156
|
+
const args = ["-p", "Task: hello"];
|
|
157
|
+
const result = getSelesaiSpawnCommand(args, deps);
|
|
158
|
+
assert.deepEqual(result, { command: "selesai", args });
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("walks from package main entry to resolve package bin", () => {
|
|
162
|
+
const tempDir = fs.mkdtempSync(
|
|
163
|
+
path.join(os.tmpdir(), "pi-spawn-package-root-"),
|
|
164
|
+
);
|
|
165
|
+
try {
|
|
166
|
+
const packageRoot = path.join(
|
|
167
|
+
tempDir,
|
|
168
|
+
"node_modules",
|
|
169
|
+
"@selesai",
|
|
170
|
+
"code",
|
|
171
|
+
);
|
|
172
|
+
const entry = path.join(packageRoot, "dist", "index.js");
|
|
173
|
+
const cliPath = path.join(packageRoot, "dist", "cli", "index.js");
|
|
174
|
+
fs.mkdirSync(path.dirname(entry), { recursive: true });
|
|
175
|
+
fs.mkdirSync(path.dirname(cliPath), { recursive: true });
|
|
176
|
+
fs.writeFileSync(entry, "export {};\n");
|
|
177
|
+
fs.writeFileSync(cliPath, "#!/usr/bin/env node\n");
|
|
178
|
+
fs.writeFileSync(
|
|
179
|
+
path.join(packageRoot, "package.json"),
|
|
180
|
+
JSON.stringify({
|
|
181
|
+
name: "@selesai/code",
|
|
182
|
+
bin: { selesai: "dist/cli/index.js" },
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
185
|
+
const result = getSelesaiSpawnCommand(["-p", "Task: hello"], {
|
|
186
|
+
platform: "win32",
|
|
187
|
+
execPath: "/usr/local/bin/node",
|
|
188
|
+
argv1: "/opt/pi/subagent-runner.ts",
|
|
189
|
+
resolvePackageEntry: () => entry,
|
|
190
|
+
env: {},
|
|
191
|
+
});
|
|
192
|
+
assert.equal(result.command, "/usr/local/bin/node");
|
|
193
|
+
assert.equal(result.args[0], cliPath);
|
|
194
|
+
} finally {
|
|
195
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
describe("getSelesaiSpawnCommand with piPackageRoot", () => {
|
|
201
|
+
it("resolves CLI script via piPackageRoot when argv1 is not runnable", () => {
|
|
202
|
+
const packageJsonPath = "/opt/pi/package.json";
|
|
203
|
+
const cliPath = path.resolve(
|
|
204
|
+
path.dirname(packageJsonPath),
|
|
205
|
+
"dist/cli/index.js",
|
|
206
|
+
);
|
|
207
|
+
const deps = makeDeps({
|
|
208
|
+
platform: "win32",
|
|
209
|
+
execPath: "/usr/local/bin/node",
|
|
210
|
+
argv1: "/opt/pi/subagent-runner.ts",
|
|
211
|
+
packageJsonPath,
|
|
212
|
+
packageJsonContent: JSON.stringify({ bin: { selesai: "dist/cli/index.js" } }),
|
|
213
|
+
existing: [packageJsonPath, cliPath],
|
|
214
|
+
});
|
|
215
|
+
deps.piPackageRoot = "/opt/pi";
|
|
216
|
+
const result = getSelesaiSpawnCommand(["-p", "Task: hello"], deps);
|
|
217
|
+
assert.equal(result.command, "/usr/local/bin/node");
|
|
218
|
+
assert.equal(result.args[0], cliPath);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe("resolveWindowsSelesaiCliScript", () => {
|
|
223
|
+
it("supports package bin as string", () => {
|
|
224
|
+
const packageJsonPath = "/opt/pi/package.json";
|
|
225
|
+
const cliPath = path.resolve(
|
|
226
|
+
path.dirname(packageJsonPath),
|
|
227
|
+
"dist/cli/index.mjs",
|
|
228
|
+
);
|
|
229
|
+
const deps = makeDeps({
|
|
230
|
+
platform: "win32",
|
|
231
|
+
argv1: "/opt/pi/subagent-runner.ts",
|
|
232
|
+
packageJsonPath,
|
|
233
|
+
packageJsonContent: JSON.stringify({ bin: "dist/cli/index.mjs" }),
|
|
234
|
+
existing: [packageJsonPath, cliPath],
|
|
235
|
+
});
|
|
236
|
+
assert.equal(resolveWindowsSelesaiCliScript(deps), cliPath);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import type { AgentConfig, ChainConfig } from "../../src/agents/agents.ts";
|
|
4
|
+
import {
|
|
5
|
+
buildProactiveSkillSubagentRecommendationLines,
|
|
6
|
+
formatProactiveSkillSubagentRecommendations,
|
|
7
|
+
recommendProactiveSkillSubagents,
|
|
8
|
+
resolveProactiveSkillSubagentsConfig,
|
|
9
|
+
} from "../../src/agents/proactive-skills.ts";
|
|
10
|
+
|
|
11
|
+
function agent(name: string, skills?: string[], disabled = false): AgentConfig {
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
description: `${name} agent`,
|
|
15
|
+
systemPrompt: "",
|
|
16
|
+
systemPromptMode: "replace",
|
|
17
|
+
inheritProjectContext: false,
|
|
18
|
+
inheritSkills: false,
|
|
19
|
+
source: "project",
|
|
20
|
+
filePath: `/tmp/${name}.md`,
|
|
21
|
+
...(skills ? { skills } : {}),
|
|
22
|
+
...(disabled ? { disabled } : {}),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function chain(name: string, skills: string[]): ChainConfig {
|
|
27
|
+
return {
|
|
28
|
+
name,
|
|
29
|
+
description: `${name} chain`,
|
|
30
|
+
source: "project",
|
|
31
|
+
filePath: `/tmp/${name}.chain.md`,
|
|
32
|
+
steps: [{ agent: "worker", skills }],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe("proactive skill subagent recommendations", () => {
|
|
37
|
+
it("recommends available skills referenced by multiple enabled configs", () => {
|
|
38
|
+
const recommendations = recommendProactiveSkillSubagents({
|
|
39
|
+
agents: [
|
|
40
|
+
agent("reviewer"),
|
|
41
|
+
agent("ui-reviewer", ["accessibility"]),
|
|
42
|
+
agent("disabled-reviewer", ["accessibility"], true),
|
|
43
|
+
],
|
|
44
|
+
chains: [chain("ui-check", ["accessibility"]), chain("cleanup", ["deslop"])],
|
|
45
|
+
availableSkills: [
|
|
46
|
+
{ name: "accessibility", description: "Accessibility review." },
|
|
47
|
+
{ name: "deslop", description: "Cleanup review." },
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
assert.equal(recommendations.length, 1);
|
|
52
|
+
assert.equal(recommendations[0]?.skill, "accessibility");
|
|
53
|
+
assert.equal(recommendations[0]?.agent, "reviewer");
|
|
54
|
+
assert.equal(recommendations[0]?.references, 2);
|
|
55
|
+
assert.deepEqual(recommendations[0]?.sources, ["agent:ui-reviewer", "chain:ui-check"]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("filters unavailable orchestration skills and honors config bounds", () => {
|
|
59
|
+
const recommendations = recommendProactiveSkillSubagents({
|
|
60
|
+
agents: [
|
|
61
|
+
agent("delegate", ["pi-subagents", "alpha", "beta"]),
|
|
62
|
+
agent("one", ["alpha", "beta"]),
|
|
63
|
+
agent("two", ["gamma"]),
|
|
64
|
+
agent("three", ["gamma"]),
|
|
65
|
+
],
|
|
66
|
+
availableSkills: [{ name: "alpha" }, { name: "beta" }, { name: "gamma" }],
|
|
67
|
+
config: { preferredAgent: "delegate", maxRecommendations: 2 },
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
assert.deepEqual(recommendations.map((entry) => entry.skill), ["alpha", "beta"]);
|
|
71
|
+
assert.ok(recommendations.every((entry) => entry.agent === "delegate"));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("can be disabled and formats guardrails for visible suggestions", () => {
|
|
75
|
+
assert.equal(resolveProactiveSkillSubagentsConfig(false).enabled, false);
|
|
76
|
+
assert.deepEqual(recommendProactiveSkillSubagents({
|
|
77
|
+
agents: [agent("reviewer", ["deslop"]), agent("cleanup", ["deslop"])],
|
|
78
|
+
availableSkills: [{ name: "deslop" }],
|
|
79
|
+
config: false,
|
|
80
|
+
}), []);
|
|
81
|
+
|
|
82
|
+
const lines = formatProactiveSkillSubagentRecommendations([
|
|
83
|
+
{
|
|
84
|
+
skill: "deslop",
|
|
85
|
+
agent: "reviewer",
|
|
86
|
+
references: 2,
|
|
87
|
+
sources: ["agent:a", "chain:b"],
|
|
88
|
+
reason: "referenced by 2 configured agents/chains",
|
|
89
|
+
},
|
|
90
|
+
]);
|
|
91
|
+
assert.match(lines.join("\n"), /Proactive skill subagent suggestions:/);
|
|
92
|
+
assert.match(lines.join("\n"), /fresh context/);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("does not discover skills when disabled and treats discovery failures as no suggestions", () => {
|
|
96
|
+
let discoveryCalls = 0;
|
|
97
|
+
const disabledLines = buildProactiveSkillSubagentRecommendationLines({
|
|
98
|
+
agents: [agent("reviewer", ["deslop"]), agent("cleanup", ["deslop"])],
|
|
99
|
+
config: false,
|
|
100
|
+
discoverAvailableSkills: () => {
|
|
101
|
+
discoveryCalls++;
|
|
102
|
+
throw new Error("should not discover when disabled");
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
assert.deepEqual(disabledLines, []);
|
|
106
|
+
assert.equal(discoveryCalls, 0);
|
|
107
|
+
|
|
108
|
+
const failedDiscoveryLines = buildProactiveSkillSubagentRecommendationLines({
|
|
109
|
+
agents: [agent("reviewer", ["deslop"]), agent("cleanup", ["deslop"])],
|
|
110
|
+
discoverAvailableSkills: () => {
|
|
111
|
+
discoveryCalls++;
|
|
112
|
+
throw new Error("skill scan failed");
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
assert.deepEqual(failedDiscoveryLines, []);
|
|
116
|
+
assert.equal(discoveryCalls, 1);
|
|
117
|
+
});
|
|
118
|
+
});
|