@oyasmi/pipiclaw 0.8.11 → 0.9.0-beta.10
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.md +146 -177
- package/dist/agent/channel-runner.d.ts +28 -0
- package/dist/agent/channel-runner.js +293 -145
- package/dist/agent/commands.d.ts +7 -1
- package/dist/agent/commands.js +26 -0
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/agent/job-manager.d.ts +34 -6
- package/dist/agent/job-manager.js +73 -7
- package/dist/agent/progress-formatter.js +3 -3
- package/dist/agent/prompt/sections.js +46 -7
- package/dist/agent/prompt/types.d.ts +9 -0
- package/dist/agent/run-queue.d.ts +10 -1
- package/dist/agent/run-queue.js +19 -2
- package/dist/agent/runner-factory.d.ts +16 -4
- package/dist/agent/runner-factory.js +9 -23
- package/dist/agent/session-events.js +7 -42
- package/dist/agent/session-resource-gate.d.ts +17 -0
- package/dist/agent/session-resource-gate.js +33 -2
- package/dist/agent/status-render.js +1 -3
- package/dist/agent/turn-recovery.d.ts +72 -0
- package/dist/agent/turn-recovery.js +193 -0
- package/dist/agent/types.d.ts +21 -1
- package/dist/agent/types.js +3 -16
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/main.js +2 -1
- package/dist/memory/extraction.js +0 -1
- package/dist/memory/maintenance-gates.d.ts +1 -1
- package/dist/memory/maintenance-jobs.js +2 -3
- package/dist/memory/metadata.d.ts +0 -15
- package/dist/memory/metadata.js +0 -7
- package/dist/memory/probation.d.ts +1 -5
- package/dist/memory/probation.js +2 -6
- package/dist/memory/review-log.js +0 -0
- package/dist/memory/scheduler.d.ts +1 -0
- package/dist/memory/scheduler.js +64 -6
- package/dist/models/auth-cli.d.ts +1 -1
- package/dist/models/auth-cli.js +3 -2
- package/dist/paths.d.ts +0 -6
- package/dist/paths.js +0 -6
- package/dist/playbooks/agent-delegation.md +48 -22
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.d.ts +2 -2
- package/dist/playbooks/catalog.js +20 -9
- package/dist/playbooks/event-scheduling.md +1 -1
- package/dist/playbooks/memory-and-learning.md +1 -1
- package/dist/playbooks/outbound-media.md +5 -5
- package/dist/playbooks/runtime-orientation.md +8 -3
- package/dist/playbooks/task-driving.md +1 -1
- package/dist/playbooks/task-planning.md +1 -1
- package/dist/runtime/active-session-store.d.ts +42 -0
- package/dist/runtime/active-session-store.js +100 -0
- package/dist/runtime/app-home.d.ts +32 -0
- package/dist/runtime/app-home.js +319 -0
- package/dist/runtime/bootstrap.d.ts +30 -36
- package/dist/runtime/bootstrap.js +359 -473
- package/dist/runtime/channel-event.d.ts +41 -0
- package/dist/runtime/channel-event.js +1 -0
- package/dist/runtime/delivery.d.ts +3 -2
- package/dist/runtime/delivery.js +11 -6
- package/dist/runtime/dingtalk.d.ts +16 -28
- package/dist/runtime/dingtalk.js +6 -10
- package/dist/runtime/durable-dispatch.d.ts +8 -2
- package/dist/runtime/durable-dispatch.js +52 -25
- package/dist/runtime/events.d.ts +3 -2
- package/dist/runtime/events.js +2 -3
- package/dist/runtime/project-commands.d.ts +16 -0
- package/dist/runtime/project-commands.js +112 -0
- package/dist/runtime/project-scope-store.d.ts +31 -0
- package/dist/runtime/project-scope-store.js +102 -0
- package/dist/runtime/store.d.ts +7 -0
- package/dist/runtime/subagent-commands.d.ts +17 -0
- package/dist/runtime/subagent-commands.js +360 -0
- package/dist/runtime/task-commands.js +7 -3
- package/dist/runtime/task-driver.d.ts +7 -7
- package/dist/runtime/task-driver.js +1 -4
- package/dist/runtime/task-migration.js +1 -1
- package/dist/runtime/task-wake.d.ts +54 -0
- package/dist/runtime/task-wake.js +99 -0
- package/dist/security/config.js +10 -0
- package/dist/security/logger.js +10 -1
- package/dist/security/path-guard.js +34 -9
- package/dist/security/project-scope.d.ts +45 -0
- package/dist/security/project-scope.js +107 -0
- package/dist/security/types.d.ts +37 -3
- package/dist/settings.d.ts +0 -106
- package/dist/settings.js +0 -224
- package/dist/shared/host-process.d.ts +37 -0
- package/dist/shared/host-process.js +112 -0
- package/dist/shared/jsonl-appender.d.ts +2 -0
- package/dist/shared/jsonl-appender.js +25 -13
- package/dist/shared/shell-words.d.ts +9 -0
- package/dist/shared/shell-words.js +52 -0
- package/dist/shared/types.d.ts +1 -0
- package/dist/shared/types.js +10 -1
- package/dist/shared/wake-claim.d.ts +23 -0
- package/dist/shared/wake-claim.js +26 -0
- package/dist/shared/with-timeout.d.ts +14 -0
- package/dist/shared/with-timeout.js +38 -0
- package/dist/subagents/detached-discovery.d.ts +13 -0
- package/dist/subagents/detached-discovery.js +17 -0
- package/dist/subagents/discovery.d.ts +74 -1
- package/dist/subagents/discovery.js +429 -82
- package/dist/subagents/external/claude-code.d.ts +2 -0
- package/dist/subagents/external/claude-code.js +158 -0
- package/dist/subagents/external/codex-cli.d.ts +2 -0
- package/dist/subagents/external/codex-cli.js +133 -0
- package/dist/subagents/external/exec.d.ts +2 -0
- package/dist/subagents/external/exec.js +44 -0
- package/dist/subagents/external/harness.d.ts +121 -0
- package/dist/subagents/external/harness.js +109 -0
- package/dist/subagents/external/registry.d.ts +2 -0
- package/dist/subagents/external/registry.js +11 -0
- package/dist/subagents/external/run.d.ts +74 -0
- package/dist/subagents/external/run.js +286 -0
- package/dist/subagents/external/settlement.d.ts +50 -0
- package/dist/subagents/external/settlement.js +123 -0
- package/dist/subagents/format.d.ts +16 -0
- package/dist/subagents/format.js +31 -0
- package/dist/subagents/runs.d.ts +342 -0
- package/dist/subagents/runs.js +909 -0
- package/dist/subagents/tool.d.ts +68 -6
- package/dist/subagents/tool.js +547 -206
- package/dist/subagents/verification-outcome.d.ts +26 -0
- package/dist/subagents/verification-outcome.js +16 -0
- package/dist/subagents/workspace-lease.d.ts +45 -0
- package/dist/subagents/workspace-lease.js +61 -0
- package/dist/tasks/artifact-subject.js +50 -2
- package/dist/tasks/control.d.ts +12 -0
- package/dist/tasks/control.js +20 -0
- package/dist/tasks/ledger.js +1 -1
- package/dist/tasks/store.d.ts +21 -0
- package/dist/tasks/store.js +80 -0
- package/dist/{shared → tasks}/task-schedule.js +1 -1
- package/dist/tasks/verification.d.ts +8 -0
- package/dist/tasks/verification.js +10 -2
- package/dist/tools/bash.js +4 -4
- package/dist/tools/edit.js +3 -3
- package/dist/tools/event-manage.js +1 -4
- package/dist/tools/grep.js +5 -6
- package/dist/tools/index.d.ts +4 -1
- package/dist/tools/index.js +25 -3
- package/dist/tools/job.js +5 -5
- package/dist/tools/memory-manage.js +3 -7
- package/dist/tools/read.js +3 -3
- package/dist/tools/registry.js +2 -1
- package/dist/tools/send-media.js +2 -2
- package/dist/tools/session-search.js +0 -1
- package/dist/tools/skill-manage.js +3 -3
- package/dist/tools/subagent-manage.d.ts +37 -0
- package/dist/tools/subagent-manage.js +245 -0
- package/dist/tools/task-manage/shared.js +2 -2
- package/dist/tools/task-manage.js +1 -4
- package/dist/tools/tool-details.d.ts +1 -1
- package/dist/tools/web-fetch.js +0 -1
- package/dist/tools/write-content.js +3 -3
- package/dist/tui/app.d.ts +1 -1
- package/dist/tui/app.js +55 -6
- package/dist/tui/cli.d.ts +1 -1
- package/dist/tui/cli.js +1 -1
- package/dist/tui/commands.d.ts +2 -0
- package/dist/tui/commands.js +4 -0
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/dist/tui/turn-controller.d.ts +2 -0
- package/dist/tui/turn-controller.js +2 -0
- package/dist/usage/ledger.d.ts +13 -0
- package/dist/usage/ledger.js +15 -2
- package/dist/usage/render.js +22 -0
- package/examples/sub-agents/README.md +75 -14
- package/examples/sub-agents/builder-hard.md +46 -0
- package/examples/sub-agents/builder.md +42 -0
- package/examples/sub-agents/documenter.md +50 -0
- package/examples/sub-agents/explorer.md +16 -13
- package/examples/sub-agents/git-committer.md +33 -40
- package/examples/sub-agents/log-sifter.md +46 -0
- package/examples/sub-agents/planner.md +42 -0
- package/examples/sub-agents/reviewer.md +31 -41
- package/examples/sub-agents/scout.md +30 -0
- package/examples/sub-agents/verifier.md +27 -37
- package/examples/sub-agents/worker.md +35 -0
- package/package.json +1 -1
- package/examples/sub-agents/researcher.md +0 -41
- /package/dist/{shared → tasks}/task-events.d.ts +0 -0
- /package/dist/{shared → tasks}/task-events.js +0 -0
- /package/dist/{shared → tasks}/task-schedule.d.ts +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A message or wake, from any producer: a real inbound DingTalk message, a scheduled event, a
|
|
3
|
+
* task-driver wake, or a job/subagent completion. `conversationId` is the one field genuinely
|
|
4
|
+
* DingTalk-specific (needed to reply into the right conversation); every synthetic producer
|
|
5
|
+
* (job-manager, task-driver, events, subagents/runs) leaves it unset rather than faking a value,
|
|
6
|
+
* since it has no DingTalk conversation to route into. `conversationType` is not DingTalk-specific
|
|
7
|
+
* in practice — every producer, real or synthetic, can derive "1"/"2" from the channelId prefix —
|
|
8
|
+
* so it stays required.
|
|
9
|
+
*/
|
|
10
|
+
export interface ChannelEvent {
|
|
11
|
+
type: "dm" | "group";
|
|
12
|
+
channelId: string;
|
|
13
|
+
ts: string;
|
|
14
|
+
user: string;
|
|
15
|
+
userName: string;
|
|
16
|
+
text: string;
|
|
17
|
+
/** DingTalk conversation id; absent on synthetic events, which have no DingTalk conversation. */
|
|
18
|
+
conversationId?: string;
|
|
19
|
+
conversationType: string;
|
|
20
|
+
/**
|
|
21
|
+
* Human-readable channel name: the group title, or the peer's nickname for a DM. Absent on
|
|
22
|
+
* synthetic events (scheduled events, task-driver wakes), which carry no conversation payload.
|
|
23
|
+
*/
|
|
24
|
+
channelName?: string;
|
|
25
|
+
/** Runtime-owned durable-dispatch record, absent for normal inbound messages. */
|
|
26
|
+
dispatchId?: string;
|
|
27
|
+
/** Structured wake provenance created only by in-process producers. DingTalk inbound parsing
|
|
28
|
+
* never copies arbitrary payload fields into this event, so user text cannot manufacture it. */
|
|
29
|
+
internalWake?: {
|
|
30
|
+
kind: "job" | "subagent";
|
|
31
|
+
resourceId: string;
|
|
32
|
+
taskId: string;
|
|
33
|
+
dispatchId: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The `attemptGeneration` this event's claim recorded, for `[TASK_DRIVER:id]` events only.
|
|
37
|
+
* Carried through durable dispatch so `finishTaskAttempt` can tell a stale, superseded claim's
|
|
38
|
+
* turn from the current one, even when redelivery or claim races reorder completions.
|
|
39
|
+
*/
|
|
40
|
+
taskAttemptGeneration?: number;
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ChannelContext, ProgressStyle } from "./channel-context.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ChannelEvent } from "./channel-event.js";
|
|
3
|
+
import type { DingTalkBot } from "./dingtalk.js";
|
|
3
4
|
import type { ChannelStore } from "./store.js";
|
|
4
5
|
/**
|
|
5
6
|
* Build the delivery contract for one turn.
|
|
@@ -11,4 +12,4 @@ import type { ChannelStore } from "./store.js";
|
|
|
11
12
|
* final answer is unaffected; it is delivered by `respondPlain`/`replaceMessage` either way, so a
|
|
12
13
|
* background turn that has something to say still says it.
|
|
13
14
|
*/
|
|
14
|
-
export declare function createDingTalkContext(event:
|
|
15
|
+
export declare function createDingTalkContext(event: ChannelEvent, bot: DingTalkBot, store: ChannelStore, progressStyleOverride?: ProgressStyle): ChannelContext;
|
package/dist/runtime/delivery.js
CHANGED
|
@@ -3,6 +3,11 @@ import { errorMessage } from "../shared/text-utils.js";
|
|
|
3
3
|
const MIN_UPDATE_INTERVAL_MS = 800;
|
|
4
4
|
const ROLLING_WINDOW_SIZE = 3;
|
|
5
5
|
const NO_CONTENT = "";
|
|
6
|
+
// DingTalk's card renderer swallows a bare "\n" between plain lines (and a blank-line
|
|
7
|
+
// paragraph break leaves too much vertical gap), but it does reliably break a markdown
|
|
8
|
+
// list onto separate lines. Render each progress entry as a list item instead.
|
|
9
|
+
const PROGRESS_LINE_BREAK = "\n";
|
|
10
|
+
const PROGRESS_ENTRY_PREFIX = "- ";
|
|
6
11
|
// Last-resort ceiling on how long flush() will block a caller. Outbound HTTP now
|
|
7
12
|
// has its own timeout, so the sync loop is already bounded; this only guards against
|
|
8
13
|
// an unforeseen stall so run()'s finally can never hang the channel forever.
|
|
@@ -123,13 +128,13 @@ class ChannelDeliveryController {
|
|
|
123
128
|
if (this.progressStartedAt === 0) {
|
|
124
129
|
this.progressStartedAt = Date.now();
|
|
125
130
|
}
|
|
126
|
-
if (text.startsWith("
|
|
131
|
+
if (text.startsWith("➜ ")) {
|
|
127
132
|
this.toolCallCount++;
|
|
128
133
|
}
|
|
129
134
|
if (this.progressSegments.length > 0) {
|
|
130
|
-
this.progressSegments.push(
|
|
135
|
+
this.progressSegments.push(PROGRESS_LINE_BREAK);
|
|
131
136
|
}
|
|
132
|
-
this.progressSegments.push(text);
|
|
137
|
+
this.progressSegments.push(`${PROGRESS_ENTRY_PREFIX}${text}`);
|
|
133
138
|
this.progressTextDirty = true;
|
|
134
139
|
if (this.progressStyle === "rolling") {
|
|
135
140
|
this.trimToRecentEntries(ROLLING_WINDOW_SIZE);
|
|
@@ -390,7 +395,7 @@ class ChannelDeliveryController {
|
|
|
390
395
|
trimToRecentEntries(maxEntries) {
|
|
391
396
|
let entryCount = 0;
|
|
392
397
|
for (const segment of this.progressSegments) {
|
|
393
|
-
if (segment !==
|
|
398
|
+
if (segment !== PROGRESS_LINE_BREAK) {
|
|
394
399
|
entryCount++;
|
|
395
400
|
}
|
|
396
401
|
}
|
|
@@ -401,11 +406,11 @@ class ChannelDeliveryController {
|
|
|
401
406
|
let removedEntries = 0;
|
|
402
407
|
while (removedEntries < entriesToRemove && this.progressSegments.length > 0) {
|
|
403
408
|
const segment = this.progressSegments.shift();
|
|
404
|
-
if (segment !==
|
|
409
|
+
if (segment !== PROGRESS_LINE_BREAK) {
|
|
405
410
|
removedEntries++;
|
|
406
411
|
}
|
|
407
412
|
}
|
|
408
|
-
while (this.progressSegments[0] ===
|
|
413
|
+
while (this.progressSegments[0] === PROGRESS_LINE_BREAK) {
|
|
409
414
|
this.progressSegments.shift();
|
|
410
415
|
}
|
|
411
416
|
this.progressTextDirty = true;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { type RuntimeCommandName } from "../agent/commands.js";
|
|
1
2
|
import type { FinalDelivery, MediaSender, MediaSendResult, OutboundMedia, ProgressStyle } from "./channel-context.js";
|
|
3
|
+
import type { ChannelEvent } from "./channel-event.js";
|
|
2
4
|
import type { ChannelObservation } from "./channel-index.js";
|
|
3
5
|
export type BusyMessageMode = "steer" | "followUp";
|
|
4
6
|
export type BusyMessageDefaultConfig = BusyMessageMode | "followup";
|
|
@@ -21,29 +23,14 @@ export interface DingTalkConfig {
|
|
|
21
23
|
responseMode?: ResponseMode;
|
|
22
24
|
cardAutoLayout?: boolean;
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
conversationType: string;
|
|
33
|
-
/**
|
|
34
|
-
* Human-readable channel name: the group title, or the peer's nickname for a DM. Absent on
|
|
35
|
-
* synthetic events (scheduled events, task-driver wakes), which carry no conversation payload.
|
|
36
|
-
*/
|
|
37
|
-
channelName?: string;
|
|
38
|
-
/** Runtime-owned durable-dispatch record, absent for normal inbound messages. */
|
|
39
|
-
dispatchId?: string;
|
|
40
|
-
/**
|
|
41
|
-
* The `attemptGeneration` this event's claim recorded, for `[TASK_DRIVER:id]` events only.
|
|
42
|
-
* Carried through durable dispatch so `finishTaskAttempt` can tell a stale, superseded claim's
|
|
43
|
-
* turn from the current one, even when redelivery or claim races reorder completions.
|
|
44
|
-
*/
|
|
45
|
-
taskAttemptGeneration?: number;
|
|
46
|
-
}
|
|
26
|
+
/**
|
|
27
|
+
* `DingTalkEvent` is kept as the public name (spec 035 D4: `src/index.ts`'s barrel is a
|
|
28
|
+
* compatibility promise, so exported names there stay stable). Internally the type now lives in
|
|
29
|
+
* `channel-event.ts` as `ChannelEvent`: most producers of this shape are not DingTalk at all
|
|
30
|
+
* (job-manager, task-driver, events, subagents/runs all synthesize wakes), so `ChannelEvent` is
|
|
31
|
+
* what the rest of the runtime imports.
|
|
32
|
+
*/
|
|
33
|
+
export type DingTalkEvent = ChannelEvent;
|
|
47
34
|
export type BusyMessageResult = {
|
|
48
35
|
kind: "handled";
|
|
49
36
|
} | {
|
|
@@ -73,11 +60,12 @@ export interface DingTalkHandler {
|
|
|
73
60
|
reserveEvent?(event: DingTalkEvent): void;
|
|
74
61
|
handleEvent(event: DingTalkEvent, bot: DingTalkBot, isEvent?: boolean): Promise<void>;
|
|
75
62
|
handleStop(channelId: string, bot: DingTalkBot): Promise<StopOutcome>;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Render one of the stateless report commands (events/tasks/status/usage/context/subagents) to
|
|
65
|
+
* text. Single dispatch point shared by the busy-turn switch below and bootstrap's idle-turn
|
|
66
|
+
* switch — both used to hand-copy the same six-case table.
|
|
67
|
+
*/
|
|
68
|
+
runRuntimeCommand(event: DingTalkEvent, name: RuntimeCommandName, args: string): Promise<string>;
|
|
81
69
|
handleBusyMessage(event: DingTalkEvent, bot: DingTalkBot, mode: BusyMessageMode, queueText: string): Promise<BusyMessageResult>;
|
|
82
70
|
}
|
|
83
71
|
export declare class DingTalkBot implements MediaSender {
|
package/dist/runtime/dingtalk.js
CHANGED
|
@@ -11,7 +11,7 @@ import axios from "axios";
|
|
|
11
11
|
import { DWClient, TOPIC_ROBOT } from "dingtalk-stream";
|
|
12
12
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
13
13
|
import { dirname, join } from "path";
|
|
14
|
-
import { formatBusyCommandList, parseBuiltInCommand, renderBuiltInHelp } from "../agent/commands.js";
|
|
14
|
+
import { formatBusyCommandList, parseBuiltInCommand, renderBuiltInHelp, } from "../agent/commands.js";
|
|
15
15
|
import * as log from "../log.js";
|
|
16
16
|
import { errorMessage } from "../shared/text-utils.js";
|
|
17
17
|
import { isRecord } from "../shared/type-guards.js";
|
|
@@ -1094,20 +1094,16 @@ export class DingTalkBot {
|
|
|
1094
1094
|
return;
|
|
1095
1095
|
}
|
|
1096
1096
|
case "events":
|
|
1097
|
-
await this.handler.handleEventsCommand(event, this, builtInCommand.args);
|
|
1098
|
-
return;
|
|
1099
1097
|
case "tasks":
|
|
1100
|
-
await this.handler.handleTasksCommand(event, this, builtInCommand.args);
|
|
1101
|
-
return;
|
|
1102
1098
|
case "status":
|
|
1103
|
-
await this.handler.handleStatusCommand(event, this);
|
|
1104
|
-
return;
|
|
1105
1099
|
case "usage":
|
|
1106
|
-
await this.handler.handleUsageCommand(event, this, builtInCommand.args);
|
|
1107
|
-
return;
|
|
1108
1100
|
case "context":
|
|
1109
|
-
|
|
1101
|
+
case "subagents":
|
|
1102
|
+
case "project": {
|
|
1103
|
+
const response = await this.handler.runRuntimeCommand(event, builtInCommand.name, builtInCommand.args);
|
|
1104
|
+
await this.sendPlain(channelId, response);
|
|
1110
1105
|
return;
|
|
1106
|
+
}
|
|
1111
1107
|
}
|
|
1112
1108
|
}
|
|
1113
1109
|
// Session commands (/model, /new, …) and unknown slash commands cannot
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChannelEvent } from "./channel-event.js";
|
|
2
|
+
import type { DingTalkBot } from "./dingtalk.js";
|
|
2
3
|
export interface DurableDispatchOptions {
|
|
3
4
|
stateDir: string;
|
|
4
5
|
bot: Pick<DingTalkBot, "enqueueEvent">;
|
|
@@ -29,12 +30,17 @@ export declare class DurableDispatchService {
|
|
|
29
30
|
constructor(options: DurableDispatchOptions);
|
|
30
31
|
start(): void;
|
|
31
32
|
stop(): void;
|
|
32
|
-
dispatch(event:
|
|
33
|
+
dispatch(event: ChannelEvent): Promise<boolean>;
|
|
33
34
|
/** Reset any in-flight records for a channel so a stop/abort can redeliver on the next tick, not after the lease expires. */
|
|
34
35
|
cancelChannel(channelId: string): Promise<number>;
|
|
35
36
|
markStarted(id: string | undefined): Promise<void>;
|
|
36
37
|
markCompleted(id: string | undefined): Promise<void>;
|
|
38
|
+
/** Release a failed handler's in-process claim without deleting its durable record. Structured
|
|
39
|
+
* wake activation uses this for transient task/job/run persistence failures so the next drain
|
|
40
|
+
* can retry the same dispatch id instead of losing the only completion signal. */
|
|
41
|
+
markRetryable(id: string | undefined): Promise<void>;
|
|
37
42
|
drainOnce(now?: number): Promise<void>;
|
|
43
|
+
private drainRecord;
|
|
38
44
|
private read;
|
|
39
45
|
private write;
|
|
40
46
|
}
|
|
@@ -105,9 +105,11 @@ export class DurableDispatchService {
|
|
|
105
105
|
};
|
|
106
106
|
await this.write(record);
|
|
107
107
|
});
|
|
108
|
-
|
|
108
|
+
// Only this record needs draining here — a full directory scan would pay for every other
|
|
109
|
+
// channel's outstanding record just to learn the outcome of the one just written.
|
|
110
|
+
await this.drainRecord(id, Date.now());
|
|
109
111
|
// The record is gone (delivered+completed already) or no longer "pending"
|
|
110
|
-
// (
|
|
112
|
+
// (drainRecord only reverts to "pending" when bot.enqueueEvent rejected it).
|
|
111
113
|
const after = await this.read(id);
|
|
112
114
|
return after?.status !== "pending";
|
|
113
115
|
}
|
|
@@ -160,6 +162,22 @@ export class DurableDispatchService {
|
|
|
160
162
|
await unlink(recordPath(this.options.stateDir, id)).catch(() => undefined);
|
|
161
163
|
});
|
|
162
164
|
}
|
|
165
|
+
/** Release a failed handler's in-process claim without deleting its durable record. Structured
|
|
166
|
+
* wake activation uses this for transient task/job/run persistence failures so the next drain
|
|
167
|
+
* can retry the same dispatch id instead of losing the only completion signal. */
|
|
168
|
+
async markRetryable(id) {
|
|
169
|
+
if (!id)
|
|
170
|
+
return;
|
|
171
|
+
this.running.delete(id);
|
|
172
|
+
await this.queue.run(id, async () => {
|
|
173
|
+
const record = await this.read(id);
|
|
174
|
+
if (!record)
|
|
175
|
+
return;
|
|
176
|
+
record.status = "pending";
|
|
177
|
+
record.leaseExpiresAt = undefined;
|
|
178
|
+
await this.write(record);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
163
181
|
async drainOnce(now = Date.now()) {
|
|
164
182
|
let filenames;
|
|
165
183
|
try {
|
|
@@ -170,32 +188,41 @@ export class DurableDispatchService {
|
|
|
170
188
|
}
|
|
171
189
|
for (const filename of filenames) {
|
|
172
190
|
const id = filename.slice(0, -".json".length);
|
|
173
|
-
await this.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
191
|
+
await this.drainRecord(id, now);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
async drainRecord(id, now) {
|
|
195
|
+
await this.queue.run(id, async () => {
|
|
196
|
+
const record = await this.read(id);
|
|
197
|
+
if (!record)
|
|
198
|
+
return;
|
|
199
|
+
// The turn is still running in this process: renew its lease rather than treating a
|
|
200
|
+
// long turn as a lost one and redelivering the wake underneath it (D2).
|
|
201
|
+
if (record.status === "running" && this.running.has(id)) {
|
|
202
|
+
const currentLeaseMs = record.leaseExpiresAt ? new Date(record.leaseExpiresAt).getTime() : 0;
|
|
203
|
+
// Only persist the renewal once the lease is more than halfway to expiry, instead of
|
|
204
|
+
// on every drain tick — a live holder gets rediscovered by the next tick regardless,
|
|
205
|
+
// so there is no correctness reason to fsync a rename this often.
|
|
206
|
+
if (currentLeaseMs - now < this.leaseMs / 2) {
|
|
180
207
|
record.leaseExpiresAt = new Date(now + this.leaseMs).toISOString();
|
|
181
208
|
await this.write(record);
|
|
182
|
-
return;
|
|
183
209
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const leaseMs = record.leaseExpiresAt ? new Date(record.leaseExpiresAt).getTime() : undefined;
|
|
213
|
+
if ((record.status === "queued" || record.status === "running") && leaseMs && leaseMs > now)
|
|
214
|
+
return;
|
|
215
|
+
record.status = "queued";
|
|
216
|
+
record.deliveries++;
|
|
217
|
+
record.leaseExpiresAt = new Date(now + this.leaseMs).toISOString();
|
|
218
|
+
await this.write(record);
|
|
219
|
+
const accepted = this.options.bot.enqueueEvent(withRedeliveryNotice({ ...record.event, dispatchId: record.id }, record.deliveries));
|
|
220
|
+
if (accepted)
|
|
221
|
+
return;
|
|
222
|
+
record.status = "pending";
|
|
223
|
+
record.leaseExpiresAt = undefined;
|
|
224
|
+
await this.write(record);
|
|
225
|
+
});
|
|
199
226
|
}
|
|
200
227
|
async read(id) {
|
|
201
228
|
try {
|
package/dist/runtime/events.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Executor } from "../executor.js";
|
|
2
2
|
import type { SecurityConfig } from "../security/types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ChannelEvent } from "./channel-event.js";
|
|
4
|
+
import type { DingTalkBot } from "./dingtalk.js";
|
|
4
5
|
export interface EventAction {
|
|
5
6
|
type: "bash";
|
|
6
7
|
command: string;
|
|
@@ -56,7 +57,7 @@ export interface EventHistoryRecord {
|
|
|
56
57
|
export interface EventsWatcherOptions {
|
|
57
58
|
historyPath?: string;
|
|
58
59
|
/** Persist synthetic work before it enters the in-memory channel queue. */
|
|
59
|
-
dispatch?: (event:
|
|
60
|
+
dispatch?: (event: ChannelEvent) => boolean | Promise<boolean>;
|
|
60
61
|
}
|
|
61
62
|
export declare function parseScheduledEventContent(content: string, filename: string): ScheduledEvent;
|
|
62
63
|
export declare class EventsWatcher {
|
package/dist/runtime/events.js
CHANGED
|
@@ -6,9 +6,9 @@ import * as log from "../log.js";
|
|
|
6
6
|
import { guardCommand } from "../security/command-guard.js";
|
|
7
7
|
import { createJsonlAppender } from "../shared/jsonl-appender.js";
|
|
8
8
|
import { formatLocalTime, parseLocalTime } from "../shared/local-time.js";
|
|
9
|
-
import { taskEventPrefix } from "../shared/task-events.js";
|
|
10
9
|
import { errorMessage, eventNameFromFilename } from "../shared/text-utils.js";
|
|
11
10
|
import { parseTaskFrontmatter } from "../tasks/ledger.js";
|
|
11
|
+
import { taskEventPrefix } from "../tasks/task-events.js";
|
|
12
12
|
import { MAX_EVENT_FILES, MAX_ONE_SHOT_DELAY_MS, validateScheduledEvent } from "./event-validation.js";
|
|
13
13
|
// ============================================================================
|
|
14
14
|
// EventsWatcher
|
|
@@ -567,7 +567,7 @@ export class EventsWatcher {
|
|
|
567
567
|
? " This is a periodic runtime wake. If it produces no user-visible change or result, reply with exactly [SILENT]."
|
|
568
568
|
: "";
|
|
569
569
|
const message = `[EVENT:${filename}:${event.type}:${scheduleInfo}] ${event.text}${periodicContract}`;
|
|
570
|
-
// Create synthetic
|
|
570
|
+
// Create synthetic ChannelEvent
|
|
571
571
|
const syntheticEvent = {
|
|
572
572
|
type: "dm",
|
|
573
573
|
channelId: event.channelId,
|
|
@@ -575,7 +575,6 @@ export class EventsWatcher {
|
|
|
575
575
|
userName: "EVENT",
|
|
576
576
|
text: message,
|
|
577
577
|
ts: Date.now().toString(),
|
|
578
|
-
conversationId: "",
|
|
579
578
|
conversationType: "1",
|
|
580
579
|
dispatchId: eventDispatchId(filename, event, occurrence),
|
|
581
580
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface HandleProjectCommandOptions {
|
|
2
|
+
args: string;
|
|
3
|
+
channelId: string;
|
|
4
|
+
channelDir: string;
|
|
5
|
+
appHomeDir: string;
|
|
6
|
+
actor: "dingtalk-command" | "tui-command";
|
|
7
|
+
/** True while a turn is in flight for this channel; blocks `set`/`reset` (D1.3/D4.2). */
|
|
8
|
+
isBusy: () => boolean;
|
|
9
|
+
/** Non-empty user-facing lines naming a running job/subagent that must finish or be cancelled
|
|
10
|
+
* first (D4.3) — sleeping tasks are deliberately not included here. */
|
|
11
|
+
listActiveBlockers: () => Promise<string[]> | string[];
|
|
12
|
+
/** Runs after a successful commit so the caller can dispose its cached runner for this channel
|
|
13
|
+
* and let the next access rebuild it under the new scope (D4.2). Not called on any failure path. */
|
|
14
|
+
onScopeChanged?: () => Promise<void> | void;
|
|
15
|
+
}
|
|
16
|
+
export declare function handleProjectCommand(options: HandleProjectCommandOptions): Promise<string>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { loadSecurityConfigWithDiagnostics } from "../security/config.js";
|
|
2
|
+
import { currentProjectSandboxStatus, isWithinAllowedRoots, resolveExistingDirectory, resolveProjectAccessPolicy, } from "../security/project-scope.js";
|
|
3
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
4
|
+
import { commitProjectSelection, readProjectSelection } from "./project-scope-store.js";
|
|
5
|
+
function usage() {
|
|
6
|
+
return `# 项目作用域
|
|
7
|
+
|
|
8
|
+
用法:
|
|
9
|
+
|
|
10
|
+
- \`/project\` — 查看当前频道的项目目录与访问边界
|
|
11
|
+
- \`/project set <absolute-path>\` — 切换项目目录(需频道空闲,且目录在允许的可选根内)
|
|
12
|
+
- \`/project reset\` — 切回 app 默认项目目录`;
|
|
13
|
+
}
|
|
14
|
+
function parseProjectCommand(args) {
|
|
15
|
+
const trimmed = args.trim();
|
|
16
|
+
if (!trimmed)
|
|
17
|
+
return { action: "show" };
|
|
18
|
+
const parts = trimmed.split(/\s+/);
|
|
19
|
+
if (parts[0] === "set") {
|
|
20
|
+
if (!parts[1] || parts.length > 2)
|
|
21
|
+
throw new Error("用法:/project set <absolute-path>");
|
|
22
|
+
return { action: "set", path: parts[1] };
|
|
23
|
+
}
|
|
24
|
+
if (parts[0] === "reset") {
|
|
25
|
+
if (parts.length > 1)
|
|
26
|
+
throw new Error("用法:/project reset");
|
|
27
|
+
return { action: "reset" };
|
|
28
|
+
}
|
|
29
|
+
throw new Error(`未知的 /project 子命令:${parts[0]}`);
|
|
30
|
+
}
|
|
31
|
+
function formatShow(options) {
|
|
32
|
+
const securityLoad = loadSecurityConfigWithDiagnostics(options.appHomeDir);
|
|
33
|
+
const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
|
|
34
|
+
const sandbox = currentProjectSandboxStatus();
|
|
35
|
+
const selection = readProjectSelection(options.channelDir);
|
|
36
|
+
const lines = ["# 项目作用域", ""];
|
|
37
|
+
if (!selection) {
|
|
38
|
+
lines.push(`项目目录:\`${resolution.policy.defaultRoot}\`(尚未选择过,将在下次准入时采用 app 默认值)`);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
lines.push(`项目目录:\`${selection.projectRoot}\`(${selection.updatedBy},更新于 ${selection.updatedAt})`);
|
|
42
|
+
}
|
|
43
|
+
lines.push(`边界:${resolution.configured ? "project(文件工具被约束在此目录内)" : "unbounded(沿用旧的全局文件权限)"}`);
|
|
44
|
+
lines.push(`Enforcement:${sandbox.level}(${sandbox.summary})`);
|
|
45
|
+
if (!resolution.configured) {
|
|
46
|
+
lines.push("", `未配置 projectAccess:\`/project set\` 不可用。在 \`security.json\` 写入 projectAccess 段后即可使用。`);
|
|
47
|
+
}
|
|
48
|
+
else if (!resolution.mutable) {
|
|
49
|
+
lines.push("", "projectAccess.defaultRoot 配置有误,项目切换已被禁用,见启动诊断。");
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
lines.push("", `可选根:${resolution.policy.allowedRoots.map((root) => `\`${root}\``).join("、")}`);
|
|
53
|
+
}
|
|
54
|
+
for (const diagnostic of resolution.diagnostics) {
|
|
55
|
+
lines.push(`⚠ ${diagnostic.message}`);
|
|
56
|
+
}
|
|
57
|
+
return lines.join("\n");
|
|
58
|
+
}
|
|
59
|
+
async function applyScopeChange(options, requestedPath, label) {
|
|
60
|
+
const securityLoad = loadSecurityConfigWithDiagnostics(options.appHomeDir);
|
|
61
|
+
const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
|
|
62
|
+
if (!resolution.configured) {
|
|
63
|
+
return `无法切换项目:未配置 projectAccess。在 \`security.json\` 写入 projectAccess 段(defaultRoot/allowedRoots)后重试。`;
|
|
64
|
+
}
|
|
65
|
+
if (!resolution.mutable) {
|
|
66
|
+
return `无法切换项目:projectAccess.defaultRoot 配置有误(见启动诊断),项目切换已被禁用直到修复。`;
|
|
67
|
+
}
|
|
68
|
+
const real = resolveExistingDirectory(requestedPath);
|
|
69
|
+
if (!real) {
|
|
70
|
+
return `无法切换项目:\`${requestedPath}\` 不是一个存在的绝对目录。`;
|
|
71
|
+
}
|
|
72
|
+
if (!isWithinAllowedRoots(real, resolution.policy)) {
|
|
73
|
+
return `无法切换项目:\`${real}\` 不在允许的可选根内。可选根:${resolution.policy.allowedRoots
|
|
74
|
+
.map((root) => `\`${root}\``)
|
|
75
|
+
.join("、")}。`;
|
|
76
|
+
}
|
|
77
|
+
if (options.isBusy()) {
|
|
78
|
+
return "无法切换项目:当前频道有回合正在进行,请等待结束后重试。";
|
|
79
|
+
}
|
|
80
|
+
const blockers = await options.listActiveBlockers();
|
|
81
|
+
if (blockers.length > 0) {
|
|
82
|
+
return `无法切换项目:\n${blockers.map((line) => `- ${line}`).join("\n")}\n\n结束或取消上述项后重试。`;
|
|
83
|
+
}
|
|
84
|
+
await commitProjectSelection(options.channelDir, real, options.actor);
|
|
85
|
+
await options.onScopeChanged?.();
|
|
86
|
+
return `${label}:\`${real}\`。下一次消息将在新的项目目录下运行。`;
|
|
87
|
+
}
|
|
88
|
+
export async function handleProjectCommand(options) {
|
|
89
|
+
let command;
|
|
90
|
+
try {
|
|
91
|
+
command = parseProjectCommand(options.args);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
return `${errorMessage(error)}\n\n${usage()}`;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
switch (command.action) {
|
|
98
|
+
case "show":
|
|
99
|
+
return formatShow(options);
|
|
100
|
+
case "set":
|
|
101
|
+
return await applyScopeChange(options, command.path, "已切换项目");
|
|
102
|
+
case "reset": {
|
|
103
|
+
const securityLoad = loadSecurityConfigWithDiagnostics(options.appHomeDir);
|
|
104
|
+
const resolution = resolveProjectAccessPolicy(securityLoad.config, process.cwd());
|
|
105
|
+
return await applyScopeChange(options, resolution.policy.defaultRoot, "已重置项目");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
return `执行 /project ${command.action} 失败:${errorMessage(error)}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ProjectAccessPolicy, type ProjectScope } from "../security/project-scope.js";
|
|
2
|
+
/** A channel's persisted project selection (D3.3). Never holds messages, only the choice itself. */
|
|
3
|
+
export interface PersistedProjectSelectionV1 {
|
|
4
|
+
version: 1;
|
|
5
|
+
/** Realpath. */
|
|
6
|
+
projectRoot: string;
|
|
7
|
+
updatedAt: string;
|
|
8
|
+
updatedBy: "migration" | "dingtalk-command" | "tui-command";
|
|
9
|
+
}
|
|
10
|
+
export declare function getProjectSelectionPath(channelDir: string): string;
|
|
11
|
+
export declare function readProjectSelection(channelDir: string): PersistedProjectSelectionV1 | undefined;
|
|
12
|
+
export declare function commitProjectSelection(channelDir: string, projectRoot: string, updatedBy: PersistedProjectSelectionV1["updatedBy"]): Promise<PersistedProjectSelectionV1>;
|
|
13
|
+
export type ProjectScopeOutcome = {
|
|
14
|
+
kind: "ready";
|
|
15
|
+
scope: ProjectScope;
|
|
16
|
+
selection: PersistedProjectSelectionV1;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "blocked";
|
|
19
|
+
reason: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Resolves the effective `ProjectScope` for a channel: its persisted selection if present and
|
|
23
|
+
* still valid, else the app default — materialized as the channel's first selection so a later
|
|
24
|
+
* daemon restart from a different startup cwd cannot silently move the channel (D3.3). Never
|
|
25
|
+
* falls back to a different root once one has been persisted (P7): a stale or now-disallowed
|
|
26
|
+
* selection blocks instead of guessing.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveProjectScope(channelDir: string, resolution: {
|
|
29
|
+
policy: ProjectAccessPolicy;
|
|
30
|
+
configured: boolean;
|
|
31
|
+
}): ProjectScopeOutcome;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync, realpathSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { currentProjectSandboxStatus, isWithinAllowedRoots, } from "../security/project-scope.js";
|
|
5
|
+
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
6
|
+
const SELECTION_FILENAME = "project.json";
|
|
7
|
+
export function getProjectSelectionPath(channelDir) {
|
|
8
|
+
return join(channelDir, SELECTION_FILENAME);
|
|
9
|
+
}
|
|
10
|
+
export function readProjectSelection(channelDir) {
|
|
11
|
+
const path = getProjectSelectionPath(channelDir);
|
|
12
|
+
if (!existsSync(path)) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
let raw;
|
|
16
|
+
try {
|
|
17
|
+
raw = JSON.parse(readFileSync(path, "utf-8"));
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
if (!raw ||
|
|
23
|
+
typeof raw !== "object" ||
|
|
24
|
+
raw.version !== 1 ||
|
|
25
|
+
typeof raw.projectRoot !== "string" ||
|
|
26
|
+
typeof raw.updatedAt !== "string" ||
|
|
27
|
+
typeof raw.updatedBy !== "string") {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return raw;
|
|
31
|
+
}
|
|
32
|
+
/** Same durability tradeoff as every other atomic writer in this codebase (temp + rename), minus
|
|
33
|
+
* the fsync `writeFileAtomically` does — used only for the one-time, in-constructor migration
|
|
34
|
+
* write (D3.3); every explicit mutation (`/project set|reset`) goes through the fsync'd async
|
|
35
|
+
* `writeFileAtomically` in `commitProjectSelection` instead. */
|
|
36
|
+
function writeProjectSelectionSync(channelDir, selection) {
|
|
37
|
+
const path = getProjectSelectionPath(channelDir);
|
|
38
|
+
const tempPath = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
39
|
+
writeFileSync(tempPath, `${JSON.stringify(selection, null, 2)}\n`, "utf-8");
|
|
40
|
+
renameSync(tempPath, path);
|
|
41
|
+
}
|
|
42
|
+
export async function commitProjectSelection(channelDir, projectRoot, updatedBy) {
|
|
43
|
+
const selection = {
|
|
44
|
+
version: 1,
|
|
45
|
+
projectRoot,
|
|
46
|
+
updatedAt: new Date().toISOString(),
|
|
47
|
+
updatedBy,
|
|
48
|
+
};
|
|
49
|
+
await writeFileAtomically(getProjectSelectionPath(channelDir), `${JSON.stringify(selection, null, 2)}\n`);
|
|
50
|
+
return selection;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolves the effective `ProjectScope` for a channel: its persisted selection if present and
|
|
54
|
+
* still valid, else the app default — materialized as the channel's first selection so a later
|
|
55
|
+
* daemon restart from a different startup cwd cannot silently move the channel (D3.3). Never
|
|
56
|
+
* falls back to a different root once one has been persisted (P7): a stale or now-disallowed
|
|
57
|
+
* selection blocks instead of guessing.
|
|
58
|
+
*/
|
|
59
|
+
export function resolveProjectScope(channelDir, resolution) {
|
|
60
|
+
const sandbox = currentProjectSandboxStatus();
|
|
61
|
+
const boundary = resolution.configured ? "project" : "unbounded";
|
|
62
|
+
const existing = readProjectSelection(channelDir);
|
|
63
|
+
if (!existing) {
|
|
64
|
+
const selection = {
|
|
65
|
+
version: 1,
|
|
66
|
+
projectRoot: resolution.policy.defaultRoot,
|
|
67
|
+
updatedAt: new Date().toISOString(),
|
|
68
|
+
updatedBy: "migration",
|
|
69
|
+
};
|
|
70
|
+
writeProjectSelectionSync(channelDir, selection);
|
|
71
|
+
return { kind: "ready", scope: { projectRoot: resolution.policy.defaultRoot, boundary, sandbox }, selection };
|
|
72
|
+
}
|
|
73
|
+
if (!existsSync(existing.projectRoot)) {
|
|
74
|
+
return {
|
|
75
|
+
kind: "blocked",
|
|
76
|
+
reason: `项目目录已不存在:${existing.projectRoot}。请恢复该目录,或在频道空闲时执行 /project set <path> 或 /project reset。`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
let real;
|
|
80
|
+
try {
|
|
81
|
+
real = realpathSync(existing.projectRoot);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return {
|
|
85
|
+
kind: "blocked",
|
|
86
|
+
reason: `项目目录不可读:${existing.projectRoot}。请检查权限,或在频道空闲时执行 /project set <path>。`,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (real !== existing.projectRoot) {
|
|
90
|
+
return {
|
|
91
|
+
kind: "blocked",
|
|
92
|
+
reason: `项目目录 ${existing.projectRoot} 现在指向 ${real}(symlink 已被重新指向),与上次选择不一致。请在频道空闲时执行 /project set <path> 确认新目标,或 /project reset。`,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
if (resolution.configured && !isWithinAllowedRoots(real, resolution.policy)) {
|
|
96
|
+
return {
|
|
97
|
+
kind: "blocked",
|
|
98
|
+
reason: `项目目录 ${real} 已不在允许的可选根内(security.json 的 projectAccess 已变更)。请在频道空闲时执行 /project set <path> 或 /project reset。`,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return { kind: "ready", scope: { projectRoot: real, boundary, sandbox }, selection: existing };
|
|
102
|
+
}
|