@oyasmi/pipiclaw 0.9.3 → 0.9.4-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/builtin-commands.d.ts +19 -0
- package/dist/agent/builtin-commands.js +80 -0
- package/dist/agent/channel-runner.d.ts +20 -208
- package/dist/agent/channel-runner.js +167 -1188
- package/dist/agent/maintenance-context.d.ts +1 -1
- package/dist/agent/maintenance-context.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +45 -64
- package/dist/agent/prompt/resources.d.ts +3 -0
- package/dist/agent/prompt/resources.js +11 -2
- package/dist/agent/runner-factory.d.ts +1 -43
- package/dist/agent/{command-extension.d.ts → session/command-extension.d.ts} +4 -0
- package/dist/agent/{command-extension.js → session/command-extension.js} +48 -35
- package/dist/agent/{type-guards.d.ts → session/event-guards.d.ts} +2 -2
- package/dist/agent/{type-guards.js → session/event-guards.js} +5 -1
- package/dist/agent/session/model-selection.d.ts +47 -0
- package/dist/agent/session/model-selection.js +99 -0
- package/dist/agent/{session-adapter.d.ts → session/session-adapter.d.ts} +21 -1
- package/dist/agent/session/session-adapter.js +159 -0
- package/dist/agent/{session-events.d.ts → session/session-events.d.ts} +9 -5
- package/dist/agent/{session-events.js → session/session-events.js} +24 -13
- package/dist/agent/session/session-host.d.ts +200 -0
- package/dist/agent/session/session-host.js +621 -0
- package/dist/agent/{session-resource-gate.js → session/session-resource-gate.js} +5 -3
- package/dist/agent/status-render.d.ts +0 -1
- package/dist/agent/status-render.js +4 -16
- package/dist/agent/{context-budget.js → turn/context-budget.js} +5 -1
- package/dist/agent/{progress-formatter.d.ts → turn/progress-formatter.d.ts} +4 -1
- package/dist/agent/{run-queue.d.ts → turn/run-queue.d.ts} +1 -1
- package/dist/agent/{run-queue.js → turn/run-queue.js} +10 -5
- package/dist/{memory → agent/turn}/task-digest.js +4 -4
- package/dist/agent/turn/turn-context.d.ts +14 -0
- package/dist/agent/turn/turn-context.js +64 -0
- package/dist/agent/turn/turn-error.d.ts +31 -0
- package/dist/agent/turn/turn-error.js +68 -0
- package/dist/agent/turn/turn-finish.d.ts +50 -0
- package/dist/agent/turn/turn-finish.js +188 -0
- package/dist/agent/turn/turn-input.d.ts +43 -0
- package/dist/agent/turn/turn-input.js +79 -0
- package/dist/agent/turn/turn-pipeline.d.ts +68 -0
- package/dist/agent/turn/turn-pipeline.js +257 -0
- package/dist/agent/{turn-prompt.d.ts → turn/turn-prompt.d.ts} +2 -2
- package/dist/agent/{turn-prompt.js → turn/turn-prompt.js} +6 -2
- package/dist/agent/{turn-recovery.js → turn/turn-recovery.js} +1 -1
- package/dist/agent/{turn-state.d.ts → turn/turn-state.d.ts} +1 -1
- package/dist/agent/types.d.ts +43 -2
- package/dist/agent/types.js +1 -1
- package/dist/{models/auth-cli.d.ts → app/auth-command.d.ts} +1 -1
- package/dist/{models/auth-cli.js → app/auth-command.js} +14 -10
- package/dist/{runtime/app-home.d.ts → app/home.d.ts} +6 -2
- package/dist/{runtime/app-home.js → app/home.js} +22 -75
- package/dist/{runtime → app}/proxy.js +4 -2
- package/dist/{app-services.d.ts → app/services.d.ts} +5 -5
- package/dist/{app-services.js → app/services.js} +17 -14
- package/dist/channel/channel-context.d.ts +12 -2
- package/dist/channel/channel-context.js +29 -2
- package/dist/channel/channel-event.d.ts +10 -2
- package/dist/channel/channel-event.js +1 -1
- package/dist/channel/channel-index.js +4 -1
- package/dist/{runtime/project-commands.d.ts → channel/commands.d.ts} +1 -1
- package/dist/{runtime/project-commands.js → channel/commands.js} +17 -16
- package/dist/channel/project-scope-store.js +1 -1
- package/dist/channel/store.js +4 -0
- package/dist/commands/catalog.d.ts +24 -7
- package/dist/commands/catalog.js +91 -44
- package/dist/commands/reply-limits.d.ts +6 -0
- package/dist/commands/reply-limits.js +24 -0
- package/dist/{runtime/report-commands.d.ts → commands/router.d.ts} +10 -3
- package/dist/{runtime/report-commands.js → commands/router.js} +6 -6
- package/dist/{settings.d.ts → config/settings.d.ts} +10 -10
- package/dist/{settings.js → config/settings.js} +11 -11
- package/dist/{tools/config.d.ts → config/tools.d.ts} +1 -2
- package/dist/{tools/config.js → config/tools.js} +5 -2
- package/dist/dingtalk/access-token.d.ts +12 -0
- package/dist/dingtalk/access-token.js +51 -0
- package/dist/dingtalk/api.d.ts +19 -0
- package/dist/dingtalk/api.js +67 -0
- package/dist/dingtalk/bot.d.ts +97 -0
- package/dist/dingtalk/bot.js +389 -0
- package/dist/dingtalk/cards.d.ts +56 -0
- package/dist/dingtalk/cards.js +318 -0
- package/dist/{runtime → dingtalk}/channel-queue.js +4 -1
- package/dist/dingtalk/config.d.ts +19 -0
- package/dist/dingtalk/config.js +95 -0
- package/dist/dingtalk/connection.d.ts +57 -0
- package/dist/dingtalk/connection.js +356 -0
- package/dist/dingtalk/conversation-meta.d.ts +16 -0
- package/dist/dingtalk/conversation-meta.js +77 -0
- package/dist/{runtime → dingtalk}/delivery.d.ts +6 -2
- package/dist/{runtime → dingtalk}/delivery.js +29 -15
- package/dist/dingtalk/handler.d.ts +90 -0
- package/dist/dingtalk/handler.js +1 -0
- package/dist/dingtalk/inbound.d.ts +66 -0
- package/dist/dingtalk/inbound.js +137 -0
- package/dist/dingtalk/media.d.ts +66 -0
- package/dist/dingtalk/media.js +214 -0
- package/dist/events/{event-commands.js → commands.js} +99 -45
- package/dist/events/parse.d.ts +14 -0
- package/dist/events/parse.js +114 -0
- package/dist/events/types.d.ts +93 -0
- package/dist/events/types.js +1 -0
- package/dist/events/{event-validation.d.ts → validation.d.ts} +14 -3
- package/dist/events/{event-validation.js → validation.js} +17 -9
- package/dist/events/watcher.d.ts +67 -0
- package/dist/events/{events.js → watcher.js} +63 -121
- package/dist/executor.js +2 -2
- package/dist/index.d.ts +6 -4
- package/dist/index.js +2 -2
- package/dist/jobs/launch.d.ts +42 -0
- package/dist/jobs/launch.js +118 -0
- package/dist/{agent/job-manager.d.ts → jobs/manager.d.ts} +1 -67
- package/dist/{agent/job-manager.js → jobs/manager.js} +34 -157
- package/dist/jobs/record.d.ts +55 -0
- package/dist/jobs/record.js +36 -0
- package/dist/log.d.ts +12 -2
- package/dist/log.js +26 -34
- package/dist/main.js +3 -3
- package/dist/memory/commands.js +29 -23
- package/dist/memory/lifecycle.js +26 -5
- package/dist/memory/maintenance-gates.d.ts +2 -2
- package/dist/memory/maintenance-state.js +4 -1
- package/dist/memory/maintenance-tuning.d.ts +15 -0
- package/dist/memory/maintenance-tuning.js +3 -0
- package/dist/memory/reflect-job.d.ts +2 -2
- package/dist/memory/reflect-job.js +4 -2
- package/dist/memory/scheduler.d.ts +3 -3
- package/dist/memory/scheduler.js +5 -2
- package/dist/memory/sidecar-worker.js +1 -1
- package/dist/memory/transcript.js +1 -1
- package/dist/{agent/model-fallback.d.ts → models/fallback.d.ts} +6 -6
- package/dist/{agent/model-fallback.js → models/fallback.js} +15 -28
- package/dist/models/login-identity.d.ts +2 -0
- package/dist/models/login-identity.js +83 -0
- package/dist/models/provider-login.d.ts +3 -1
- package/dist/models/provider-login.js +8 -2
- package/dist/models/reference.d.ts +20 -0
- package/dist/models/{utils.js → reference.js} +0 -48
- package/dist/models/{utils.d.ts → runtime.d.ts} +1 -16
- package/dist/models/runtime.js +52 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +9 -0
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/playbooks/catalog.d.ts +6 -2
- package/dist/playbooks/catalog.js +9 -6
- package/dist/runtime/bootstrap.d.ts +7 -17
- package/dist/runtime/bootstrap.js +70 -659
- package/dist/runtime/durable-dispatch.d.ts +43 -4
- package/dist/runtime/durable-dispatch.js +153 -3
- package/dist/runtime/inbound-images.d.ts +18 -0
- package/dist/runtime/inbound-images.js +51 -0
- package/dist/runtime/shutdown.d.ts +39 -0
- package/dist/runtime/shutdown.js +120 -0
- package/dist/runtime/stop-watchdog.d.ts +16 -0
- package/dist/runtime/stop-watchdog.js +32 -0
- package/dist/runtime/task-driver.d.ts +6 -4
- package/dist/runtime/task-driver.js +58 -23
- package/dist/runtime/task-migration.js +25 -8
- package/dist/runtime/task-spawn.d.ts +1 -1
- package/dist/runtime/task-spawn.js +13 -6
- package/dist/runtime/turn-handler.d.ts +47 -0
- package/dist/runtime/turn-handler.js +318 -0
- package/dist/runtime/turn-run.d.ts +52 -0
- package/dist/runtime/turn-run.js +318 -0
- package/dist/runtime/wake-coalescing.d.ts +18 -0
- package/dist/runtime/wake-coalescing.js +29 -0
- package/dist/security/block-message.d.ts +22 -1
- package/dist/security/block-message.js +66 -1
- package/dist/security/command-guard.js +4 -0
- package/dist/security/network.d.ts +2 -1
- package/dist/security/network.js +7 -2
- package/dist/security/path-guard-check.js +2 -2
- package/dist/security/path-guard.js +4 -0
- package/dist/security/types.d.ts +1 -2
- package/dist/security/types.js +1 -2
- package/dist/shared/exact-keys.d.ts +1 -1
- package/dist/shared/format.d.ts +12 -0
- package/dist/shared/format.js +37 -0
- package/dist/shared/host-process.js +16 -4
- package/dist/shared/wake-claim.d.ts +1 -1
- package/dist/shared/with-timeout.d.ts +3 -2
- package/dist/shared/with-timeout.js +14 -3
- package/dist/{runtime/skill-commands.d.ts → skills/commands.d.ts} +2 -2
- package/dist/{runtime/skill-commands.js → skills/commands.js} +18 -11
- package/dist/{agent/workspace-resources.js → skills/loader.js} +1 -1
- package/dist/{tools/skill-security.js → skills/validation.js} +4 -0
- package/dist/skills/workspace.d.ts +33 -0
- package/dist/skills/workspace.js +116 -0
- package/dist/{runtime/subagent-commands.d.ts → subagents/commands.d.ts} +9 -7
- package/dist/{runtime/subagent-commands.js → subagents/commands.js} +116 -77
- package/dist/subagents/completion-wake.d.ts +17 -0
- package/dist/subagents/completion-wake.js +76 -0
- package/dist/subagents/detached-discovery.js +1 -1
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +2 -2
- package/dist/subagents/dispatch.d.ts +33 -0
- package/dist/subagents/dispatch.js +190 -0
- package/dist/subagents/external/claude-code.js +23 -1
- package/dist/subagents/external/dispatch.d.ts +25 -0
- package/dist/subagents/external/dispatch.js +90 -0
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/progress-tail.d.ts +18 -1
- package/dist/subagents/external/progress-tail.js +64 -17
- package/dist/subagents/external/run.d.ts +5 -1
- package/dist/subagents/external/run.js +23 -9
- package/dist/subagents/external/settlement.d.ts +4 -1
- package/dist/subagents/external/settlement.js +1 -1
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/grace.d.ts +24 -0
- package/dist/subagents/grace.js +57 -0
- package/dist/subagents/internal/outcome.d.ts +24 -0
- package/dist/subagents/internal/outcome.js +149 -0
- package/dist/subagents/internal/provider-retry.d.ts +19 -0
- package/dist/subagents/internal/provider-retry.js +83 -0
- package/dist/subagents/internal/run.d.ts +31 -0
- package/dist/subagents/internal/run.js +240 -0
- package/dist/subagents/internal/state.d.ts +43 -0
- package/dist/subagents/internal/state.js +48 -0
- package/dist/subagents/internal/worker.d.ts +51 -0
- package/dist/subagents/internal/worker.js +167 -0
- package/dist/subagents/result.d.ts +62 -0
- package/dist/subagents/result.js +103 -0
- package/dist/subagents/run-record.d.ts +222 -0
- package/dist/subagents/run-record.js +101 -0
- package/dist/subagents/run-registry.d.ts +9 -0
- package/dist/subagents/run-registry.js +125 -0
- package/dist/subagents/runs.d.ts +16 -232
- package/dist/subagents/runs.js +132 -310
- package/dist/subagents/task-envelope.d.ts +36 -0
- package/dist/subagents/task-envelope.js +168 -0
- package/dist/subagents/types.d.ts +154 -0
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/verification-outcome.d.ts +1 -1
- package/dist/subagents/workspace-summary.d.ts +16 -4
- package/dist/subagents/workspace-summary.js +74 -18
- package/dist/tasks/board.d.ts +10 -3
- package/dist/tasks/board.js +38 -3
- package/dist/tasks/{work-log.d.ts → bound-work.d.ts} +1 -1
- package/dist/tasks/{work-log.js → bound-work.js} +1 -1
- package/dist/tasks/brief.js +1 -1
- package/dist/{runtime/task-commands.d.ts → tasks/commands.d.ts} +1 -1
- package/dist/{runtime/task-commands.js → tasks/commands.js} +117 -67
- package/dist/tasks/contract-input.d.ts +1 -1
- package/dist/tasks/contract-input.js +1 -1
- package/dist/tasks/create.js +1 -1
- package/dist/tasks/frontmatter.d.ts +5 -0
- package/dist/tasks/frontmatter.js +8 -0
- package/dist/tasks/{log.d.ts → loop-log.d.ts} +11 -1
- package/dist/tasks/{log.js → loop-log.js} +59 -3
- package/dist/tasks/mutation-lock.js +1 -1
- package/dist/tasks/session-path.js +1 -1
- package/dist/tasks/steer.js +1 -1
- package/dist/tasks/store.js +6 -4
- package/dist/tasks/ticket.d.ts +3 -1
- package/dist/tasks/ticket.js +19 -1
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.js +2 -2
- package/dist/tools/{tool-details.d.ts → contract/details.d.ts} +11 -3
- package/dist/tools/{tool-details.js → contract/details.js} +42 -5
- package/dist/tools/{presentation.js → contract/presentation.js} +3 -3
- package/dist/tools/event-manage.d.ts +1 -1
- package/dist/tools/event-manage.js +4 -4
- package/dist/tools/index.d.ts +5 -3
- package/dist/tools/index.js +8 -6
- package/dist/tools/job.d.ts +1 -1
- package/dist/tools/memory-manage.js +4 -1
- package/dist/tools/registry.d.ts +7 -7
- package/dist/tools/registry.js +6 -6
- package/dist/tools/session-search.d.ts +1 -1
- package/dist/tools/skill.d.ts +2 -34
- package/dist/tools/skill.js +8 -116
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +19 -13
- package/dist/tools/subagent.d.ts +46 -0
- package/dist/tools/subagent.js +127 -0
- package/dist/tools/{task-manage.d.ts → task-manage/factory.d.ts} +7 -3
- package/dist/tools/{task-manage.js → task-manage/factory.js} +7 -7
- package/dist/tools/task-manage/lifecycle.js +2 -2
- package/dist/tools/task-manage/log-view.js +2 -2
- package/dist/tools/task-manage/shared.js +3 -3
- package/dist/tools/task-manage/step-end.js +7 -4
- package/dist/tools/task-manage/types.d.ts +1 -1
- package/dist/tools/web-fetch.d.ts +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/tui/app.d.ts +1 -1
- package/dist/tui/app.js +6 -6
- package/dist/tui/cli.d.ts +1 -1
- package/dist/tui/cli.js +3 -3
- package/dist/tui/commands.js +4 -4
- package/dist/tui/frontend.d.ts +44 -0
- package/dist/tui/frontend.js +13 -0
- package/dist/tui/pitui-frontend.d.ts +1 -1
- package/dist/tui/pitui-frontend.js +1 -1
- package/dist/tui/plain-frontend.d.ts +1 -1
- package/dist/tui/renderer.d.ts +3 -42
- package/dist/tui/renderer.js +3 -2
- package/dist/tui/terminal-context.d.ts +2 -2
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/dist/tui/turn-controller.d.ts +3 -1
- package/dist/tui/turn-controller.js +36 -21
- package/dist/usage/ledger.js +7 -1
- package/dist/usage/render.js +3 -1
- package/dist/{shared/types.d.ts → usage/totals.d.ts} +3 -0
- package/dist/web/client.d.ts +5 -1
- package/dist/web/client.js +4 -0
- package/dist/web/config.d.ts +1 -1
- package/dist/web/fetch.d.ts +1 -1
- package/dist/web/search-providers.d.ts +1 -1
- package/dist/web/search.d.ts +1 -1
- package/package.json +9 -7
- package/dist/agent/session-adapter.js +0 -77
- package/dist/events/events.d.ts +0 -159
- package/dist/runtime/dingtalk.d.ts +0 -272
- package/dist/runtime/dingtalk.js +0 -1416
- package/dist/subagents/tool.d.ts +0 -206
- package/dist/subagents/tool.js +0 -1088
- /package/dist/{runtime → agent/prompt}/workspace-templates.d.ts +0 -0
- /package/dist/{runtime → agent/prompt}/workspace-templates.js +0 -0
- /package/dist/agent/{session-resource-gate.d.ts → session/session-resource-gate.d.ts} +0 -0
- /package/dist/agent/{context-budget.d.ts → turn/context-budget.d.ts} +0 -0
- /package/dist/agent/{progress-formatter.js → turn/progress-formatter.js} +0 -0
- /package/dist/{memory → agent/turn}/task-digest.d.ts +0 -0
- /package/dist/agent/{turn-recovery.d.ts → turn/turn-recovery.d.ts} +0 -0
- /package/dist/agent/{turn-state.js → turn/turn-state.js} +0 -0
- /package/dist/{runtime → app}/proxy.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/channel-queue.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.js +0 -0
- /package/dist/events/{event-commands.d.ts → commands.d.ts} +0 -0
- /package/dist/{agent/workspace-resources.d.ts → skills/loader.d.ts} +0 -0
- /package/dist/{tools/skill-security.d.ts → skills/validation.d.ts} +0 -0
- /package/dist/tasks/{ledger.d.ts → contract.d.ts} +0 -0
- /package/dist/tasks/{ledger.js → contract.js} +0 -0
- /package/dist/tools/{subagent-tool-names.d.ts → contract/names.d.ts} +0 -0
- /package/dist/tools/{subagent-tool-names.js → contract/names.js} +0 -0
- /package/dist/tools/{presentation.d.ts → contract/presentation.d.ts} +0 -0
- /package/dist/{shared/types.js → usage/totals.js} +0 -0
|
@@ -4,7 +4,7 @@ import { promisify } from "node:util";
|
|
|
4
4
|
* Stateless host-process operations shared by background jobs and external delegation runs
|
|
5
5
|
* (spec 040, D1): a liveness probe and a process-group kill. Nothing here is job- or run-specific
|
|
6
6
|
* — both callers bring their own persisted pid and decide what "gone" means for their own state
|
|
7
|
-
* machine. `
|
|
7
|
+
* machine. `jobs/manager.ts` still probes through its shell `Executor` (its jobs are shell
|
|
8
8
|
* children); this is for callers that spawn argv-direct, detached children of their own (D3/D4).
|
|
9
9
|
*/
|
|
10
10
|
const execFileAsync = promisify(execFile);
|
|
@@ -26,6 +26,8 @@ export async function readProcessStartTime(pid) {
|
|
|
26
26
|
}
|
|
27
27
|
const CLI_VERSION_PROBE_TIMEOUT_MS = 1_000;
|
|
28
28
|
const CLI_VERSION_MAX_CHARS = 200;
|
|
29
|
+
const CLI_VERSION_CACHE_TTL_MS = 10 * 60_000;
|
|
30
|
+
const cliVersionCache = new Map();
|
|
29
31
|
/**
|
|
30
32
|
* Best-effort `<executable> --version`, so a run persists which build of the target CLI it ran
|
|
31
33
|
* against (spec 042 D12) — the other half of `parserVersion`'s "adapter drift vs. agent failure"
|
|
@@ -33,14 +35,24 @@ const CLI_VERSION_MAX_CHARS = 200;
|
|
|
33
35
|
* a CLI that does not support `--version`, is slow to start, or fails outright.
|
|
34
36
|
*/
|
|
35
37
|
export async function probeCliVersion(executable) {
|
|
38
|
+
// A CLI's version changes only when someone upgrades it, while a busy channel dispatches the
|
|
39
|
+
// same executable many times an hour — re-spawning `<cli> --version` (a cold Node start for
|
|
40
|
+
// claude/codex) per dispatch bought nothing. A short TTL keeps an upgrade visible soon after.
|
|
41
|
+
const cached = cliVersionCache.get(executable);
|
|
42
|
+
if (cached && Date.now() - cached.at < CLI_VERSION_CACHE_TTL_MS)
|
|
43
|
+
return cached.value;
|
|
44
|
+
let value;
|
|
36
45
|
try {
|
|
37
46
|
const { stdout } = await execFileAsync(executable, ["--version"], { timeout: CLI_VERSION_PROBE_TIMEOUT_MS });
|
|
38
|
-
|
|
39
|
-
return value || undefined;
|
|
47
|
+
value = stdout.trim().split("\n")[0]?.slice(0, CLI_VERSION_MAX_CHARS) || undefined;
|
|
40
48
|
}
|
|
41
49
|
catch {
|
|
42
|
-
|
|
50
|
+
value = undefined;
|
|
43
51
|
}
|
|
52
|
+
// Only a real answer is cached: a timeout on a cold start should not hide the version for the TTL.
|
|
53
|
+
if (value)
|
|
54
|
+
cliVersionCache.set(executable, { value, at: Date.now() });
|
|
55
|
+
return value;
|
|
44
56
|
}
|
|
45
57
|
/** True if `pid` names a live process this user can at least see, without sending a real signal. */
|
|
46
58
|
export function isProcessAlive(pid) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The two-phase "claim, then finish" decision shared by `
|
|
2
|
+
* The two-phase "claim, then finish" decision shared by `jobs/manager.ts` and `subagents/runs.ts`
|
|
3
3
|
* for reserving a completion wake exactly once (spec 040, D7/T9). Both managers persist a
|
|
4
4
|
* `RunRecord`/`JobRecord` differently and gate eligibility on a different terminal condition
|
|
5
5
|
* (job: `status !== "running"`; run: `settledAt` set), so only the claim/consume decision on the
|
|
@@ -12,6 +12,7 @@ export declare class OperationTimeoutError extends Error {
|
|
|
12
12
|
constructor(operation: string, timeoutMs: number);
|
|
13
13
|
}
|
|
14
14
|
/** A delay that never keeps the process alive on its own — every background-loop backoff and
|
|
15
|
-
* budget wait in the codebase wants this, not a bare `setTimeout` promise.
|
|
16
|
-
|
|
15
|
+
* budget wait in the codebase wants this, not a bare `setTimeout` promise. An aborted `signal`
|
|
16
|
+
* ends the wait early (it still resolves; callers re-check whatever aborted it). */
|
|
17
|
+
export declare function sleepUnref(ms: number, signal?: AbortSignal): Promise<void>;
|
|
17
18
|
export declare function withTimeout<T>(operation: string, timeoutMs: number, run: () => Promise<T>): Promise<T>;
|
|
@@ -15,11 +15,22 @@ export class OperationTimeoutError extends Error {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
/** A delay that never keeps the process alive on its own — every background-loop backoff and
|
|
18
|
-
* budget wait in the codebase wants this, not a bare `setTimeout` promise.
|
|
19
|
-
|
|
18
|
+
* budget wait in the codebase wants this, not a bare `setTimeout` promise. An aborted `signal`
|
|
19
|
+
* ends the wait early (it still resolves; callers re-check whatever aborted it). */
|
|
20
|
+
export function sleepUnref(ms, signal) {
|
|
20
21
|
return new Promise((resolve) => {
|
|
21
|
-
|
|
22
|
+
if (signal?.aborted) {
|
|
23
|
+
resolve();
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const done = () => {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
signal?.removeEventListener("abort", done);
|
|
29
|
+
resolve();
|
|
30
|
+
};
|
|
31
|
+
const timer = setTimeout(done, ms);
|
|
22
32
|
timer.unref?.();
|
|
33
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
23
34
|
});
|
|
24
35
|
}
|
|
25
36
|
export async function withTimeout(operation, timeoutMs, run) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `/skills` — the human control path for a workspace's skill catalog (spec 045's read-only
|
|
3
|
-
* `skill` tool has no channel-command counterpart until now). Mirrors `
|
|
3
|
+
* `skill` tool has no channel-command counterpart until now). Mirrors `channel/commands.ts`'s
|
|
4
4
|
* shape: pure-ish functions returning markdown, no bot/event coupling.
|
|
5
5
|
*
|
|
6
6
|
* Deliberately a disk scan via `listWorkspaceSkills`, not the live `ChannelRunner`'s already-
|
|
7
7
|
* loaded catalog: that keeps `/skills` usable while a turn is streaming and for a channel with no
|
|
8
8
|
* active runner, and — the whole reason this exists rather than reusing `/help`'s discovery tail
|
|
9
9
|
* — it is the only place that shows a skill that failed the content scan and was silently dropped
|
|
10
|
-
* from
|
|
10
|
+
* from the prompt's skill list (`src/skills/loader.ts`).
|
|
11
11
|
*/
|
|
12
12
|
export interface HandleSkillsCommandOptions {
|
|
13
13
|
args: string;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { renderSubcommandUsage } from "../commands/catalog.js";
|
|
2
|
-
import { capReply } from "../commands/reply-limits.js";
|
|
2
|
+
import { capReply, flattenMarkdownForChat } from "../commands/reply-limits.js";
|
|
3
|
+
import { GuardBlockedError, renderGuardBlockForUser } from "../security/block-message.js";
|
|
3
4
|
import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
|
|
5
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
4
6
|
import { errorMessage } from "../shared/text-utils.js";
|
|
5
|
-
import { listWorkspaceSkills, loadWorkspaceSkillFile } from "
|
|
7
|
+
import { listWorkspaceSkills, loadWorkspaceSkillFile } from "./workspace.js";
|
|
6
8
|
function usage() {
|
|
7
9
|
return renderSubcommandUsage("skills");
|
|
8
10
|
}
|
|
@@ -17,25 +19,25 @@ export function parseSkillsCommand(args) {
|
|
|
17
19
|
throw new Error("用法:/skills show <name>");
|
|
18
20
|
return { action: "show", name: parts[1] };
|
|
19
21
|
}
|
|
20
|
-
throw new Error(
|
|
22
|
+
throw new Error(`未知子命令 \`${parts[0]}\`。`);
|
|
21
23
|
}
|
|
22
24
|
async function listSkills(workspaceDir) {
|
|
23
25
|
const skills = await listWorkspaceSkills({ workspaceDir });
|
|
24
26
|
if (skills.length === 0) {
|
|
25
|
-
return (
|
|
26
|
-
|
|
27
|
+
return ("暂无工作区 skill。\n" +
|
|
28
|
+
`让我帮你创建,或手动放到 \`${workspaceDir}/skills/<name>/SKILL.md\`(文件头需要非空的 \`name\`,与目录名一致,以及 \`description\`)。`);
|
|
27
29
|
}
|
|
28
30
|
const loaded = skills.filter((skill) => !skill.warning);
|
|
29
31
|
const rejected = skills.filter((skill) => skill.warning);
|
|
30
|
-
const lines = [
|
|
32
|
+
const lines = [`**工作区 skills**(${loaded.length} 个)· 用 \`/skill:<名称>\` 调用`, ""];
|
|
31
33
|
if (loaded.length > 0) {
|
|
32
|
-
lines.push(...loaded.map((skill) => `- \`${skill.name}\` — ${skill.description || "
|
|
34
|
+
lines.push(...loaded.map((skill) => `- \`${skill.name}\` — ${skill.description || "(无 description)"}`));
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
35
37
|
lines.push("(全部未通过加载,见下)");
|
|
36
38
|
}
|
|
37
39
|
if (rejected.length > 0) {
|
|
38
|
-
lines.push("", "
|
|
40
|
+
lines.push("", "⚠️ 未加载(助手看不到,也无法用 `/skill:名称` 调用)", "");
|
|
39
41
|
lines.push(...rejected.map((skill) => `- \`${skill.name}\` — ${skill.warning}`));
|
|
40
42
|
}
|
|
41
43
|
return capReply(lines.join("\n"), { nextStepHint: "用 `/skills show <name>` 查看单个 skill 的完整正文" }).text;
|
|
@@ -48,11 +50,16 @@ async function showSkill(options, name) {
|
|
|
48
50
|
securityConfig,
|
|
49
51
|
channelId: options.channelId,
|
|
50
52
|
}, name);
|
|
51
|
-
const body = `**Skill \`${file.name}\`**\n\n路径:\`${file.path}\`\n\n${file.content}`;
|
|
52
|
-
return capReply(body, { nextStepHint:
|
|
53
|
+
const body = `**Skill \`${file.name}\`**\n\n路径:\`${file.path}\`\n\n${flattenMarkdownForChat(file.content)}`;
|
|
54
|
+
return capReply(body, { nextStepHint: `完整内容在 \`${file.path}\`` }).text;
|
|
53
55
|
}
|
|
54
56
|
catch (error) {
|
|
55
|
-
|
|
57
|
+
// The loader's errors are written for the model (`Use action "list"…`); say it in the user's terms.
|
|
58
|
+
if (error instanceof RecoverableToolError)
|
|
59
|
+
return `未找到 skill \`${name}\`。用 \`/skills\` 查看可用的 skill。`;
|
|
60
|
+
if (error instanceof GuardBlockedError)
|
|
61
|
+
return renderGuardBlockForUser(error.blocked);
|
|
62
|
+
return `无法读取 skill \`${name}\`:${errorMessage(error)}`;
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
export async function handleSkillsCommand(options) {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { readFileSync } from "node:fs";
|
|
8
8
|
import { loadSkillsFromDir } from "@earendil-works/pi-coding-agent";
|
|
9
9
|
import { join } from "path";
|
|
10
|
-
import { scanSkillContent } from "
|
|
10
|
+
import { scanSkillContent } from "./validation.js";
|
|
11
11
|
/**
|
|
12
12
|
* Content scanning moved here from the old `skill_manage` write path (spec 045): `skill` is now
|
|
13
13
|
* read-only and workspace skills are authored through the generic `write`/`edit` tools, which have
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation of workspace skills: names, frontmatter, content scanning, and confinement of a skill's
|
|
3
|
+
* path to `workspace/skills/`.
|
|
4
|
+
*/
|
|
1
5
|
import { resolve } from "node:path";
|
|
2
6
|
const SKILL_NAME_REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
3
7
|
const FRONTMATTER_REGEX = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
2
|
+
export interface WorkspaceSkillSummary {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
path: string;
|
|
6
|
+
warning?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface WorkspaceSkillOptions {
|
|
9
|
+
workspaceDir: string;
|
|
10
|
+
securityConfig?: SecurityConfig;
|
|
11
|
+
securityContext?: SecurityRuntimeContext;
|
|
12
|
+
channelId?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function listWorkspaceSkills(options: {
|
|
15
|
+
workspaceDir: string;
|
|
16
|
+
securityConfig?: SecurityConfig;
|
|
17
|
+
securityContext?: SecurityRuntimeContext;
|
|
18
|
+
}): Promise<WorkspaceSkillSummary[]>;
|
|
19
|
+
export interface WorkspaceSkillFile {
|
|
20
|
+
name: string;
|
|
21
|
+
/** The guard-resolved path actually opened — never the raw pre-guard path. */
|
|
22
|
+
path: string;
|
|
23
|
+
/** The whole file; callers that need a size cap (the `skill` tool) apply it themselves. */
|
|
24
|
+
content: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Load one skill's `SKILL.md` bytes through the same path-guard every other file read goes
|
|
28
|
+
* through. Shared by the `skill` tool's `read` action and the `/skills show` runtime command
|
|
29
|
+
* (`skills/commands.ts`) — a `SKILL.md` that is itself a symlink pointing outside
|
|
30
|
+
* `workspace/skills/` (planted via `bash ln -s`, not via `name` -- `resolveSkillPath` already
|
|
31
|
+
* confines that) is caught here in both callers instead of being read verbatim.
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadWorkspaceSkillFile(options: WorkspaceSkillOptions, name: string): Promise<WorkspaceSkillFile>;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace skill catalog access: list the skills under `workspace/skills/` and load one
|
|
3
|
+
* `SKILL.md`, both through the path guard. The `skill` tool and `/skills` are thin adapters over
|
|
4
|
+
* this file (spec 054 D8/D10).
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { readdir, readFile, stat } from "node:fs/promises";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
10
|
+
import { checkPathGuard } from "../security/path-guard-check.js";
|
|
11
|
+
import { readGuardAllows } from "../security/path-guard-filter.js";
|
|
12
|
+
import { isNodeError } from "../shared/os.js";
|
|
13
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
14
|
+
import { resolveSkillPath, scanSkillContent, validateSkillFrontmatter, validateSkillName } from "./validation.js";
|
|
15
|
+
function extractDescription(content) {
|
|
16
|
+
const match = content.replace(/\r\n/g, "\n").match(/^---\n([\s\S]*?)\n---/);
|
|
17
|
+
if (!match) {
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
for (const line of (match[1] ?? "").split("\n")) {
|
|
21
|
+
const fieldMatch = line.match(/^description:\s*(.*)$/);
|
|
22
|
+
if (fieldMatch) {
|
|
23
|
+
return fieldMatch[1].replace(/^["']|["']$/g, "").trim();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
28
|
+
export async function listWorkspaceSkills(options) {
|
|
29
|
+
const skillsDir = join(options.workspaceDir, "skills");
|
|
30
|
+
// `skill read` runs each SKILL.md through the path guard (`loadWorkspaceSkillFile`); `list`
|
|
31
|
+
// must apply the same guard so a skill whose SKILL.md is a symlink out of `workspace/skills/`
|
|
32
|
+
// is silently omitted here too, rather than being advertised and then refused on read.
|
|
33
|
+
const guardConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
34
|
+
const guardContext = options.securityContext ?? {
|
|
35
|
+
agentWorkspaceDir: options.workspaceDir,
|
|
36
|
+
projectRoot: options.workspaceDir,
|
|
37
|
+
};
|
|
38
|
+
let names;
|
|
39
|
+
try {
|
|
40
|
+
names = await readdir(skillsDir);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (isNodeError(error) && error.code === "ENOENT") {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
const summaries = [];
|
|
49
|
+
for (const name of names.sort()) {
|
|
50
|
+
const nameValidation = validateSkillName(name);
|
|
51
|
+
if (!nameValidation.ok) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
const skillDir = join(skillsDir, name);
|
|
55
|
+
const skillStats = await stat(skillDir).catch(() => null);
|
|
56
|
+
if (!skillStats?.isDirectory()) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const skillPath = join(skillDir, "SKILL.md");
|
|
60
|
+
if (!readGuardAllows(skillPath, guardConfig, guardContext)) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
let content;
|
|
64
|
+
try {
|
|
65
|
+
const skillFileStats = await stat(skillPath);
|
|
66
|
+
if (!skillFileStats.isFile()) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
content = await readFile(skillPath, "utf-8");
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (isNodeError(error) && error.code === "ENOENT") {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
const validation = validateSkillFrontmatter(content, name);
|
|
78
|
+
const scan = validation.ok ? scanSkillContent(content) : validation;
|
|
79
|
+
summaries.push({
|
|
80
|
+
name,
|
|
81
|
+
description: extractDescription(content),
|
|
82
|
+
path: `${options.workspaceDir}/skills/${name}/SKILL.md`,
|
|
83
|
+
warning: scan.ok ? undefined : scan.error,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return summaries;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Load one skill's `SKILL.md` bytes through the same path-guard every other file read goes
|
|
90
|
+
* through. Shared by the `skill` tool's `read` action and the `/skills show` runtime command
|
|
91
|
+
* (`skills/commands.ts`) — a `SKILL.md` that is itself a symlink pointing outside
|
|
92
|
+
* `workspace/skills/` (planted via `bash ln -s`, not via `name` -- `resolveSkillPath` already
|
|
93
|
+
* confines that) is caught here in both callers instead of being read verbatim.
|
|
94
|
+
*/
|
|
95
|
+
export async function loadWorkspaceSkillFile(options, name) {
|
|
96
|
+
const nameValidation = validateSkillName(name);
|
|
97
|
+
if (!nameValidation.ok) {
|
|
98
|
+
throw new RecoverableToolError(nameValidation.error ?? `Invalid skill name "${name}".`);
|
|
99
|
+
}
|
|
100
|
+
const skillDir = resolveSkillPath(options.workspaceDir, name);
|
|
101
|
+
const rawPath = join(skillDir, "SKILL.md");
|
|
102
|
+
if (!existsSync(rawPath)) {
|
|
103
|
+
throw new RecoverableToolError(`Workspace skill "${name}" does not exist. Use action "list" to see what's available.`);
|
|
104
|
+
}
|
|
105
|
+
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
106
|
+
const securityContext = options.securityContext ?? {
|
|
107
|
+
agentWorkspaceDir: options.workspaceDir,
|
|
108
|
+
projectRoot: options.workspaceDir,
|
|
109
|
+
};
|
|
110
|
+
const target = await checkPathGuard(rawPath, "read", securityConfig, securityContext, {
|
|
111
|
+
tool: "skill",
|
|
112
|
+
channelId: options.channelId,
|
|
113
|
+
});
|
|
114
|
+
const content = await readFile(target, "utf-8");
|
|
115
|
+
return { name, path: target, content };
|
|
116
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { SubAgentDiscoveryResult } from "
|
|
2
|
-
import type { RunNotice
|
|
1
|
+
import type { SubAgentDiscoveryResult } from "./discovery.js";
|
|
2
|
+
import type { RunNotice } from "./run-record.js";
|
|
3
|
+
import type { SubAgentRunManager } from "./runs.js";
|
|
3
4
|
/**
|
|
4
5
|
* `/subagents` — the human control path that does not depend on the model (spec 040 D6, polished
|
|
5
|
-
* by spec 041). Mirrors `
|
|
6
|
+
* by spec 041). Mirrors `tasks/commands.ts`'s shape: pure functions returning markdown, no
|
|
6
7
|
* bot/event coupling.
|
|
7
8
|
*/
|
|
8
9
|
export interface HandleSubagentsCommandOptions {
|
|
@@ -37,10 +38,11 @@ type SubagentsCommand = {
|
|
|
37
38
|
export declare function parseSubagentsCommand(args: string): SubagentsCommand;
|
|
38
39
|
export declare function handleSubagentsCommand(options: HandleSubagentsCommandOptions): Promise<string>;
|
|
39
40
|
/**
|
|
40
|
-
* Render a `RunNotice` (P0-1/P1a) as a
|
|
41
|
-
*
|
|
42
|
-
* caller filters `kind: "progress"` out
|
|
43
|
-
*
|
|
41
|
+
* Render a `RunNotice` (P0-1/P1a) as a runtime push (spec 053, D6): one marker, the run id the
|
|
42
|
+
* user can act on, and — for a failure — the command that shows why. `notices: "off"` is enforced
|
|
43
|
+
* by the caller not invoking this at all; a `"settled"` caller filters `kind: "progress"` out
|
|
44
|
+
* before calling (a `"stalled"` warning needs attention, so it passes both levels). Returns `undefined` for a notice with nothing worth showing (a progress step
|
|
45
|
+
* that never resolved to a label).
|
|
44
46
|
*/
|
|
45
47
|
export declare function renderRunNotice(notice: RunNotice): string | undefined;
|
|
46
48
|
export {};
|