@oyasmi/pipiclaw 0.9.5 → 0.9.6-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/README.en.md +300 -142
- package/README.md +295 -140
- package/dist/agent/builtin-commands.d.ts +1 -1
- package/dist/agent/builtin-commands.js +1 -1
- package/dist/agent/channel-runner.d.ts +4 -3
- package/dist/agent/channel-runner.js +17 -28
- package/dist/agent/maintenance-context.js +2 -2
- package/dist/agent/prompt/builder.d.ts +1 -1
- package/dist/agent/prompt/builder.js +1 -1
- package/dist/agent/prompt/extension.d.ts +1 -1
- package/dist/agent/prompt/extension.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +12 -5
- package/dist/agent/prompt/resources.d.ts +0 -3
- package/dist/agent/prompt/resources.js +0 -6
- package/dist/agent/prompt/sections.d.ts +2 -2
- package/dist/agent/prompt/sections.js +36 -26
- package/dist/agent/prompt/types.d.ts +3 -2
- package/dist/agent/runner-factory.js +1 -1
- package/dist/agent/session/command-extension.js +3 -1
- package/dist/agent/session/compaction-summary.js +3 -6
- package/dist/agent/session/compaction.d.ts +2 -0
- package/dist/agent/session/compaction.js +22 -14
- package/dist/agent/session/event-guards.d.ts +2 -1
- package/dist/agent/session/event-guards.js +6 -0
- package/dist/agent/session/model-selection.d.ts +2 -1
- package/dist/agent/session/model-selection.js +5 -5
- package/dist/agent/session/session-events.js +31 -4
- package/dist/agent/session/session-host.d.ts +5 -3
- package/dist/agent/session/session-host.js +20 -16
- package/dist/agent/status-render.js +3 -0
- package/dist/agent/stop-watchdog.js +5 -1
- package/dist/agent/turn/task-digest.d.ts +2 -5
- package/dist/agent/turn/task-digest.js +25 -45
- package/dist/agent/turn/turn-context.js +4 -6
- package/dist/agent/turn/turn-error.d.ts +1 -1
- package/dist/agent/turn/turn-error.js +9 -0
- package/dist/agent/turn/turn-pipeline.d.ts +10 -5
- package/dist/agent/turn/turn-pipeline.js +36 -7
- package/dist/agent/turn/turn-prompt.d.ts +2 -0
- package/dist/agent/turn/turn-prompt.js +2 -1
- package/dist/agent/turn/turn-recovery.js +4 -1
- package/dist/agent/turn/turn-state.d.ts +2 -0
- package/dist/agent/turn/turn-state.js +2 -1
- package/dist/agent/types.d.ts +23 -3
- package/dist/agent/types.js +2 -0
- package/dist/app/auth-command.d.ts +25 -0
- package/dist/app/auth-command.js +200 -67
- package/dist/app/home.d.ts +7 -8
- package/dist/app/home.js +143 -56
- package/dist/channel/attachments.d.ts +4 -0
- package/dist/channel/attachments.js +4 -0
- package/dist/channel/channel-context.d.ts +6 -0
- package/dist/channel/config.d.ts +3 -0
- package/dist/channel/config.js +11 -5
- package/dist/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +42 -10
- package/dist/commands/router.js +5 -1
- package/dist/desk/commands.d.ts +44 -5
- package/dist/desk/commands.js +162 -28
- package/dist/desk/paths.d.ts +6 -0
- package/dist/desk/paths.js +21 -1
- package/dist/desk/registry.d.ts +17 -2
- package/dist/desk/registry.js +122 -12
- package/dist/desk/types.d.ts +83 -1
- package/dist/dingtalk/bot.d.ts +1 -1
- package/dist/dingtalk/bot.js +4 -3
- package/dist/dingtalk/config.js +10 -10
- package/dist/dingtalk/delivery.js +15 -8
- package/dist/dingtalk/inbound-media.d.ts +36 -14
- package/dist/dingtalk/inbound-media.js +71 -12
- package/dist/dingtalk/inbound.d.ts +9 -2
- package/dist/dingtalk/inbound.js +17 -2
- package/dist/dingtalk/media.d.ts +4 -10
- package/dist/dingtalk/media.js +58 -32
- package/dist/events/commands.d.ts +2 -0
- package/dist/events/commands.js +13 -8
- package/dist/events/history.d.ts +9 -0
- package/dist/events/history.js +66 -0
- package/dist/events/parse.js +7 -3
- package/dist/events/types.d.ts +3 -0
- package/dist/events/watcher.d.ts +4 -8
- package/dist/events/watcher.js +53 -58
- package/dist/jobs/kill.d.ts +23 -0
- package/dist/jobs/kill.js +65 -0
- package/dist/jobs/manager.d.ts +19 -18
- package/dist/jobs/manager.js +36 -103
- package/dist/main.js +15 -3
- package/dist/memory/boundary-work.d.ts +2 -1
- package/dist/memory/boundary-work.js +1 -1
- package/dist/memory/lifecycle.d.ts +2 -1
- package/dist/memory/lifecycle.js +2 -2
- package/dist/memory/reflect-job.d.ts +2 -1
- package/dist/memory/reflect-job.js +1 -1
- package/dist/memory/reflect.d.ts +2 -1
- package/dist/memory/reflect.js +25 -4
- package/dist/memory/scheduler.d.ts +2 -1
- package/dist/memory/scheduler.js +1 -1
- package/dist/memory/session-corpus.d.ts +1 -1
- package/dist/memory/session-corpus.js +76 -1
- package/dist/memory/session-search.d.ts +2 -1
- package/dist/memory/session-search.js +14 -12
- package/dist/memory/sidecar-worker.d.ts +2 -1
- package/dist/memory/sidecar-worker.js +2 -4
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +19 -9
- package/dist/models/credential-work.d.ts +7 -0
- package/dist/models/credential-work.js +36 -0
- package/dist/models/login-ui.js +4 -4
- package/dist/models/provider-login.js +7 -6
- package/dist/models/requests.d.ts +8 -0
- package/dist/models/requests.js +69 -0
- package/dist/models/runtime.d.ts +3 -1
- package/dist/models/runtime.js +9 -2
- package/dist/playbooks/agent-delegation.md +20 -45
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/delegation-inline.md +25 -0
- package/dist/playbooks/delegation-recovery.md +28 -0
- package/dist/playbooks/event-scheduling.md +18 -37
- package/dist/playbooks/event-sensors.md +26 -0
- package/dist/playbooks/event-task-template.md +22 -0
- package/dist/playbooks/learning-and-skills.md +26 -0
- package/dist/playbooks/memory-operations.md +36 -0
- package/dist/playbooks/outbound-media.md +2 -2
- package/dist/playbooks/runtime-files.md +29 -0
- package/dist/playbooks/runtime-operations.md +25 -0
- package/dist/playbooks/runtime-orientation.md +18 -53
- package/dist/playbooks/task-lead.md +22 -68
- package/dist/playbooks/task-manage.md +38 -0
- package/dist/playbooks/task-recovery.md +24 -0
- package/dist/playbooks/task-verify.md +22 -0
- package/dist/runtime/bootstrap.d.ts +10 -0
- package/dist/runtime/bootstrap.js +93 -29
- package/dist/runtime/daemon-lock.js +3 -3
- package/dist/runtime/desk-runtime.d.ts +40 -7
- package/dist/runtime/desk-runtime.js +330 -44
- package/dist/runtime/durable-dispatch.d.ts +14 -2
- package/dist/runtime/durable-dispatch.js +207 -65
- package/dist/runtime/ingress-busy.js +17 -8
- package/dist/runtime/ingress-commands.js +24 -4
- package/dist/runtime/ingress-deps.d.ts +4 -1
- package/dist/runtime/ingress.js +6 -1
- package/dist/runtime/request-execution.js +7 -6
- package/dist/runtime/shutdown.d.ts +4 -1
- package/dist/runtime/shutdown.js +88 -35
- package/dist/runtime/task-close.d.ts +1 -1
- package/dist/runtime/task-close.js +6 -3
- package/dist/runtime/task-control.d.ts +2 -3
- package/dist/runtime/task-control.js +38 -11
- package/dist/runtime/task-input.js +1 -1
- package/dist/runtime/task-lane-types.d.ts +12 -2
- package/dist/runtime/task-lane-types.js +9 -0
- package/dist/runtime/task-lane.d.ts +2 -0
- package/dist/runtime/task-lane.js +38 -20
- package/dist/runtime/task-step.d.ts +3 -3
- package/dist/runtime/task-step.js +34 -16
- package/dist/runtime/transports.js +6 -5
- package/dist/runtime/turn-run.js +103 -66
- package/dist/security/command-guard.d.ts +1 -1
- package/dist/security/command-guard.js +259 -314
- package/dist/security/path-guard.js +48 -7
- package/dist/security/shell-parse.d.ts +10 -0
- package/dist/security/shell-parse.js +224 -0
- package/dist/security/types.d.ts +2 -0
- package/dist/subagents/commands.d.ts +1 -1
- package/dist/subagents/commands.js +14 -5
- package/dist/subagents/completion-wake.js +6 -0
- package/dist/subagents/detached-discovery.d.ts +1 -1
- package/dist/subagents/discovery.d.ts +18 -199
- package/dist/subagents/discovery.js +35 -289
- package/dist/subagents/dispatch.d.ts +1 -2
- package/dist/subagents/dispatch.js +50 -29
- package/dist/subagents/external/antigravity-cli.d.ts +2 -0
- package/dist/subagents/external/antigravity-cli.js +517 -0
- package/dist/subagents/external/claude-code.js +8 -17
- package/dist/subagents/external/codex-cli.js +8 -18
- package/dist/subagents/external/cursor-cli.js +34 -31
- package/dist/subagents/external/dispatch.d.ts +21 -7
- package/dist/subagents/external/dispatch.js +146 -12
- package/dist/subagents/external/exec.js +3 -0
- package/dist/subagents/external/harness.d.ts +57 -33
- package/dist/subagents/external/harness.js +69 -40
- package/dist/subagents/external/reconciliation.js +1 -0
- package/dist/subagents/external/registry.js +4 -1
- package/dist/subagents/external/role-warnings.d.ts +4 -13
- package/dist/subagents/external/role-warnings.js +4 -28
- package/dist/subagents/external/run.d.ts +1 -2
- package/dist/subagents/external/run.js +16 -26
- package/dist/subagents/external/settlement.d.ts +2 -0
- package/dist/subagents/external/settlement.js +13 -3
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/internal/outcome.d.ts +1 -2
- package/dist/subagents/internal/outcome.js +19 -12
- package/dist/subagents/internal/provider-retry.d.ts +1 -2
- package/dist/subagents/internal/provider-retry.js +2 -4
- package/dist/subagents/internal/run.d.ts +2 -3
- package/dist/subagents/internal/run.js +27 -4
- package/dist/subagents/internal/state.d.ts +2 -5
- package/dist/subagents/internal/state.js +1 -2
- package/dist/subagents/internal/worker.d.ts +1 -2
- package/dist/subagents/internal/worker.js +20 -10
- package/dist/subagents/resolve.d.ts +56 -0
- package/dist/subagents/resolve.js +202 -0
- package/dist/subagents/result.d.ts +6 -4
- package/dist/subagents/result.js +39 -6
- package/dist/subagents/run-record.d.ts +54 -2
- package/dist/subagents/run-record.js +7 -0
- package/dist/subagents/runs.d.ts +6 -31
- package/dist/subagents/runs.js +26 -31
- package/dist/subagents/task-envelope.d.ts +1 -2
- package/dist/subagents/task-envelope.js +13 -4
- package/dist/subagents/task-settlement.js +1 -0
- package/dist/subagents/types.d.ts +105 -6
- package/dist/subagents/types.js +16 -1
- package/dist/subagents/workspace-lease.d.ts +41 -24
- package/dist/subagents/workspace-lease.js +159 -24
- package/dist/subagents/worktree.d.ts +52 -0
- package/dist/subagents/worktree.js +363 -0
- package/dist/tasks/archive.js +4 -0
- package/dist/tasks/brief.d.ts +5 -1
- package/dist/tasks/brief.js +19 -5
- package/dist/tasks/commands.d.ts +6 -1
- package/dist/tasks/commands.js +32 -7
- package/dist/tasks/control.d.ts +11 -0
- package/dist/tasks/delivery.d.ts +2 -0
- package/dist/tasks/delivery.js +141 -21
- package/dist/tasks/loop-log.d.ts +12 -0
- package/dist/tasks/loop-log.js +10 -1
- package/dist/tasks/receipts.d.ts +7 -3
- package/dist/tasks/receipts.js +34 -5
- package/dist/tools/bash.d.ts +3 -0
- package/dist/tools/bash.js +29 -15
- package/dist/tools/contract/presentation.js +7 -5
- package/dist/tools/edit-diff.d.ts +11 -0
- package/dist/tools/edit-diff.js +148 -0
- package/dist/tools/edit-match.d.ts +18 -0
- package/dist/tools/edit-match.js +242 -0
- package/dist/tools/edit.d.ts +10 -2
- package/dist/tools/edit.js +91 -361
- package/dist/tools/event-manage.d.ts +2 -1
- package/dist/tools/event-manage.js +46 -39
- package/dist/tools/file-observations.d.ts +9 -0
- package/dist/tools/file-observations.js +50 -0
- package/dist/tools/glob-match.d.ts +3 -1
- package/dist/tools/glob-match.js +40 -17
- package/dist/tools/glob.d.ts +1 -0
- package/dist/tools/glob.js +39 -19
- package/dist/tools/grep-command.d.ts +13 -0
- package/dist/tools/grep-command.js +77 -0
- package/dist/tools/grep.js +96 -201
- package/dist/tools/index.d.ts +6 -2
- package/dist/tools/index.js +9 -4
- package/dist/tools/job.js +12 -11
- package/dist/tools/read.d.ts +2 -0
- package/dist/tools/read.js +10 -2
- package/dist/tools/registry.d.ts +16 -11
- package/dist/tools/registry.js +32 -12
- package/dist/tools/send-media.js +9 -5
- package/dist/tools/session-search.d.ts +2 -1
- package/dist/tools/session-search.js +15 -5
- package/dist/tools/skill.js +13 -12
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +25 -152
- package/dist/tools/subagent.d.ts +24 -2
- package/dist/tools/subagent.js +24 -18
- package/dist/tools/task-manage/control-tools.js +1 -1
- package/dist/tools/task-manage/factory.d.ts +2 -2
- package/dist/tools/task-manage/factory.js +40 -4
- package/dist/tools/task-manage/lifecycle.d.ts +3 -3
- package/dist/tools/task-manage/lifecycle.js +56 -13
- package/dist/tools/task-manage/schema.d.ts +4 -1
- package/dist/tools/task-manage/schema.js +4 -1
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/types.d.ts +5 -1
- package/dist/tools/write-content.d.ts +7 -1
- package/dist/tools/write-content.js +18 -6
- package/dist/tools/write.d.ts +3 -0
- package/dist/tools/write.js +6 -2
- package/dist/tui/cli.d.ts +6 -6
- package/dist/tui/cli.js +120 -28
- package/dist/tui/client.d.ts +7 -0
- package/dist/tui/client.js +67 -16
- package/dist/tui/frontend.d.ts +2 -0
- package/dist/tui/pitui-frontend.d.ts +4 -0
- package/dist/tui/pitui-frontend.js +27 -0
- package/dist/tui/render.d.ts +1 -0
- package/dist/tui/render.js +5 -0
- package/dist/tui/session.js +6 -0
- package/dist/usage/ledger.d.ts +1 -1
- package/dist/usage/render.js +1 -1
- package/dist/web/client.d.ts +1 -0
- package/dist/web/client.js +11 -0
- package/dist/web/fetch.js +6 -3
- package/dist/webapi/auth.d.ts +0 -3
- package/dist/webapi/auth.js +3 -7
- package/dist/webapi/config.js +17 -14
- package/dist/webapi/key-command.js +41 -41
- package/dist/webapi/response-state.d.ts +7 -1
- package/dist/webapi/response-state.js +166 -3
- package/dist/webapi/routes/websocket.js +24 -1
- package/dist/webapi/server.d.ts +3 -1
- package/dist/webapi/server.js +32 -1
- package/dist/webapi/service.js +8 -0
- package/dist/webapi/transport.d.ts +2 -0
- package/dist/webapi/transport.js +11 -1
- package/examples/sub-agents/README.md +43 -75
- package/examples/sub-agents/agy-main.md +21 -0
- package/examples/sub-agents/claude-high.md +21 -0
- package/examples/sub-agents/claude-main.md +21 -0
- package/examples/sub-agents/codex-flash.md +21 -0
- package/examples/sub-agents/codex-high.md +21 -0
- package/examples/sub-agents/codex-main.md +21 -0
- package/examples/sub-agents/codex-review.md +20 -0
- package/examples/sub-agents/cursor-high.md +20 -0
- package/examples/sub-agents/cursor-main.md +20 -0
- package/examples/sub-agents/glm-flash.md +21 -0
- package/examples/sub-agents/glm-high.md +21 -0
- package/examples/sub-agents/pi-scout.md +20 -0
- package/package.json +11 -12
- package/dist/agent/session/request-tools.d.ts +0 -3
- package/dist/agent/session/request-tools.js +0 -20
- package/dist/models/api-keys.d.ts +0 -11
- package/dist/models/api-keys.js +0 -22
- package/dist/playbooks/memory-and-learning.md +0 -55
- package/examples/sub-agents/agents/claude-high.md +0 -23
- package/examples/sub-agents/agents/claude-main.md +0 -23
- package/examples/sub-agents/agents/codex-flash.md +0 -23
- package/examples/sub-agents/agents/codex-high.md +0 -23
- package/examples/sub-agents/agents/codex-main.md +0 -23
- package/examples/sub-agents/agents/codex-review.md +0 -23
- package/examples/sub-agents/agents/cursor-high.md +0 -22
- package/examples/sub-agents/agents/cursor-main.md +0 -22
- package/examples/sub-agents/agents/glm-flash.md +0 -23
- package/examples/sub-agents/agents/glm-high.md +0 -23
- package/examples/sub-agents/agents/scout.md +0 -30
- package/examples/sub-agents/roles/builder-hard.md +0 -34
- package/examples/sub-agents/roles/builder.md +0 -34
- package/examples/sub-agents/roles/explorer.md +0 -39
- package/examples/sub-agents/roles/git-committer.md +0 -43
- package/examples/sub-agents/roles/planner.md +0 -33
- package/examples/sub-agents/roles/reviewer.md +0 -33
- package/examples/sub-agents/roles/verifier.md +0 -35
- package/examples/sub-agents/roles/worker.md +0 -34
package/dist/subagents/runs.js
CHANGED
|
@@ -17,6 +17,7 @@ import { runArchiveEntry, runLedgerEntry } from "./run-archive.js";
|
|
|
17
17
|
import { applyPendingSettlement, createPendingSettlement, isTerminal, MAX_RUNNING_SUBAGENT_RUNS_PER_DESK, MAX_RUNNING_SUBAGENT_RUNS_PER_HOST, normalizeRunIdQuery, parseRunRecord, RUN_ARTIFACT_FILENAMES, RUN_ID_PREFIX, RUN_RETENTION_MS, randomRunIdSuffix, } from "./run-record.js";
|
|
18
18
|
import { creditTaskForRun } from "./task-settlement.js";
|
|
19
19
|
import { acquireWorkspaceLease, formatWorkspaceLeaseConflict, releaseWorkspaceLease } from "./workspace-lease.js";
|
|
20
|
+
import { reclaimManagedWorktree, reclaimTaskManagedWorktrees, settleManagedWorktree, sweepExpiredRunWorktree, } from "./worktree.js";
|
|
20
21
|
/** Registration is serialized across channel managers so the host-wide count and insertion are
|
|
21
22
|
* one admission transaction. The per-run manager queue alone cannot protect the 19 -> 20 edge
|
|
22
23
|
* when two different channels register concurrently. */
|
|
@@ -130,6 +131,8 @@ export class SubAgentRunManager {
|
|
|
130
131
|
const notify = this.options.notify;
|
|
131
132
|
if (!notify)
|
|
132
133
|
return;
|
|
134
|
+
if (record.taskId && !notice.taskId)
|
|
135
|
+
notice = { ...notice, taskId: record.taskId };
|
|
133
136
|
void Promise.resolve()
|
|
134
137
|
.then(() => notify(this.target.desk, record.channelId, notice))
|
|
135
138
|
.catch((error) => log.logWarn("subagent.notice.failed", "Run notice failed", {
|
|
@@ -140,9 +143,7 @@ export class SubAgentRunManager {
|
|
|
140
143
|
/** Start tailing a just-launched external run's artifact file for a human-readable step label
|
|
141
144
|
* (P1a). Best-effort only — see `progress-tail.ts` for the polling/pacing contract. */
|
|
142
145
|
startExternalProgressTail(record) {
|
|
143
|
-
if (this.stopped)
|
|
144
|
-
return;
|
|
145
|
-
if (!record.harness)
|
|
146
|
+
if (this.stopped || !record.harness)
|
|
146
147
|
return;
|
|
147
148
|
this.stopExternalProgressTail(record.runId);
|
|
148
149
|
const tail = startExternalProgressTail({
|
|
@@ -223,6 +224,7 @@ export class SubAgentRunManager {
|
|
|
223
224
|
async forget(record) {
|
|
224
225
|
// Delete artifacts before the durable record. If a real filesystem error occurs, retaining
|
|
225
226
|
// the record keeps the run eligible for a later daily retry instead of orphaning its files.
|
|
227
|
+
await reclaimManagedWorktree(record.artifactDir).catch(() => undefined);
|
|
226
228
|
await Promise.all(RUN_ARTIFACT_FILENAMES.map((name) => unlinkIfPresent(join(record.artifactDir, name))));
|
|
227
229
|
// Only removes the directory when it is now actually empty — a run that left extra files
|
|
228
230
|
// behind (e.g. `returns: "artifact"`) keeps its directory, matching the "not recursively
|
|
@@ -363,6 +365,8 @@ export class SubAgentRunManager {
|
|
|
363
365
|
// at settle(), means a run that crashes before any output is still resumable.
|
|
364
366
|
if (info.sessionId)
|
|
365
367
|
record.sessionId = info.sessionId;
|
|
368
|
+
if (info.expectedResumeSessionId)
|
|
369
|
+
record.expectedResumeSessionId = info.expectedResumeSessionId;
|
|
366
370
|
record.maxWallTimeSec = info.maxWallTimeSec;
|
|
367
371
|
record.processStartedAt = info.processStartedAt;
|
|
368
372
|
record.deskDir = info.deskDir;
|
|
@@ -429,11 +433,12 @@ export class SubAgentRunManager {
|
|
|
429
433
|
const record = this.runs.get(runId);
|
|
430
434
|
if (!record || record.settledAt)
|
|
431
435
|
return; // Idempotent: already settled, never replay.
|
|
432
|
-
//
|
|
433
|
-
//
|
|
434
|
-
|
|
436
|
+
// The worker/process has finished; keep the record `running` until settlement is durable
|
|
437
|
+
// and its lease is released, so restart recovery cannot publish an unprotected writer.
|
|
438
|
+
const worktree = await settleManagedWorktree(record.artifactDir, record.settlementPending?.worktree ?? input.worktree, record.runId).catch(() => undefined);
|
|
439
|
+
const effectiveInput = worktree ? { ...input, worktree } : input;
|
|
435
440
|
const snapshot = { ...record };
|
|
436
|
-
const pending = record.settlementPending ?? createPendingSettlement(
|
|
441
|
+
const pending = record.settlementPending ?? createPendingSettlement(effectiveInput, Date.now(), options.announce);
|
|
437
442
|
if (!record.settlementPending) {
|
|
438
443
|
record.settlementPending = pending;
|
|
439
444
|
try {
|
|
@@ -444,14 +449,14 @@ export class SubAgentRunManager {
|
|
|
444
449
|
throw error;
|
|
445
450
|
}
|
|
446
451
|
}
|
|
447
|
-
const outputSaved = await this.writeOutputFile(record,
|
|
452
|
+
const outputSaved = await this.writeOutputFile(record, effectiveInput.outputText);
|
|
448
453
|
// This is the commit point for the observable state transition. Both operations are
|
|
449
454
|
// synchronous and adjacent: no observer can see a terminal record while this run still
|
|
450
455
|
// owns the lease. The durable intent above covers a crash before this point.
|
|
451
456
|
releaseWorkspaceLease(record.leaseKey, record.runId);
|
|
452
457
|
record.leaseKey = undefined;
|
|
453
458
|
applyPendingSettlement(record, pending);
|
|
454
|
-
//
|
|
459
|
+
// The terminal write is best-effort:
|
|
455
460
|
// the durable intent above remains available for restart recovery if this publish fails,
|
|
456
461
|
// and the lease must not be reacquired after the process has finished.
|
|
457
462
|
await this.persist(record);
|
|
@@ -632,6 +637,9 @@ export class SubAgentRunManager {
|
|
|
632
637
|
record.wakeEnqueued = true;
|
|
633
638
|
releaseWorkspaceLease(record.leaseKey, record.runId);
|
|
634
639
|
record.leaseKey = undefined;
|
|
640
|
+
const worktree = await settleManagedWorktree(record.artifactDir).catch(() => undefined);
|
|
641
|
+
if (worktree)
|
|
642
|
+
record.worktree = worktree;
|
|
635
643
|
await this.persist(record);
|
|
636
644
|
return record.status;
|
|
637
645
|
}
|
|
@@ -712,21 +720,7 @@ export class SubAgentRunManager {
|
|
|
712
720
|
const pending = record.settlementPending;
|
|
713
721
|
record.leaseKey = undefined;
|
|
714
722
|
const outputText = await readFile(join(record.artifactDir, "output.md"), "utf-8").catch(() => "");
|
|
715
|
-
await this.settle(record.runId, {
|
|
716
|
-
status: pending.status,
|
|
717
|
-
failureReason: pending.failureReason,
|
|
718
|
-
usage: pending.usage,
|
|
719
|
-
usageKnown: pending.usageKnown,
|
|
720
|
-
costKnown: pending.costKnown,
|
|
721
|
-
turns: pending.turns,
|
|
722
|
-
toolCalls: pending.toolCalls,
|
|
723
|
-
durationMs: pending.durationMs,
|
|
724
|
-
durationEstimated: pending.durationEstimated,
|
|
725
|
-
outputText,
|
|
726
|
-
verificationVerdict: pending.verificationVerdict,
|
|
727
|
-
workspaceSummary: pending.workspaceSummary,
|
|
728
|
-
sessionId: pending.sessionId,
|
|
729
|
-
}, { announce: pending.announce }).catch((error) => {
|
|
723
|
+
await this.settle(record.runId, { ...pending, outputText }, { announce: pending.announce }).catch((error) => {
|
|
730
724
|
log.logWarn("subagent.settle.failed", "Pending settlement could not be finished", {
|
|
731
725
|
reason: errorMessage(error),
|
|
732
726
|
fields: { runId: record?.runId },
|
|
@@ -763,6 +757,7 @@ export class SubAgentRunManager {
|
|
|
763
757
|
runId: record.runId,
|
|
764
758
|
channelId: record.channelId,
|
|
765
759
|
workingDirectory: record.workingDirectory,
|
|
760
|
+
mode: record.mutates === "read" ? (record.purpose === "verify" ? "read" : "use") : "write",
|
|
766
761
|
});
|
|
767
762
|
if (rebuilt.ok) {
|
|
768
763
|
// Spec 042 D5: persist what was *actually* acquired, not just trust the old
|
|
@@ -901,17 +896,22 @@ export class SubAgentRunManager {
|
|
|
901
896
|
await this.reconcileExternalRun(record);
|
|
902
897
|
});
|
|
903
898
|
}
|
|
899
|
+
async reclaimTaskWorktrees(taskId) {
|
|
900
|
+
return reclaimTaskManagedWorktrees(this.runs.values(), taskId, (record) => this.persist(record));
|
|
901
|
+
}
|
|
904
902
|
/**
|
|
905
903
|
* Daily retention GC. A settled run and all runtime-managed artifacts are deleted together once
|
|
906
|
-
* they are at least 30 days old.
|
|
907
|
-
*
|
|
904
|
+
* they are at least 30 days old. Clean/merged managed worktrees are reclaimed after 24 hours;
|
|
905
|
+
* dirty or unmerged worktrees stay on disk and emit a one-time warning.
|
|
908
906
|
*/
|
|
909
907
|
async collectGarbageIfExpired(record, now = Date.now()) {
|
|
910
908
|
if (!record.settledAt || (record.taskId && !record.taskAccounted))
|
|
911
909
|
return;
|
|
912
910
|
if (now - record.settledAt >= RUN_RETENTION_MS) {
|
|
913
911
|
await this.forget(record);
|
|
912
|
+
return;
|
|
914
913
|
}
|
|
914
|
+
await sweepExpiredRunWorktree(record, now, (updated) => this.persist(updated));
|
|
915
915
|
}
|
|
916
916
|
async collectGarbage(now = Date.now()) {
|
|
917
917
|
for (const record of Array.from(this.runs.values())) {
|
|
@@ -926,8 +926,3 @@ export class SubAgentRunManager {
|
|
|
926
926
|
}
|
|
927
927
|
}
|
|
928
928
|
}
|
|
929
|
-
/**
|
|
930
|
-
* The channel each record directory belongs to. The id is read out of a record itself — the one
|
|
931
|
-
* lossless source, since a directory name is the *escaped* id and `__` cannot be turned back
|
|
932
|
-
* into `/` — with the directory name as the fallback for a directory without a readable record.
|
|
933
|
-
*/
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { ResolvedSubAgentConfig, SubAgentConfig } from "./
|
|
2
|
-
import type { SubAgentRunContext, SubAgentToolOptions } from "./types.js";
|
|
1
|
+
import type { ResolvedSubAgentConfig, SubAgentConfig, SubAgentRunContext, SubAgentToolOptions } from "./types.js";
|
|
3
2
|
/**
|
|
4
3
|
* `buildContextualBlocks` shared by the external dispatch path and `runToCompletion`'s internal
|
|
5
4
|
* one (spec 040 gap closed post-review): context injection is an enhancement, not a
|
|
@@ -13,6 +13,7 @@ import { listMemoryEntries } from "../memory/store.js";
|
|
|
13
13
|
import { localDayKey } from "../shared/local-time.js";
|
|
14
14
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
15
15
|
import { errorMessage } from "../shared/text-utils.js";
|
|
16
|
+
import { getExternalHarness } from "./external/registry.js";
|
|
16
17
|
import { findWorkspaceLeaseHolder, formatWorkspaceLeaseConflict } from "./workspace-lease.js";
|
|
17
18
|
/**
|
|
18
19
|
* `buildContextualBlocks` shared by the external dispatch path and `runToCompletion`'s internal
|
|
@@ -43,9 +44,10 @@ export function buildVerificationProtocol(taskPath, item) {
|
|
|
43
44
|
return [
|
|
44
45
|
"Verification protocol:",
|
|
45
46
|
scope,
|
|
46
|
-
"-
|
|
47
|
+
"- Check against the requirements, not the maker's success claims. Do not modify the implementation or fix failures; report them.",
|
|
47
48
|
"- You may run npm tests/builds and other deterministic checks; keep any generated output out of tracked files and product directories.",
|
|
48
|
-
"-
|
|
49
|
+
"- Identify the inspected version or changes, evidence for each requirement, and unverified items. Reuse verified checks only while relevant artifacts and environment remain unchanged; run missing checks or investigate concrete risks.",
|
|
50
|
+
"- PASS requires sufficient evidence for this scope. For FAIL, distinguish proven defects from blocked verification so the leader can choose repair or further checking.",
|
|
49
51
|
"- End the response with exactly one final line: VERDICT: PASS or VERDICT: FAIL.",
|
|
50
52
|
].join("\n");
|
|
51
53
|
}
|
|
@@ -59,8 +61,10 @@ export function buildVerificationProtocol(taskPath, item) {
|
|
|
59
61
|
export function assertVerifyAdmissible(config, purpose, workingDirectory) {
|
|
60
62
|
if (purpose !== "verify")
|
|
61
63
|
return;
|
|
62
|
-
if (config.runtime === "external" &&
|
|
63
|
-
|
|
64
|
+
if (config.runtime === "external" &&
|
|
65
|
+
config.harness &&
|
|
66
|
+
!getExternalHarness(config.harness)?.requiresProtocolTerminal) {
|
|
67
|
+
throw new RecoverableToolError(`Sub-agent "${config.name}" uses the ${config.harness} harness, which has no protocol terminal and cannot be used for purpose=verify.`);
|
|
64
68
|
}
|
|
65
69
|
const holder = findWorkspaceLeaseHolder(workingDirectory);
|
|
66
70
|
if (holder) {
|
|
@@ -80,6 +84,11 @@ export function buildSubAgentTask(task, config, runtimeContext, contextBlocks, r
|
|
|
80
84
|
`- Desk directory: ${runtimeContext.deskDir}`,
|
|
81
85
|
`- Channel id: ${runtimeContext.channelId}`,
|
|
82
86
|
`- Working directory: ${runContext.workingDirectory}`,
|
|
87
|
+
...(runContext.managedWorktree
|
|
88
|
+
? [
|
|
89
|
+
`- Isolated git worktree: ${runContext.managedWorktree.path} (branch: ${runContext.managedWorktree.branch ?? "detached"}, base: ${runContext.managedWorktree.baseHead.slice(0, 12)}; make all edits inside Working directory — do not modify ${runContext.managedWorktree.baseDir})`,
|
|
90
|
+
]
|
|
91
|
+
: []),
|
|
83
92
|
`- Artifact directory: ${runContext.artifactDir}`,
|
|
84
93
|
`- Your configured role: ${config.name}`,
|
|
85
94
|
];
|
|
@@ -14,6 +14,7 @@ export async function creditTaskForRun(deskDir, record, input, outputSaved, inli
|
|
|
14
14
|
output: outputSaved ? join(record.artifactDir, "output.md") : undefined,
|
|
15
15
|
tail: input.outputText.slice(-WAKE_OUTPUT_TAIL_CHARS).trim() || undefined,
|
|
16
16
|
changed: record.workspaceSummary,
|
|
17
|
+
...(record.worktree ? { worktree: record.worktree } : {}),
|
|
17
18
|
durationMs: input.durationMs,
|
|
18
19
|
...(inline ? { inline: true } : {}),
|
|
19
20
|
}, { usd: input.usage.cost.total, estimated: false, known: input.costKnown });
|
|
@@ -1,17 +1,103 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared shapes for delegation
|
|
3
|
-
* context, the worker surface, and the details payload every dispatch
|
|
4
|
-
*
|
|
2
|
+
* Shared vocabulary and shapes for delegation: role configs, the options the composition root
|
|
3
|
+
* hands in, the per-run context, the worker surface, and the details payload every dispatch
|
|
4
|
+
* returns. Leaf module within `subagents/` so `discovery`, `resolve`, `dispatch`, `task-envelope`,
|
|
5
|
+
* `internal`, and `external` can all import it without forming a cycle.
|
|
5
6
|
*/
|
|
6
7
|
import type { AgentEvent, AgentMessage, AgentState, AgentTool } from "@earendil-works/pi-agent-core";
|
|
7
8
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
8
9
|
import type { PipiclawWebToolsConfig } from "../config/tools.js";
|
|
9
10
|
import type { Executor } from "../executor.js";
|
|
10
11
|
import type { FileStore } from "../file-store.js";
|
|
12
|
+
import type { ModelRequests } from "../models/requests.js";
|
|
11
13
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
14
|
+
import type { SubAgentToolName } from "../tools/contract/names.js";
|
|
12
15
|
import type { UsageTotals } from "../usage/totals.js";
|
|
13
|
-
import type {
|
|
16
|
+
import type { ManagedWorktreeSummary, RunHarness, SubAgentThinkingLevel } from "./run-record.js";
|
|
14
17
|
import type { SubAgentRunManager } from "./runs.js";
|
|
18
|
+
export declare const DEFAULT_SUB_AGENT_TOOLS: readonly ["read", "bash"];
|
|
19
|
+
export declare const DEFAULT_MAX_TURNS = 32;
|
|
20
|
+
export declare const DEFAULT_MAX_TOOL_CALLS = 96;
|
|
21
|
+
export declare const DEFAULT_MAX_WALL_TIME_SEC = 600;
|
|
22
|
+
export declare const DEFAULT_BASH_TIMEOUT_SEC = 120;
|
|
23
|
+
/** External runs have no turn/tool-call budget (D5); wall time is their only lever. */
|
|
24
|
+
export declare const DEFAULT_EXTERNAL_MAX_WALL_TIME_SEC = 3600;
|
|
25
|
+
export declare const ALLOWED_CONTEXT_MODES: readonly ["isolated", "contextual"];
|
|
26
|
+
export declare const ALLOWED_MEMORY_MODES: readonly ["none", "index"];
|
|
27
|
+
export declare const ALLOWED_RUNTIMES: readonly ["internal", "external"];
|
|
28
|
+
export declare const ALLOWED_WORKLOADS: readonly ["light", "heavy"];
|
|
29
|
+
export declare const ALLOWED_MUTATES: readonly ["read", "write"];
|
|
30
|
+
/** Internal work/verify default, aligned with the main agent's DEFAULT_MAIN_THINKING_LEVEL
|
|
31
|
+
* (channel-runner.ts). External work leaves thinkingLevel unset instead (see `resolve.ts`):
|
|
32
|
+
* pipiclaw has no standing to pick a reasoning effort for another CLI's own configuration. */
|
|
33
|
+
export declare const DEFAULT_THINKING_LEVEL: SubAgentThinkingLevel;
|
|
34
|
+
export type SubAgentContextMode = (typeof ALLOWED_CONTEXT_MODES)[number];
|
|
35
|
+
export type SubAgentMemoryMode = (typeof ALLOWED_MEMORY_MODES)[number];
|
|
36
|
+
export type SubAgentRoleRuntime = (typeof ALLOWED_RUNTIMES)[number];
|
|
37
|
+
export type SubAgentWorkload = (typeof ALLOWED_WORKLOADS)[number];
|
|
38
|
+
export type SubAgentMutates = (typeof ALLOWED_MUTATES)[number];
|
|
39
|
+
interface SubAgentConfigFields {
|
|
40
|
+
name: string;
|
|
41
|
+
description: string;
|
|
42
|
+
systemPrompt: string;
|
|
43
|
+
tools: SubAgentToolName[];
|
|
44
|
+
model?: Model<Api>;
|
|
45
|
+
modelRef?: string;
|
|
46
|
+
maxTurns: number;
|
|
47
|
+
maxToolCalls: number;
|
|
48
|
+
maxWallTimeSec: number;
|
|
49
|
+
bashTimeoutSec: number;
|
|
50
|
+
contextMode: SubAgentContextMode;
|
|
51
|
+
memory: SubAgentMemoryMode;
|
|
52
|
+
paths: string[];
|
|
53
|
+
/** Unset means "apply the purpose-based default at resolution time" (spec 032 D3). */
|
|
54
|
+
thinkingLevel?: SubAgentThinkingLevel;
|
|
55
|
+
filePath?: string;
|
|
56
|
+
source: "predefined" | "inline";
|
|
57
|
+
/** Defaults to "internal"; existing role files therefore parse unchanged (spec 040, D5). */
|
|
58
|
+
runtime: SubAgentRoleRuntime;
|
|
59
|
+
/** External only. */
|
|
60
|
+
harness?: RunHarness;
|
|
61
|
+
/** External only: the raw, unvalidated command line. Tokenized by the harness at invocation
|
|
62
|
+
* time (D4), never by discovery — discovery only checks that it is non-empty. */
|
|
63
|
+
command?: string;
|
|
64
|
+
/** exec harness only: run `command` through `/bin/sh -lc` instead of argv-direct spawn (D4). */
|
|
65
|
+
shell?: boolean;
|
|
66
|
+
/** External only: env vars appended to (and overriding) the inherited environment (D8.2). */
|
|
67
|
+
env?: Record<string, string>;
|
|
68
|
+
/** Drives system-prompt directory grouping (D11); defaults by runtime when unset. */
|
|
69
|
+
workload?: SubAgentWorkload;
|
|
70
|
+
/** Required for external (an explicit declaration); optional for internal (inferred from `tools`). */
|
|
71
|
+
mutates?: SubAgentMutates;
|
|
72
|
+
/** External only: the harness's own model string, passed through unresolved (D5) — never
|
|
73
|
+
* looked up in `models.json`, because pipiclaw cannot validate another CLI's model names. */
|
|
74
|
+
externalModelRef?: string;
|
|
75
|
+
/** Set when the role is otherwise valid but currently cannot be invoked (e.g. missing binary).
|
|
76
|
+
* The role is still listed — never silently dropped (D5) — and invocation must explain why. */
|
|
77
|
+
unavailable?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface InternalSubAgentConfig extends SubAgentConfigFields {
|
|
80
|
+
runtime: "internal";
|
|
81
|
+
}
|
|
82
|
+
export interface ExternalSubAgentConfig extends SubAgentConfigFields {
|
|
83
|
+
runtime: "external";
|
|
84
|
+
harness: RunHarness;
|
|
85
|
+
command: string;
|
|
86
|
+
mutates: SubAgentMutates;
|
|
87
|
+
model?: never;
|
|
88
|
+
modelRef?: never;
|
|
89
|
+
}
|
|
90
|
+
export type SubAgentConfig = InternalSubAgentConfig | ExternalSubAgentConfig;
|
|
91
|
+
export interface ResolvedInternalSubAgentConfig extends InternalSubAgentConfig {
|
|
92
|
+
model: Model<Api>;
|
|
93
|
+
modelRef: string;
|
|
94
|
+
}
|
|
95
|
+
export type ResolvedSubAgentConfig = ResolvedInternalSubAgentConfig | ExternalSubAgentConfig;
|
|
96
|
+
export interface SubAgentDiscoveryResult {
|
|
97
|
+
directory: string;
|
|
98
|
+
agents: SubAgentConfig[];
|
|
99
|
+
warnings: string[];
|
|
100
|
+
}
|
|
15
101
|
/**
|
|
16
102
|
* Fields every delegation dispatch returns as its tool-result details. `kind` is not among them: `withToolDetails`
|
|
17
103
|
* stamps it from the registration name when the tool set is built (see `tools/contract/details.ts`; `tools/subagent.ts` exports the stamped `SubAgentToolDetails`).
|
|
@@ -41,6 +127,8 @@ export interface SubAgentToolFields {
|
|
|
41
127
|
* not as another tool result.
|
|
42
128
|
*/
|
|
43
129
|
dispatched?: boolean;
|
|
130
|
+
/** Structured worktree details when `worktree: true` was requested. */
|
|
131
|
+
worktree?: ManagedWorktreeSummary;
|
|
44
132
|
}
|
|
45
133
|
/** Exported for `subagent_run op=follow_up` (spec 042 D7), which constructs one of these for
|
|
46
134
|
* its own new run rather than a hand-rolled envelope. */
|
|
@@ -51,11 +139,18 @@ export interface SubAgentRunContext {
|
|
|
51
139
|
item?: string;
|
|
52
140
|
workingDirectory: string;
|
|
53
141
|
artifactDir: string;
|
|
142
|
+
managedWorktree?: {
|
|
143
|
+
path: string;
|
|
144
|
+
baseDir: string;
|
|
145
|
+
branch: string | null;
|
|
146
|
+
baseHead: string;
|
|
147
|
+
};
|
|
54
148
|
}
|
|
55
149
|
/** The delegation parameters both invocation surfaces share (`task` plus routing). */
|
|
56
150
|
export interface DelegationParams {
|
|
57
151
|
task: string;
|
|
58
152
|
workingDirectory?: string;
|
|
153
|
+
worktree?: boolean;
|
|
59
154
|
purpose?: "work" | "verify";
|
|
60
155
|
item?: string;
|
|
61
156
|
}
|
|
@@ -89,7 +184,9 @@ export interface WorkerToolRequest {
|
|
|
89
184
|
workspaceDir: string;
|
|
90
185
|
webConfig?: PipiclawWebToolsConfig;
|
|
91
186
|
rtkEnabled?: boolean;
|
|
187
|
+
bashInterceptorEnabled?: boolean;
|
|
92
188
|
bashDefaultTimeoutSeconds: number;
|
|
189
|
+
leaseOwnerRunId?: string;
|
|
93
190
|
}
|
|
94
191
|
/** Builds a sub-agent's scoped tool set from the shared registry; injected by `tools/index.ts`. */
|
|
95
192
|
export type BuildWorkerTools = (request: WorkerToolRequest) => AgentTool<any>[];
|
|
@@ -102,8 +199,9 @@ export interface SubAgentToolOptions {
|
|
|
102
199
|
workingDirectory?: string;
|
|
103
200
|
getCurrentModel: () => Model<Api>;
|
|
104
201
|
getAvailableModels: () => Model<Api>[];
|
|
105
|
-
|
|
202
|
+
modelRequests: ModelRequests;
|
|
106
203
|
workspaceDir: string;
|
|
204
|
+
appHomeDir?: string;
|
|
107
205
|
deskDir: string;
|
|
108
206
|
getSubAgentDiscovery?: () => SubAgentDiscoveryResult;
|
|
109
207
|
/** `settings.subagentModel` (spec 032 D5); null/undefined means unset. */
|
|
@@ -111,6 +209,7 @@ export interface SubAgentToolOptions {
|
|
|
111
209
|
securityConfig?: SecurityConfig;
|
|
112
210
|
webConfig?: PipiclawWebToolsConfig;
|
|
113
211
|
rtkEnabled?: boolean;
|
|
212
|
+
bashInterceptorEnabled?: boolean;
|
|
114
213
|
runtimeContext: {
|
|
115
214
|
workspaceDir: string;
|
|
116
215
|
/** The desk the delegating turn belongs to, and its directory (tasks, memory). */
|
|
@@ -120,7 +219,6 @@ export interface SubAgentToolOptions {
|
|
|
120
219
|
};
|
|
121
220
|
createWorker?: (config: {
|
|
122
221
|
subAgent: ResolvedInternalSubAgentConfig;
|
|
123
|
-
apiKey: string;
|
|
124
222
|
tools: AgentTool<any>[];
|
|
125
223
|
}) => SubAgentWorker;
|
|
126
224
|
/** Test seam for failures while constructing the scoped tool set after durable registration. */
|
|
@@ -152,3 +250,4 @@ export interface DelegationResult {
|
|
|
152
250
|
}
|
|
153
251
|
/** Builds the tool set one internal run's worker gets (default: `internal/worker.ts`'s `buildSubagentTools`). */
|
|
154
252
|
export type BuildSubagentTools = (executor: Executor, bashTimeoutSec: number, options: SubAgentToolOptions, runContext: SubAgentRunContext) => AgentTool<any>[];
|
|
253
|
+
export {};
|
package/dist/subagents/types.js
CHANGED
|
@@ -1 +1,16 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const DEFAULT_SUB_AGENT_TOOLS = ["read", "bash"];
|
|
2
|
+
export const DEFAULT_MAX_TURNS = 32;
|
|
3
|
+
export const DEFAULT_MAX_TOOL_CALLS = 96;
|
|
4
|
+
export const DEFAULT_MAX_WALL_TIME_SEC = 600;
|
|
5
|
+
export const DEFAULT_BASH_TIMEOUT_SEC = 120;
|
|
6
|
+
/** External runs have no turn/tool-call budget (D5); wall time is their only lever. */
|
|
7
|
+
export const DEFAULT_EXTERNAL_MAX_WALL_TIME_SEC = 3600;
|
|
8
|
+
export const ALLOWED_CONTEXT_MODES = ["isolated", "contextual"];
|
|
9
|
+
export const ALLOWED_MEMORY_MODES = ["none", "index"];
|
|
10
|
+
export const ALLOWED_RUNTIMES = ["internal", "external"];
|
|
11
|
+
export const ALLOWED_WORKLOADS = ["light", "heavy"];
|
|
12
|
+
export const ALLOWED_MUTATES = ["read", "write"];
|
|
13
|
+
/** Internal work/verify default, aligned with the main agent's DEFAULT_MAIN_THINKING_LEVEL
|
|
14
|
+
* (channel-runner.ts). External work leaves thinkingLevel unset instead (see `resolve.ts`):
|
|
15
|
+
* pipiclaw has no standing to pick a reasoning effort for another CLI's own configuration. */
|
|
16
|
+
export const DEFAULT_THINKING_LEVEL = "medium";
|
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* plus the parked-review's own judgement rather than a second locking dimension.
|
|
11
|
-
*
|
|
12
|
-
* Global, not per-channel: two channels pointed at the same checkout must still exclude each
|
|
13
|
-
* other. The main agent's own write/edit/bash calls deliberately do **not** participate — see
|
|
14
|
-
* the design doc D10.1 for why (it would deadlock a run against the very turn that dispatched
|
|
15
|
-
* it, and turns this into a runtime-wide concurrency redesign this spec does not attempt).
|
|
2
|
+
* Process-wide checkout RW leases for delegations (spec 040 D10.1, Direction 1.3):
|
|
3
|
+
* - `mode: "write"` (default): exclusive — conflicts with any overlapping write OR read lease, and
|
|
4
|
+
* blocks main/task-session `write`/`edit` calls targeting the leased checkout.
|
|
5
|
+
* - `mode: "read"` (`purpose: "verify"` runs with `mutates: "read"`): shared — coexists with other
|
|
6
|
+
* read leases on overlapping paths while blocking write delegations and main/task `write`/`edit`
|
|
7
|
+
* calls so files cannot move mid-verification.
|
|
8
|
+
* - `mode: "use"`: ordinary read-only work may overlap writers, but pins its directory against
|
|
9
|
+
* cleanup. Cleanup excludes all users and holds admission closed across asynchronous Git I/O.
|
|
16
10
|
*/
|
|
11
|
+
export type WorkspaceLeaseMode = "write" | "read" | "use";
|
|
17
12
|
export interface WorkspaceLeaseHolder {
|
|
18
13
|
runId: string;
|
|
19
14
|
channelId: string;
|
|
20
15
|
workingDirectory: string;
|
|
16
|
+
mode?: WorkspaceLeaseMode;
|
|
21
17
|
}
|
|
22
|
-
/**
|
|
23
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a directory or file path (including not-yet-created files for `write`) through symlinks
|
|
20
|
+
* so an alias or `..` segment cannot bypass an active checkout lease.
|
|
21
|
+
*/
|
|
22
|
+
export declare function workspaceLeaseKey(targetPath: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Atomically exclude every other directory user, then hold that exclusion across inspection and
|
|
25
|
+
* removal. A finished worker may clean up under its own still-held lease; never release that lease
|
|
26
|
+
* here — settlement remains the run manager's responsibility.
|
|
27
|
+
*/
|
|
28
|
+
export declare function withWorkspaceCleanupLease<T>(workingDirectory: string, ownerRunId: string | undefined, cleanup: () => Promise<T>): Promise<T | undefined>;
|
|
24
29
|
export type AcquireWorkspaceLeaseResult = {
|
|
25
30
|
ok: true;
|
|
26
31
|
leaseKey: string;
|
|
@@ -31,15 +36,27 @@ export type AcquireWorkspaceLeaseResult = {
|
|
|
31
36
|
};
|
|
32
37
|
export declare function acquireWorkspaceLease(holder: WorkspaceLeaseHolder): AcquireWorkspaceLeaseResult;
|
|
33
38
|
/**
|
|
34
|
-
* Spec 042 D5: release only the caller's own lease
|
|
35
|
-
*
|
|
36
|
-
* `settle()` and delete the *new* holder's lease for the same key, and a caller could otherwise
|
|
37
|
-
* double-release harmlessly-in-appearance but incorrectly-in-general. `runId` must match the
|
|
38
|
-
* current holder for the delete to happen; anything else (already released, held by someone else)
|
|
39
|
-
* is a no-op rather than an assertion failure — callers already treat "did I ever hold it" as
|
|
40
|
-
* something they cannot always know for certain (e.g. a settle() racing a lease rebuild).
|
|
39
|
+
* Spec 042 D5: release only the caller's own lease (`runId` must match). Shared read leases remove
|
|
40
|
+
* only their own entry and delete `leaseKey` once the last holder settles.
|
|
41
41
|
*/
|
|
42
42
|
export declare function releaseWorkspaceLease(leaseKey: string | undefined, runId: string): void;
|
|
43
|
-
/** Read-only check for
|
|
43
|
+
/** Read-only check for pre-flight gates (`purpose=verify`, D9): returns any overlapping *write* holder. */
|
|
44
44
|
export declare function findWorkspaceLeaseHolder(workingDirectory: string): WorkspaceLeaseHolder | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Check whether mutating (or reading) `targetPath` conflicts with an active delegation lease,
|
|
47
|
+
* ignoring `excludeRunId` (the worker's own run) and Pipiclaw's desk control-plane files (`tasks/`, etc.).
|
|
48
|
+
*/
|
|
49
|
+
export declare function findConflictingWorkspaceLease(targetPath: string, options?: {
|
|
50
|
+
mode?: WorkspaceLeaseMode;
|
|
51
|
+
excludeRunId?: string;
|
|
52
|
+
deskDir?: string;
|
|
53
|
+
}): WorkspaceLeaseHolder | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Guard for main-session and task-session `write`/`edit` tools (Direction 1.3): rejects mutations
|
|
56
|
+
* to a checkout currently locked by a write delegation or being inspected by a verification read lease.
|
|
57
|
+
*/
|
|
58
|
+
export declare function assertPathWritableUnderLease(targetPath: string, options?: {
|
|
59
|
+
excludeRunId?: string;
|
|
60
|
+
deskDir?: string;
|
|
61
|
+
}): void;
|
|
45
62
|
export declare function formatWorkspaceLeaseConflict(heldBy: WorkspaceLeaseHolder): string;
|