@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
|
@@ -7,16 +7,15 @@ import { join } from "path";
|
|
|
7
7
|
import { loadDetachedMaintenanceContext } from "../agent/maintenance-context.js";
|
|
8
8
|
import { createRunner } from "../agent/runner-factory.js";
|
|
9
9
|
import { scanConversationsForInterruptedTurns } from "../agent/turn/turn-recovery.js";
|
|
10
|
-
import {
|
|
10
|
+
import { ensureModelOnboarding } from "../app/auth-command.js";
|
|
11
|
+
import { BootstrapExitError, bootstrapAppHome, DEFAULT_BOOTSTRAP_PATHS, parseArgs, printBootstrapSummary, printStartupReadySummary, readCliVersion, } from "../app/home.js";
|
|
11
12
|
import { prepareAppServices } from "../app/services.js";
|
|
12
13
|
import { CHANNELS_INDEX_FILENAME, createChannelIndex } from "../channel/channel-index.js";
|
|
13
14
|
import { ChannelStore } from "../channel/store.js";
|
|
14
15
|
import { PipiclawSettingsManager } from "../config/settings.js";
|
|
15
16
|
import { getToolsConfigPath, loadToolsConfig } from "../config/tools.js";
|
|
16
|
-
import { buildDeskList } from "../desk/commands.js";
|
|
17
17
|
import { initializeDefaultDesk } from "../desk/default.js";
|
|
18
18
|
import { getDeskDir } from "../desk/paths.js";
|
|
19
|
-
import { listDesks } from "../desk/registry.js";
|
|
20
19
|
import { StartupRefusal } from "../desk/startup-error.js";
|
|
21
20
|
import { createEventsWatcher } from "../events/watcher.js";
|
|
22
21
|
import { createExecutor } from "../executor.js";
|
|
@@ -24,6 +23,7 @@ import { createFileStore } from "../file-store.js";
|
|
|
24
23
|
import { createJobRuntime } from "../jobs/runtime.js";
|
|
25
24
|
import * as log from "../log.js";
|
|
26
25
|
import { MemoryMaintenanceScheduler } from "../memory/scheduler.js";
|
|
26
|
+
import { flushModelCredentials } from "../models/credential-work.js";
|
|
27
27
|
import { defaultModel } from "../models/runtime.js";
|
|
28
28
|
import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
|
|
29
29
|
import { logSecurityEvent } from "../security/logger.js";
|
|
@@ -31,6 +31,7 @@ import { fileStamp } from "../shared/format.js";
|
|
|
31
31
|
import { errorMessage } from "../shared/text-utils.js";
|
|
32
32
|
import { renderRunNotice } from "../subagents/commands.js";
|
|
33
33
|
import { createSubAgentRuntime } from "../subagents/run-registry.js";
|
|
34
|
+
import { findConflictingWorkspaceLease } from "../subagents/workspace-lease.js";
|
|
34
35
|
import { taskSessionPath } from "../tasks/session-path.js";
|
|
35
36
|
import { getUsageLedger } from "../usage/ledger.js";
|
|
36
37
|
import { acquireDaemonLock, tryAcquireDaemonLock } from "./daemon-lock.js";
|
|
@@ -116,7 +117,7 @@ async function buildRuntimeContext(options, daemonLock) {
|
|
|
116
117
|
const sessionResetChains = new Map();
|
|
117
118
|
const activeTasks = new Set();
|
|
118
119
|
/** Channels with a `/stop` watchdog in flight, so a burst of `/stop` starts only one. */
|
|
119
|
-
const stopWatchdogs = new
|
|
120
|
+
const stopWatchdogs = new Map();
|
|
120
121
|
let durableDispatch;
|
|
121
122
|
let shuttingDown = false;
|
|
122
123
|
const executor = options.executor ?? createExecutor();
|
|
@@ -162,15 +163,17 @@ async function buildRuntimeContext(options, daemonLock) {
|
|
|
162
163
|
});
|
|
163
164
|
}
|
|
164
165
|
},
|
|
165
|
-
createWatcher: (target) =>
|
|
166
|
-
|
|
167
|
-
|
|
166
|
+
createWatcher: (target) => {
|
|
167
|
+
if (options.createEventsWatcher)
|
|
168
|
+
return options.createEventsWatcher(target);
|
|
169
|
+
const security = loadSecurityConfigWithDiagnostics(appHomeDir).config;
|
|
170
|
+
return createEventsWatcher({
|
|
168
171
|
...target,
|
|
169
172
|
isBound: (channelId) => deskRuntime.isBoundTo(channelId, target.desk),
|
|
170
173
|
isReachable: (channelId) => transports.isReachable(channelId),
|
|
171
174
|
sink: ingress,
|
|
172
175
|
executor,
|
|
173
|
-
commandGuardConfig:
|
|
176
|
+
commandGuardConfig: security.enabled ? security.commandGuard : undefined,
|
|
174
177
|
historyPath: options.paths.eventHistoryPath,
|
|
175
178
|
dispatch,
|
|
176
179
|
spawnTask: createTaskSpawner({
|
|
@@ -178,11 +181,26 @@ async function buildRuntimeContext(options, daemonLock) {
|
|
|
178
181
|
wake: () => taskLane.notify(),
|
|
179
182
|
notify: (desk, channelId, text) => deskRuntime.sendFromDesk(desk, channelId, text),
|
|
180
183
|
}),
|
|
181
|
-
})
|
|
184
|
+
});
|
|
185
|
+
},
|
|
182
186
|
send: (channelId, text) => pushTo(channelId, { text }),
|
|
183
187
|
isChannelBusy: (channelId) => channelRunners.get(channelId)?.isBusy() ?? false,
|
|
188
|
+
isDeskBusy: (desk, currentCwd) => {
|
|
189
|
+
const runningTask = taskLane?.runningTaskInDesk(desk);
|
|
190
|
+
if (runningTask)
|
|
191
|
+
return `后台任务 \`${runningTask}\` 正在执行当前步骤`;
|
|
192
|
+
const lease = findConflictingWorkspaceLease(currentCwd, {
|
|
193
|
+
mode: "write",
|
|
194
|
+
deskDir: getDeskDir(workspaceDir, desk),
|
|
195
|
+
});
|
|
196
|
+
if (lease)
|
|
197
|
+
return `委派 \`${lease.runId}\` 正在占用当前工作目录`;
|
|
198
|
+
return undefined;
|
|
199
|
+
},
|
|
200
|
+
describeChannel: (channelId) => labelOf(channelId),
|
|
184
201
|
releaseRunner: (channelId) => releaseCachedRunner(channelRunners, channelId),
|
|
185
202
|
onBindingChanged: () => channelIndex.noteBindingChanged(),
|
|
203
|
+
onActivated: () => taskLane?.notify(),
|
|
186
204
|
});
|
|
187
205
|
await deskRuntime.load();
|
|
188
206
|
const isBoundTo = (channelId, desk) => deskRuntime.isBoundTo(channelId, desk);
|
|
@@ -204,6 +222,7 @@ async function buildRuntimeContext(options, daemonLock) {
|
|
|
204
222
|
const describeChannel = (desk, channelId) => ({
|
|
205
223
|
label: labelOf(channelId),
|
|
206
224
|
boundHere: deskRuntime.isBoundTo(channelId, desk),
|
|
225
|
+
reachable: transports.isReachable(channelId),
|
|
207
226
|
});
|
|
208
227
|
const archiveIncomingMessage = async (channelId, message, contextLabel) => {
|
|
209
228
|
try {
|
|
@@ -220,6 +239,7 @@ async function buildRuntimeContext(options, daemonLock) {
|
|
|
220
239
|
/** What every runner of a channel shares: the desk's managers, settings and how the channel is named and answered. */
|
|
221
240
|
const runnerPaths = (conversation, channelId) => ({
|
|
222
241
|
fileStore,
|
|
242
|
+
executor,
|
|
223
243
|
jobManager: jobs.get(conversation.desk),
|
|
224
244
|
runManager: runs.get(conversation.desk),
|
|
225
245
|
appHomeDir,
|
|
@@ -253,13 +273,21 @@ async function buildRuntimeContext(options, daemonLock) {
|
|
|
253
273
|
return undefined;
|
|
254
274
|
const { conversation } = resolution;
|
|
255
275
|
const existing = channelRunners.get(channelId);
|
|
256
|
-
if (existing
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
276
|
+
if (existing) {
|
|
277
|
+
if (existing.conversation.desk === conversation.desk && existing.conversation.cwd === conversation.cwd) {
|
|
278
|
+
// Re-insert to move this channel to the end (most-recently-used) of the Map's
|
|
279
|
+
// iteration order, which evictIdleRunnersOverCap relies on.
|
|
280
|
+
channelRunners.delete(channelId);
|
|
281
|
+
channelRunners.set(channelId, existing);
|
|
282
|
+
return existing;
|
|
283
|
+
}
|
|
284
|
+
// Keep the in-flight runner reachable for `/stop` and steer until its turn settles; the
|
|
285
|
+
// next call after it finishes replaces it with one built for the updated desk/cwd.
|
|
286
|
+
if (existing.isBusy())
|
|
287
|
+
return existing;
|
|
288
|
+
void releaseCachedRunner(channelRunners, channelId);
|
|
262
289
|
}
|
|
290
|
+
runtimeSettingsManager.reload();
|
|
263
291
|
const runner = createRunner(conversation, { ...runnerPaths(conversation, channelId), getTaskControl });
|
|
264
292
|
channelRunners.set(channelId, runner);
|
|
265
293
|
void evictIdleRunnersOverCap(channelRunners);
|
|
@@ -281,6 +309,7 @@ async function buildRuntimeContext(options, daemonLock) {
|
|
|
281
309
|
isShuttingDown,
|
|
282
310
|
createRunner: (conversation) => createRunner(conversation, {
|
|
283
311
|
profile: { kind: "request" },
|
|
312
|
+
executor,
|
|
284
313
|
jobManager: jobs.get(conversation.desk),
|
|
285
314
|
runManager: runs.get(conversation.desk),
|
|
286
315
|
appHomeDir,
|
|
@@ -305,10 +334,13 @@ async function buildRuntimeContext(options, daemonLock) {
|
|
|
305
334
|
ensureBinding: (channelId, desk) => deskRuntime.ensureDefaultBinding(channelId, desk),
|
|
306
335
|
unbind: (channelId) => deskRuntime.unbind(channelId),
|
|
307
336
|
deskPort: (channelId) => ({
|
|
308
|
-
list:
|
|
337
|
+
list: () => deskRuntime.listDeskItems(channelId, labelOf),
|
|
309
338
|
channelIndexPath: join(workspaceDir, CHANNELS_INDEX_FILENAME),
|
|
310
|
-
create: (name) => deskRuntime.create(name),
|
|
339
|
+
create: (name, cwd) => deskRuntime.create(name, cwd),
|
|
311
340
|
bind: (name) => deskRuntime.bind(channelId, name),
|
|
341
|
+
cwd: (input) => deskRuntime.cwd(channelId, input),
|
|
342
|
+
archive: (name) => deskRuntime.archive(channelId, name),
|
|
343
|
+
unarchive: (name) => deskRuntime.unarchive(name),
|
|
312
344
|
}),
|
|
313
345
|
describeChannel,
|
|
314
346
|
cliVersion,
|
|
@@ -388,16 +420,19 @@ async function buildRuntimeContext(options, daemonLock) {
|
|
|
388
420
|
const taskLane = new TaskLane({
|
|
389
421
|
getActiveDesks: () => deskRuntime.activeDesks(),
|
|
390
422
|
getDeskDir: (desk) => getDeskDir(workspaceDir, desk),
|
|
423
|
+
getDeskCwd: (desk) => deskRuntime.deskCwd(desk),
|
|
391
424
|
isBoundTo,
|
|
425
|
+
onDeskIdle: (desk) => void deskRuntime.reconcileActivity(desk),
|
|
392
426
|
isReachable: (channelId) => transports.isReachable(channelId),
|
|
393
|
-
// One runner per executing task, built from
|
|
427
|
+
// One runner per executing task, built from its desk's conversation record even when the
|
|
428
|
+
// report channel is currently bound to another desk (Direction 1.2).
|
|
394
429
|
createTaskRunner: (target) => {
|
|
395
|
-
const
|
|
396
|
-
if (
|
|
397
|
-
throw new Error(`Task ${target.taskId}:
|
|
430
|
+
const conversation = deskRuntime.taskConversation(target.desk, target.channelId);
|
|
431
|
+
if (!conversation) {
|
|
432
|
+
throw new Error(`Task ${target.taskId}: desk ${target.desk} is unavailable for channel ${target.channelId}`);
|
|
398
433
|
}
|
|
399
|
-
return createRunner(
|
|
400
|
-
...runnerPaths(
|
|
434
|
+
return createRunner(conversation, {
|
|
435
|
+
...runnerPaths(conversation, target.channelId),
|
|
401
436
|
profile: {
|
|
402
437
|
kind: "task",
|
|
403
438
|
sessionPath: taskSessionPath(target.deskDir, target.taskId),
|
|
@@ -434,7 +469,9 @@ async function buildRuntimeContext(options, daemonLock) {
|
|
|
434
469
|
// gets a lightweight disk-backed context instead of resurrecting a full runner.
|
|
435
470
|
getRuntimeContext: async (conversation) => {
|
|
436
471
|
const runner = channelRunners.get(conversation.channelId);
|
|
437
|
-
if (runner &&
|
|
472
|
+
if (runner &&
|
|
473
|
+
runner.conversation.desk === conversation.desk &&
|
|
474
|
+
runner.conversation.cwd === conversation.cwd) {
|
|
438
475
|
return runner.getMemoryMaintenanceContext();
|
|
439
476
|
}
|
|
440
477
|
return loadDetachedMaintenanceContext({
|
|
@@ -465,6 +502,7 @@ async function buildRuntimeContext(options, daemonLock) {
|
|
|
465
502
|
channelIndex,
|
|
466
503
|
channelRunners,
|
|
467
504
|
activeTasks,
|
|
505
|
+
flushCredentials: () => flushModelCredentials(options.paths.authConfigPath),
|
|
468
506
|
markShuttingDown: () => {
|
|
469
507
|
shuttingDown = true;
|
|
470
508
|
},
|
|
@@ -509,11 +547,33 @@ export async function bootstrap(argv, options = {}) {
|
|
|
509
547
|
parseArgs(argv, paths, io);
|
|
510
548
|
const bootstrapResult = bootstrapAppHome(paths);
|
|
511
549
|
printBootstrapSummary(bootstrapResult, io, paths);
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
550
|
+
let daemonLock;
|
|
551
|
+
try {
|
|
552
|
+
daemonLock = await acquireDaemonLock(paths.appHomeDir);
|
|
553
|
+
}
|
|
554
|
+
catch (error) {
|
|
555
|
+
if (!(error instanceof StartupRefusal))
|
|
556
|
+
throw error;
|
|
557
|
+
io.error(error.message);
|
|
558
|
+
throw new BootstrapExitError(1);
|
|
559
|
+
}
|
|
560
|
+
let readiness;
|
|
561
|
+
if (startServices || options.interactive !== undefined) {
|
|
562
|
+
const interactive = options.interactive ??
|
|
563
|
+
(startServices && options.io === undefined && process.stdin.isTTY === true && process.stderr.isTTY === true);
|
|
564
|
+
try {
|
|
565
|
+
readiness = await ensureModelOnboarding({
|
|
566
|
+
paths,
|
|
567
|
+
io,
|
|
568
|
+
interactive,
|
|
569
|
+
confirmLogin: options.confirmModelLogin,
|
|
570
|
+
performLogin: options.performModelLogin,
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
catch (error) {
|
|
574
|
+
await daemonLock.release();
|
|
575
|
+
throw error;
|
|
576
|
+
}
|
|
517
577
|
}
|
|
518
578
|
const { settingsManager } = prepareAppServices(paths);
|
|
519
579
|
log.logStartup(paths.workspaceDir);
|
|
@@ -521,6 +581,7 @@ export async function bootstrap(argv, options = {}) {
|
|
|
521
581
|
try {
|
|
522
582
|
runtime = await createRuntimeContext({
|
|
523
583
|
paths,
|
|
584
|
+
daemonLock,
|
|
524
585
|
...(options.transports ? { transports: options.transports } : {}),
|
|
525
586
|
registerSignalHandlers,
|
|
526
587
|
startServices,
|
|
@@ -533,6 +594,9 @@ export async function bootstrap(argv, options = {}) {
|
|
|
533
594
|
io.error(error.message);
|
|
534
595
|
throw new BootstrapExitError(1);
|
|
535
596
|
}
|
|
597
|
+
if (startServices) {
|
|
598
|
+
printStartupReadySummary(io, paths, runtime.transports.all().map((transport) => transport.name), readiness);
|
|
599
|
+
}
|
|
536
600
|
return {
|
|
537
601
|
store: runtime.store,
|
|
538
602
|
shutdown: async () => {
|
|
@@ -15,8 +15,8 @@ export async function tryAcquireDaemonLock(appHomeDir) {
|
|
|
15
15
|
return {
|
|
16
16
|
kind: "held",
|
|
17
17
|
holder: result.heldBy
|
|
18
|
-
? `pid ${result.heldBy.pid}
|
|
19
|
-
: "
|
|
18
|
+
? `pid ${result.heldBy.pid}(主机 ${result.heldBy.hostname},启动于 ${result.heldBy.acquiredAt})`
|
|
19
|
+
: "另一个进程",
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
/** Take the lock, or refuse to start and say who holds it. */
|
|
@@ -24,5 +24,5 @@ export async function acquireDaemonLock(appHomeDir) {
|
|
|
24
24
|
const result = await tryAcquireDaemonLock(appHomeDir);
|
|
25
25
|
if (result.kind === "acquired")
|
|
26
26
|
return result.handle;
|
|
27
|
-
throw new StartupRefusal(
|
|
27
|
+
throw new StartupRefusal(`目录 ${appHomeDir} 已被另一个 Pipiclaw 进程占用(${result.holder})。\n如需与正在运行的服务对话,请直接执行 \`pipiclaw tui\`;如需重启服务,请先停止原进程(若确认无进程运行,可删除锁文件 ${lockPath(appHomeDir)})。`);
|
|
28
28
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { BindingsFile, ConversationKind, CreateDeskOutcome, DeskConversation } from "../desk/types.js";
|
|
1
|
+
import { type BindOutcome, type DeskListItem } from "../desk/commands.js";
|
|
2
|
+
import type { ArchiveDeskOutcome, BindingsFile, ConversationKind, CreateDeskOutcome, DeskConversation, DeskCwdOutcome, UnarchiveDeskOutcome } from "../desk/types.js";
|
|
3
3
|
export type ChannelResolution = {
|
|
4
4
|
kind: "bound";
|
|
5
5
|
conversation: DeskConversation;
|
|
@@ -41,11 +41,19 @@ export interface DeskRuntimeOptions {
|
|
|
41
41
|
createWatcher: (target: {
|
|
42
42
|
desk: string;
|
|
43
43
|
deskDir: string;
|
|
44
|
+
cwd: string;
|
|
44
45
|
}) => DeskWatcher;
|
|
45
46
|
/** The transport's plain send, for background notices that pass the binding guard. */
|
|
46
47
|
send: (channelId: string, text: string) => Promise<boolean>;
|
|
47
48
|
/** Whether the channel has a turn in flight; `/desk bind` refuses then (D5 step 1). */
|
|
48
49
|
isChannelBusy: (channelId: string) => boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Optional check for active execution in `desk` (e.g. a running task step or checkout lease on
|
|
52
|
+
* `currentCwd`); returns a short Chinese reason to refuse mutating `cwd` or archiving mid-flight.
|
|
53
|
+
*/
|
|
54
|
+
isDeskBusy?: (desk: string, currentCwd: string) => string | undefined;
|
|
55
|
+
/** Human-readable channel label for `/desk` messages. */
|
|
56
|
+
describeChannel?: (channelId: string) => string;
|
|
49
57
|
/**
|
|
50
58
|
* Drop the channel's cached runner and dispose it — its final reflect lands in the desk it was
|
|
51
59
|
* bound to (D5 step 5). Called only after the new binding is on disk.
|
|
@@ -53,12 +61,15 @@ export interface DeskRuntimeOptions {
|
|
|
53
61
|
releaseRunner: (channelId: string) => Promise<void>;
|
|
54
62
|
/** A binding changed (the channel index rewrites its desk column). */
|
|
55
63
|
onBindingChanged?: (channelId: string) => void;
|
|
64
|
+
/** A desk was activated or gained a bound channel (wakes the task lane to drain held deliveries). */
|
|
65
|
+
onActivated?: (desk: string) => void;
|
|
56
66
|
}
|
|
57
67
|
export declare class DeskRuntime {
|
|
58
68
|
private readonly options;
|
|
59
69
|
private bindings;
|
|
60
|
-
/** Every desk a binding
|
|
70
|
+
/** Every desk a binding or scan has touched, kept fresh when `desk.json`'s stamp changes. */
|
|
61
71
|
private readonly records;
|
|
72
|
+
private readonly recordStamps;
|
|
62
73
|
private readonly active;
|
|
63
74
|
private readonly watchers;
|
|
64
75
|
/** Activation and dormancy of one desk run in order, so interleaved calls settle on the last one. */
|
|
@@ -74,7 +85,16 @@ export declare class DeskRuntime {
|
|
|
74
85
|
*/
|
|
75
86
|
load(): Promise<void>;
|
|
76
87
|
private refreshRecord;
|
|
88
|
+
private syncRecordIfChanged;
|
|
77
89
|
resolve(channelId: string): ChannelResolution;
|
|
90
|
+
/** Effective working directory of `desk`, independent of whether any channel is currently bound to it. */
|
|
91
|
+
deskCwd(desk: string): string | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Build the `DeskConversation` a task runner in `desk` needs for `channelId`, even after
|
|
94
|
+
* `channelId` has rebound to another desk (Direction 1.2: background task execution is decoupled
|
|
95
|
+
* from current chat binding; `desk.json` retains the registered conversation record).
|
|
96
|
+
*/
|
|
97
|
+
taskConversation(desk: string, channelId: string): DeskConversation | undefined;
|
|
78
98
|
/** The producer- and admission-side check of INV-5: is this channel bound to this (available) desk? */
|
|
79
99
|
isBoundTo(channelId: string, desk: string): boolean;
|
|
80
100
|
/** The whole binding table, for `/desk list`. A copy: callers cannot change bindings through it. */
|
|
@@ -90,7 +110,7 @@ export declare class DeskRuntime {
|
|
|
90
110
|
/** The channel a conversation directory of this desk belongs to (for `session_search` labels). */
|
|
91
111
|
channelOfConversation(desk: string, conversation: string): string | undefined;
|
|
92
112
|
private boundChannelsOf;
|
|
93
|
-
/** Startup: activate every desk that has
|
|
113
|
+
/** Startup: activate every non-archived desk that has a binding or retained background work. */
|
|
94
114
|
activateBound(): Promise<void>;
|
|
95
115
|
/**
|
|
96
116
|
* D6 activation: repair the desk's bound conversations, then mark it active (the task driver and
|
|
@@ -99,10 +119,23 @@ export declare class DeskRuntime {
|
|
|
99
119
|
activate(desk: string): Promise<void>;
|
|
100
120
|
/** D6 dormancy: stop the watcher and leave the background scans. Running runs and jobs are untouched. */
|
|
101
121
|
deactivate(desk: string): Promise<void>;
|
|
122
|
+
/** Put an unbound desk to sleep once its last runnable task and task-spawning event are gone. */
|
|
123
|
+
reconcileActivity(desk: string): Promise<void>;
|
|
102
124
|
private startWatcher;
|
|
103
125
|
private stopWatcher;
|
|
104
126
|
/** `/desk new`: an empty desk, bound to nothing and therefore dormant (D5). */
|
|
105
|
-
create(name: string): Promise<CreateDeskOutcome>;
|
|
127
|
+
create(name: string, cwd?: string): Promise<CreateDeskOutcome>;
|
|
128
|
+
/** `/desk list` rows enriched with live background task and pending-delivery counts. */
|
|
129
|
+
listDeskItems(askingChannelId: string, labelOf: (channelId: string) => string): Promise<DeskListItem[]>;
|
|
130
|
+
/** `/desk cwd`: view or update the working directory of `channelId`'s bound desk. */
|
|
131
|
+
cwd(channelId: string, input: {
|
|
132
|
+
cwd?: string;
|
|
133
|
+
reset?: boolean;
|
|
134
|
+
}): Promise<DeskCwdOutcome>;
|
|
135
|
+
/** `/desk archive <name>`: retire an idle desk, unbinding stale terminal sessions and stopping events. */
|
|
136
|
+
archive(askingChannelId: string | undefined, name: string): Promise<ArchiveDeskOutcome>;
|
|
137
|
+
/** `/desk unarchive <name>`: clear `archivedAt` and re-activate if work is waiting. */
|
|
138
|
+
unarchive(name: string): Promise<UnarchiveDeskOutcome>;
|
|
106
139
|
/** `/desk bind` from `channelId`, in D5's order. Throws only when the bindings write itself fails. */
|
|
107
140
|
bind(channelId: string, name: string): Promise<BindOutcome>;
|
|
108
141
|
/**
|
|
@@ -113,8 +146,8 @@ export declare class DeskRuntime {
|
|
|
113
146
|
private bindNow;
|
|
114
147
|
/**
|
|
115
148
|
* The channel is gone for good (a Web API conversation was deleted): drop its binding, its
|
|
116
|
-
* runner, and — when it was the desk's last channel — the desk's
|
|
117
|
-
* directory stays in the desk as history. Whether there was a binding to drop.
|
|
149
|
+
* runner, and — when it was the desk's last channel and no background work remains — the desk's
|
|
150
|
+
* activity. Its conversation directory stays in the desk as history. Whether there was a binding to drop.
|
|
118
151
|
*/
|
|
119
152
|
unbind(channelId: string): Promise<boolean>;
|
|
120
153
|
/** Start the event watchers of every active desk; later activations start theirs directly. */
|