@oyasmi/pipiclaw 0.9.0 → 0.9.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/channel-runner.d.ts +5 -1
- package/dist/agent/channel-runner.js +36 -2
- package/dist/agent/commands.js +3 -1
- package/dist/agent/runner-factory.d.ts +0 -2
- package/dist/agent/types.d.ts +6 -0
- package/dist/memory/lifecycle.d.ts +15 -0
- package/dist/memory/lifecycle.js +60 -0
- package/dist/memory/task-digest.js +0 -2
- package/dist/playbooks/agent-delegation.md +3 -2
- package/dist/playbooks/task-driving.md +11 -13
- package/dist/playbooks/task-planning.md +3 -5
- package/dist/runtime/active-session-store.d.ts +12 -0
- package/dist/runtime/active-session-store.js +26 -0
- package/dist/runtime/bootstrap.d.ts +1 -1
- package/dist/runtime/bootstrap.js +87 -49
- package/dist/runtime/channel-event.d.ts +0 -6
- package/dist/runtime/delivery.js +1 -1
- package/dist/runtime/dingtalk.d.ts +7 -0
- package/dist/runtime/dingtalk.js +22 -3
- package/dist/runtime/task-commands.d.ts +1 -1
- package/dist/runtime/task-commands.js +33 -174
- package/dist/runtime/task-driver.d.ts +1 -3
- package/dist/runtime/task-driver.js +34 -40
- package/dist/runtime/task-migration.d.ts +7 -6
- package/dist/runtime/task-migration.js +85 -19
- package/dist/runtime/task-wake.d.ts +3 -5
- package/dist/runtime/task-wake.js +7 -15
- package/dist/subagents/external/run.js +18 -1
- package/dist/subagents/runs.js +22 -3
- package/dist/subagents/tool.d.ts +10 -0
- package/dist/subagents/tool.js +32 -7
- package/dist/subagents/verification-outcome.js +17 -10
- package/dist/tasks/control.d.ts +18 -67
- package/dist/tasks/control.js +44 -176
- package/dist/tasks/ledger.d.ts +7 -13
- package/dist/tasks/ledger.js +13 -49
- package/dist/tasks/store.d.ts +15 -48
- package/dist/tasks/store.js +22 -154
- package/dist/tasks/transitions.d.ts +3 -4
- package/dist/tasks/transitions.js +8 -27
- package/dist/tools/index.d.ts +0 -2
- package/dist/tools/index.js +2 -1
- package/dist/tools/registry.d.ts +0 -1
- package/dist/tools/registry.js +0 -1
- package/dist/tools/subagent-manage.d.ts +8 -1
- package/dist/tools/subagent-manage.js +77 -7
- package/dist/tools/task-manage/lifecycle.js +19 -17
- package/dist/tools/task-manage/schema.d.ts +2 -6
- package/dist/tools/task-manage/schema.js +4 -17
- package/dist/tools/task-manage/shared.js +1 -6
- package/dist/tools/task-manage/types.d.ts +0 -3
- package/dist/tools/task-manage/verification.d.ts +9 -6
- package/dist/tools/task-manage/verification.js +19 -71
- package/dist/tools/task-manage.d.ts +1 -1
- package/dist/tools/task-manage.js +2 -4
- package/dist/usage/ledger.d.ts +4 -0
- package/dist/usage/ledger.js +3 -0
- package/package.json +1 -1
|
@@ -15,7 +15,6 @@ export declare class ChannelRunner implements AgentRunner {
|
|
|
15
15
|
private readonly modelsConfigPath;
|
|
16
16
|
private readonly onSessionEvent?;
|
|
17
17
|
private readonly mediaSender?;
|
|
18
|
-
private readonly dispatchVerification?;
|
|
19
18
|
private readonly workspaceDir;
|
|
20
19
|
/**
|
|
21
20
|
* Frozen for the lifetime of this runner generation (spec 043, D4.2): AgentSession, the
|
|
@@ -60,6 +59,8 @@ export declare class ChannelRunner implements AgentRunner {
|
|
|
60
59
|
* whichever turn started in the meantime.
|
|
61
60
|
*/
|
|
62
61
|
private abandonedTurns;
|
|
62
|
+
/** Set once transport-level `/new` replaces this generation. A retired runner is never reused. */
|
|
63
|
+
private retired;
|
|
63
64
|
/** When the primary model last failed and we switched to the backup. null = on primary. */
|
|
64
65
|
private primaryFailedAt;
|
|
65
66
|
private runState;
|
|
@@ -103,6 +104,9 @@ export declare class ChannelRunner implements AgentRunner {
|
|
|
103
104
|
getMemoryMaintenanceContext(): Promise<MemoryMaintenanceRuntimeContext>;
|
|
104
105
|
getStatusSnapshot(): RunnerStatusSnapshot;
|
|
105
106
|
abort(): Promise<void>;
|
|
107
|
+
isCompacting(): boolean;
|
|
108
|
+
interruptCompaction(): boolean;
|
|
109
|
+
retireForNewSession(): void;
|
|
106
110
|
/**
|
|
107
111
|
* `/context` — read-only prompt accounting, no LLM cost. Reports the section
|
|
108
112
|
* breakdown of the system prompt, the tool schemas (billed on top of it, and
|
|
@@ -96,6 +96,8 @@ export class ChannelRunner {
|
|
|
96
96
|
* whichever turn started in the meantime.
|
|
97
97
|
*/
|
|
98
98
|
this.abandonedTurns = 0;
|
|
99
|
+
/** Set once transport-level `/new` replaces this generation. A retired runner is never reused. */
|
|
100
|
+
this.retired = false;
|
|
99
101
|
/** When the primary model last failed and we switched to the backup. null = on primary. */
|
|
100
102
|
this.primaryFailedAt = null;
|
|
101
103
|
// --- Per run ---
|
|
@@ -107,7 +109,6 @@ export class ChannelRunner {
|
|
|
107
109
|
this.modelsConfigPath = paths.modelsConfigPath;
|
|
108
110
|
this.onSessionEvent = paths.onSessionEvent;
|
|
109
111
|
this.mediaSender = paths.mediaSender;
|
|
110
|
-
this.dispatchVerification = paths.dispatchVerification;
|
|
111
112
|
const executor = createExecutor();
|
|
112
113
|
this.executor = executor;
|
|
113
114
|
this.workspaceDir = resolve(dirname(channelDir));
|
|
@@ -700,6 +701,40 @@ export class ChannelRunner {
|
|
|
700
701
|
async abort() {
|
|
701
702
|
await this.session.abort();
|
|
702
703
|
}
|
|
704
|
+
isCompacting() {
|
|
705
|
+
return this.session?.isCompacting ?? false;
|
|
706
|
+
}
|
|
707
|
+
interruptCompaction() {
|
|
708
|
+
if (!this.session?.isCompacting)
|
|
709
|
+
return false;
|
|
710
|
+
this.session.abortCompaction();
|
|
711
|
+
return true;
|
|
712
|
+
}
|
|
713
|
+
retireForNewSession() {
|
|
714
|
+
if (this.retired)
|
|
715
|
+
return;
|
|
716
|
+
this.retired = true;
|
|
717
|
+
if (this.session) {
|
|
718
|
+
this.memoryLifecycle.noteNewSessionBoundary();
|
|
719
|
+
}
|
|
720
|
+
// close() marks the delivery context closed synchronously before awaiting its drain,
|
|
721
|
+
// so late events from the old provider cannot overwrite the new session's response.
|
|
722
|
+
void this.runState.ctx?.close().catch(() => undefined);
|
|
723
|
+
this.forceEndTurn("superseded by /new");
|
|
724
|
+
const retireLiveSession = () => {
|
|
725
|
+
this.sessionUnsubscribe?.();
|
|
726
|
+
this.sessionUnsubscribe = undefined;
|
|
727
|
+
this.session.dispose();
|
|
728
|
+
};
|
|
729
|
+
if (this.session) {
|
|
730
|
+
retireLiveSession();
|
|
731
|
+
}
|
|
732
|
+
else {
|
|
733
|
+
// A second message can issue `/new` while this generation is still initializing.
|
|
734
|
+
// Let construction settle in the background, then immediately tear it down.
|
|
735
|
+
void this.sessionReady.then(retireLiveSession, () => undefined);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
703
738
|
/**
|
|
704
739
|
* `/context` — read-only prompt accounting, no LLM cost. Reports the section
|
|
705
740
|
* breakdown of the system prompt, the tool schemas (billed on top of it, and
|
|
@@ -1225,7 +1260,6 @@ export class ChannelRunner {
|
|
|
1225
1260
|
securityConfig: securityLoad.config,
|
|
1226
1261
|
toolsConfig: toolsLoad.config,
|
|
1227
1262
|
mediaSender: this.mediaSender,
|
|
1228
|
-
dispatchVerification: this.dispatchVerification,
|
|
1229
1263
|
});
|
|
1230
1264
|
this.currentTools = tools;
|
|
1231
1265
|
// Tool schemas are billed with the system prompt and, unlike it, nothing trims them.
|
package/dist/agent/commands.js
CHANGED
|
@@ -141,6 +141,7 @@ export const SESSION_COMMANDS = [
|
|
|
141
141
|
name: "new",
|
|
142
142
|
description: "开启新会话",
|
|
143
143
|
examples: ["/new"],
|
|
144
|
+
availableWhileBusy: true,
|
|
144
145
|
},
|
|
145
146
|
{
|
|
146
147
|
name: "compact",
|
|
@@ -169,7 +170,8 @@ export function isRunnerBuiltInCommand(command) {
|
|
|
169
170
|
}
|
|
170
171
|
/** Comma-separated list of commands usable while a task is streaming (names only). */
|
|
171
172
|
export function formatBusyCommandList() {
|
|
172
|
-
return BUILT_IN_COMMANDS
|
|
173
|
+
return [...BUILT_IN_COMMANDS, ...SESSION_COMMANDS]
|
|
174
|
+
.filter((command) => command.availableWhileBusy)
|
|
173
175
|
.map((command) => `\`/${command.name}\``)
|
|
174
176
|
.join(", ");
|
|
175
177
|
}
|
|
@@ -18,8 +18,6 @@ export interface RunnerFactoryPaths {
|
|
|
18
18
|
* Present enables the `send_media` tool; absent, the tool is not built.
|
|
19
19
|
*/
|
|
20
20
|
mediaSender?: MediaSender;
|
|
21
|
-
/** Runtime callback that durably enqueues an independent task verifier. */
|
|
22
|
-
dispatchVerification?: (taskId: string) => Promise<boolean>;
|
|
23
21
|
}
|
|
24
22
|
/**
|
|
25
23
|
* Stateless: always constructs a fresh runner. The daemon (`runtime/bootstrap.ts`) and the TUI
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -56,6 +56,12 @@ export interface AgentRunner {
|
|
|
56
56
|
* already discovered, without forcing a rescan. */
|
|
57
57
|
getSubAgentDiscoverySnapshot(): SubAgentDiscoveryResult;
|
|
58
58
|
abort(): Promise<void>;
|
|
59
|
+
/** True when the SDK is currently summarizing context. */
|
|
60
|
+
isCompacting?(): boolean;
|
|
61
|
+
/** Cancel context summarization synchronously; returns whether one was active. */
|
|
62
|
+
interruptCompaction?(): boolean;
|
|
63
|
+
/** Permanently retire this runner generation after an out-of-band `/new`. */
|
|
64
|
+
retireForNewSession?(): void;
|
|
59
65
|
/**
|
|
60
66
|
* Synchronously reserve the turn for a message. Transports MUST call this in
|
|
61
67
|
* the same tick they dequeue the message, before any await, so a concurrent
|
|
@@ -5,6 +5,19 @@ import type { PipiclawSessionMemorySettings } from "../settings.js";
|
|
|
5
5
|
import { type ChannelMemoryQueue } from "./channel-maintenance-queue.js";
|
|
6
6
|
import { type MemoryActivityEvent } from "./maintenance-state.js";
|
|
7
7
|
export type ConsolidationReason = "compaction" | "new-session" | "idle" | "shutdown";
|
|
8
|
+
/**
|
|
9
|
+
* Bound one standalone summarization request. Provider limits can be lower than a model's
|
|
10
|
+
* advertised context window; sending the whole pre-compaction transcript is therefore not safe.
|
|
11
|
+
* The head preserves the original goal and the larger tail preserves current work. Durable
|
|
12
|
+
* memory is refreshed before this runs, so the omitted middle is still available outside the
|
|
13
|
+
* provider request.
|
|
14
|
+
*/
|
|
15
|
+
export declare function boundCompactionMessages(messages: AgentMessage[], contextWindow: number, reserveTokens: number): {
|
|
16
|
+
messages: AgentMessage[];
|
|
17
|
+
truncated: boolean;
|
|
18
|
+
originalChars: number;
|
|
19
|
+
boundedChars: number;
|
|
20
|
+
};
|
|
8
21
|
export interface MemoryLifecycleOptions {
|
|
9
22
|
channelId: string;
|
|
10
23
|
channelDir: string;
|
|
@@ -46,6 +59,8 @@ export declare class MemoryLifecycle {
|
|
|
46
59
|
private handleSessionBeforeCompact;
|
|
47
60
|
private handleSessionCompact;
|
|
48
61
|
private handleSessionBeforeSwitch;
|
|
62
|
+
/** Snapshot the outgoing state for an out-of-band `/new` before its runner is retired. */
|
|
63
|
+
noteNewSessionBoundary(): void;
|
|
49
64
|
/** Await any in-flight detached new-session consolidation (shutdown/tests). */
|
|
50
65
|
whenNewSessionConsolidationSettled(): Promise<void>;
|
|
51
66
|
private handleSessionStart;
|
package/dist/memory/lifecycle.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { convertToLlm, serializeConversation } from "@earendil-works/pi-coding-agent";
|
|
1
2
|
import * as log from "../log.js";
|
|
2
3
|
import { formatLocalTime } from "../shared/local-time.js";
|
|
4
|
+
import { clipTextByPromptUnits } from "../shared/prompt-units.js";
|
|
3
5
|
import { errorMessage } from "../shared/text-utils.js";
|
|
4
6
|
import { getDefaultChannelMemoryQueue } from "./channel-maintenance-queue.js";
|
|
5
7
|
import { runInlineConsolidation, } from "./consolidation.js";
|
|
@@ -7,6 +9,51 @@ import { readMemoryMaintenanceState, updateMemoryMaintenanceState, } from "./mai
|
|
|
7
9
|
import { appendMemoryReviewLog } from "./review-log.js";
|
|
8
10
|
import { updateChannelSessionMemory } from "./session.js";
|
|
9
11
|
import { buildCompactionMemorySourceWindow, buildIncrementalMemorySourceWindow, } from "./source-window.js";
|
|
12
|
+
const COMPACTION_INPUT_MAX_UNITS = 48_000;
|
|
13
|
+
const COMPACTION_INPUT_MIN_UNITS = 4_000;
|
|
14
|
+
const COMPACTION_INPUT_CHARS_PER_TOKEN = 3;
|
|
15
|
+
const COMPACTION_INPUT_HEAD_RATIO = 0.35;
|
|
16
|
+
/**
|
|
17
|
+
* Bound one standalone summarization request. Provider limits can be lower than a model's
|
|
18
|
+
* advertised context window; sending the whole pre-compaction transcript is therefore not safe.
|
|
19
|
+
* The head preserves the original goal and the larger tail preserves current work. Durable
|
|
20
|
+
* memory is refreshed before this runs, so the omitted middle is still available outside the
|
|
21
|
+
* provider request.
|
|
22
|
+
*/
|
|
23
|
+
export function boundCompactionMessages(messages, contextWindow, reserveTokens) {
|
|
24
|
+
if (messages.length === 0) {
|
|
25
|
+
return { messages, truncated: false, originalChars: 0, boundedChars: 0 };
|
|
26
|
+
}
|
|
27
|
+
const safeWindow = Number.isFinite(contextWindow) && contextWindow > 0 ? Math.floor(contextWindow) : 128_000;
|
|
28
|
+
const safeReserve = Number.isFinite(reserveTokens) && reserveTokens > 0 ? Math.floor(reserveTokens) : 16_384;
|
|
29
|
+
const maxUnits = Math.min(COMPACTION_INPUT_MAX_UNITS, Math.max(COMPACTION_INPUT_MIN_UNITS, safeWindow - safeReserve - 8_192));
|
|
30
|
+
const serialized = serializeConversation(convertToLlm(messages));
|
|
31
|
+
const clipped = clipTextByPromptUnits(serialized, maxUnits, {
|
|
32
|
+
headRatio: COMPACTION_INPUT_HEAD_RATIO,
|
|
33
|
+
maxChars: maxUnits * COMPACTION_INPUT_CHARS_PER_TOKEN,
|
|
34
|
+
marker: "\n\n[... middle omitted from this compaction request; durable channel memory was refreshed before compaction ...]\n\n",
|
|
35
|
+
});
|
|
36
|
+
if (!clipped.truncated) {
|
|
37
|
+
return {
|
|
38
|
+
messages,
|
|
39
|
+
truncated: false,
|
|
40
|
+
originalChars: serialized.length,
|
|
41
|
+
boundedChars: serialized.length,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
messages: [
|
|
46
|
+
{
|
|
47
|
+
role: "user",
|
|
48
|
+
content: [{ type: "text", text: clipped.text }],
|
|
49
|
+
timestamp: Date.now(),
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
truncated: true,
|
|
53
|
+
originalChars: serialized.length,
|
|
54
|
+
boundedChars: clipped.text.length,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
10
57
|
export class MemoryLifecycle {
|
|
11
58
|
constructor(options) {
|
|
12
59
|
this.options = options;
|
|
@@ -243,6 +290,14 @@ export class MemoryLifecycle {
|
|
|
243
290
|
}
|
|
244
291
|
async handleSessionBeforeCompact(event) {
|
|
245
292
|
await this.runPreflightConsolidation("compaction", event.preparation.messagesToSummarize, this.options.getSessionEntries(), event.preparation.firstKeptEntryId);
|
|
293
|
+
const model = this.options.getModel();
|
|
294
|
+
for (const key of ["messagesToSummarize", "turnPrefixMessages"]) {
|
|
295
|
+
const bounded = boundCompactionMessages(event.preparation[key] ?? [], model.contextWindow, event.preparation.settings?.reserveTokens ?? 16_384);
|
|
296
|
+
if (!bounded.truncated)
|
|
297
|
+
continue;
|
|
298
|
+
event.preparation[key] = bounded.messages;
|
|
299
|
+
log.logWarning(`[${this.options.channelId}] Bounded oversized compaction input (${key})`, `${bounded.originalChars} -> ${bounded.boundedChars} chars; model=${model.provider}/${model.id}`);
|
|
300
|
+
}
|
|
246
301
|
}
|
|
247
302
|
handleSessionCompact(_event) {
|
|
248
303
|
this.recordActivity("boundary");
|
|
@@ -251,6 +306,10 @@ export class MemoryLifecycle {
|
|
|
251
306
|
if (event.reason !== "new") {
|
|
252
307
|
return;
|
|
253
308
|
}
|
|
309
|
+
this.noteNewSessionBoundary();
|
|
310
|
+
}
|
|
311
|
+
/** Snapshot the outgoing state for an out-of-band `/new` before its runner is retired. */
|
|
312
|
+
noteNewSessionBoundary() {
|
|
254
313
|
// Snapshot the outgoing session synchronously: the switch has not happened
|
|
255
314
|
// yet, so getMessages()/getSessionEntries() still reference the session that
|
|
256
315
|
// is about to be replaced. Once we yield, this.session is rebound to the new
|
|
@@ -265,6 +324,7 @@ export class MemoryLifecycle {
|
|
|
265
324
|
const message = errorMessage(error);
|
|
266
325
|
log.logWarning(`[${this.options.channelId}] Background new-session consolidation rejected`, message);
|
|
267
326
|
});
|
|
327
|
+
this.recordActivity("boundary");
|
|
268
328
|
}
|
|
269
329
|
/** Await any in-flight detached new-session consolidation (shutdown/tests). */
|
|
270
330
|
async whenNewSessionConsolidationSettled() {
|
|
@@ -27,8 +27,6 @@ function renderLine(entry, now) {
|
|
|
27
27
|
];
|
|
28
28
|
const control = entry.frontmatter.control;
|
|
29
29
|
if (control) {
|
|
30
|
-
parts.push(`priority ${control.priority}`);
|
|
31
|
-
parts.push(`attempt ${control.usage.attempts}/${control.budget.maxAttempts}`);
|
|
32
30
|
if (control.verification.required)
|
|
33
31
|
parts.push(`verify required/${control.verification.status}`);
|
|
34
32
|
if (control.waitingFor)
|
|
@@ -49,10 +49,11 @@ order: 36
|
|
|
49
49
|
一次委派的返回只有两种:结果已经在手,或者一个 `runId` 加"稍后会叫醒你"。后一种情况下:
|
|
50
50
|
|
|
51
51
|
1. **不要轮询,也不要用后台作业包一层等待。** 委派结束时 runtime 会唤醒本频道,带回状态、耗时、结果尾部和产物路径。这是 runtime 保证。
|
|
52
|
-
2. **立即结束当前回合。** 属于某个 task 时,派发就带上 `taskId`,并用 `task_manage progress`
|
|
52
|
+
2. **立即结束当前回合。** 属于某个 task 时,派发就带上 `taskId`,并用 `task_manage progress` 停泊为 `waiting`(`waitingFor` 随手记一个 external-signal/job 之类的展示值即可)——runtime 按 run 记录里的 `taskId` 认领并恢复该任务,不看 `waitingFor` 写了什么。
|
|
53
53
|
3. 想看进度用 `subagent_manage op=list`(人可用 `/subagents list`),不要靠反复调用委派工具来"检查"。
|
|
54
54
|
4. 每个频道最多 6 个同时在跑的委派(宿主全局 20 个)。被上限拒绝时先等一个结束或 `cancel` 一个,不要改小任务再试。
|
|
55
|
-
5. daemon 重启时外部 run
|
|
55
|
+
5. daemon 重启时外部 run 通常继续跑,内置 run 会被判 `lost` 并唤醒说明;但外部 run 若在进程 pid 真正落盘之前就重启,也会被判 `lost`,不是外部 run 的例外。收到 `lost` 就是"结局未知":先查真实产物,再决定重派,不要假设它已经做完。重连恢复出的耗时前面会带 `≈`,那是从产物文件估算出来的,不是实测值,别当精确数字用。
|
|
56
|
+
6. `subagent_manage op=show <runId>` 给出一次派发的完整机器可读细节(实际 argv、派发警告、适配器/CLI 版本、外部 run 的 stderr 尾部)——外部 run 失败但看不出原因时,先用它自诊断,不要凭猜测重派。
|
|
56
57
|
|
|
57
58
|
## 五、纠偏与续接
|
|
58
59
|
|
|
@@ -9,24 +9,23 @@ order: 41
|
|
|
9
9
|
|
|
10
10
|
## 等待与恢复
|
|
11
11
|
|
|
12
|
-
本页是 task waiting 两种形态的唯一真相源:`waiting + wake` 是定时等待;`waiting` 无 wake 是停泊信号等待,普通 driver
|
|
12
|
+
本页是 task waiting 两种形态的唯一真相源:`waiting + wake` 是定时等待;`waiting` 无 wake 是停泊信号等待,普通 driver 不会轮询。`waitingFor` 只是记录性展示——真正决定能否恢复的,是一个真实的 wake,或者 runtime 里一条 `taskId` 指向本任务、已经 settle 的 run/job 记录,不是 `waitingFor` 写的字符串本身。
|
|
13
13
|
|
|
14
|
-
- 等外部 job
|
|
15
|
-
-
|
|
16
|
-
- 只有状态查询:设置合理 wake,写 `waitingFor: time`,并在 blockedReason 记录回访对象、条件和下一步。
|
|
14
|
+
- 等外部 job、用户或委派(含 verify sub-agent):不设 wake,写 `waitingFor: job`、`user` 或 `external-signal`;后台作业或委派结束时 runtime 只恢复所属 task。独立验收就是按这条路径委派 `purpose: verify` sub-agent,没有单独的等待语义。
|
|
15
|
+
- 只有状态查询:设置合理 wake,写 `waitingFor: time`,并在 `nextAction` 记录回访对象、条件和下一步。
|
|
17
16
|
|
|
18
17
|
后台作业的启动与完成唤醒见 `background-jobs.md`;外部 AI Agent 的等待、纠偏和验收见 `agent-delegation.md`。
|
|
19
18
|
|
|
20
19
|
## 每次唤醒先恢复真相
|
|
21
20
|
|
|
22
21
|
1. 打开消息指定的 `tasks/<id>.md`,不要只依赖唤醒文本、旧对话或记忆。
|
|
23
|
-
2. 核对 status、enabled/stop、Current Cycle、`nextAction`、wake、deadline、
|
|
22
|
+
2. 核对 status、enabled/stop、Current Cycle、`nextAction`、wake、deadline、waitingFor 和 verification。
|
|
24
23
|
3. 检查上一步产物是否已经存在。派发是 at-least-once,重放可能让同一步再次到达。
|
|
25
24
|
4. 只推进一个清晰的下一阶段;外部动作前先查询真实状态,避免重复发送、发布或部署。
|
|
26
25
|
|
|
27
26
|
## 回合结束必须留下状态
|
|
28
27
|
|
|
29
|
-
仍需继续时,用 `task_manage progress` 原子记录发生了什么、证据、下一步、status/wake;Plan 变化放在同一次 `planSteps` 中。生命周期动作 `
|
|
28
|
+
仍需继续时,用 `task_manage progress` 原子记录发生了什么、证据、下一步、status/wake;Plan 变化放在同一次 `planSteps` 中。生命周期动作 `complete`、`skip`、`cancel` 本身就是 checkpoint。
|
|
30
29
|
|
|
31
30
|
- 当前可继续:`active`,清除 wake。
|
|
32
31
|
- 等待真实条件:按“等待与恢复”设置 `waiting`、wake 和 waitingFor。
|
|
@@ -47,8 +46,8 @@ Task 创建即持续委托;能力边界和 task scope 是 authority。不要
|
|
|
47
46
|
## 独立验收
|
|
48
47
|
|
|
49
48
|
1. 只有证据成立后才勾选 DoD/Verification checklist。
|
|
50
|
-
2.
|
|
51
|
-
3. checker
|
|
49
|
+
2. 像任何其他委派一样,派发一个 `purpose: verify`、带 `taskId` 的 sub-agent,然后用 `task_manage progress` 把任务停泊为 `waiting`(不设 wake,`waitingFor: external-signal`)——没有单独的 `request-verification` 动作或 `waiting + waitingFor: verification` 状态。
|
|
50
|
+
3. checker 只读检查,结尾返回 `VERDICT: PASS` 或 `VERDICT: FAIL`;完成后 runtime 通过完成唤醒恢复所属 task,恢复的依据是 run 记录里的 `taskId`,不是 `waitingFor` 写的值。
|
|
52
51
|
4. 主回合用 `task_manage verify` 导入 runId;attestation 必须属于当前 task、未改变 workspace,且 contract body hash 与 artifact subject 新鲜。
|
|
53
52
|
5. PASS/FAIL 都恢复 active;PASS 后 complete 仍会重新校验 attestation、contract hash 和 artifact subject。
|
|
54
53
|
|
|
@@ -70,7 +69,7 @@ driver 只派发 enabled 且 active 的任务。waiting 到 wake 时 runtime 先
|
|
|
70
69
|
|
|
71
70
|
## 治理器停止
|
|
72
71
|
|
|
73
|
-
deadline
|
|
72
|
+
deadline 超期,或连续三次 wake 没有可见 effect 时,runtime 写:
|
|
74
73
|
|
|
75
74
|
```text
|
|
76
75
|
enabled: false
|
|
@@ -79,18 +78,17 @@ control.stop.by: governor
|
|
|
79
78
|
control.stop.reason: <确定性原因>
|
|
80
79
|
```
|
|
81
80
|
|
|
82
|
-
治理器直接发送确定性 receipt,不开启诊断回合。先检查 Current Cycle
|
|
81
|
+
治理器直接发送确定性 receipt,不开启诊断回合。先检查 Current Cycle 和真实产物;修正范围或 deadline 后用 `/tasks resume <id>` 保留原阶段,或让 Agent cancel。
|
|
83
82
|
|
|
84
83
|
## Doctor 与损坏文件
|
|
85
84
|
|
|
86
85
|
`/tasks doctor` 的每条问题都带 Next step。重点检查:
|
|
87
86
|
|
|
88
87
|
- active 隐藏 future wake;
|
|
89
|
-
-
|
|
90
|
-
- waiting parked 是否有明确 user/job/verification 来源;
|
|
88
|
+
- waiting parked 是否有真实、可恢复的来源(有效 wake,或一条正在跑、`taskId` 指向本任务的 job/委派记录)——不看 `waitingFor` 写了什么;
|
|
91
89
|
- sleeping 的 schedule、wake 和 occurrence;
|
|
92
90
|
- enabled 与 stop 是否一致;
|
|
93
91
|
- required verification 的 attestation、contract hash、artifact subject;
|
|
94
|
-
-
|
|
92
|
+
- 不可读 frontmatter 或不可解析的 control(旧版本 control 会直接判为不可读,用 task_manage set 重写)。
|
|
95
93
|
|
|
96
94
|
修复 metadata 不执行外部动作。坏 frontmatter 会 fail-open 让问题显现;坏 control 先修 JSON,再用 task_manage set。daemon restart 后按任务文件重新恢复,仍须遵守幂等检查。
|
|
@@ -32,11 +32,9 @@ Task 创建即持续委托;是否触达外部系统由可用工具、security
|
|
|
32
32
|
|
|
33
33
|
## Control 决策
|
|
34
34
|
|
|
35
|
-
- `
|
|
36
|
-
- `nextAction
|
|
37
|
-
- `
|
|
38
|
-
- `waitingFor`:记录恢复源:time、user、job、verification 或 external-signal。
|
|
39
|
-
- `blockedReason`:写清楚等待的对象、条件和下一步。
|
|
35
|
+
- `deadline`:硬期限,表达真实用户意图;不用 `wake` 冒充 deadline。
|
|
36
|
+
- `nextAction`:下一条可执行动作,避免抽象愿望;也是等待时记录"等什么、条件、下一步"的地方——不再有单独的 blockedReason 字段。
|
|
37
|
+
- `waitingFor`:记录性展示,说明恢复源大致是 time、user、job 还是 external-signal;driver 是否恢复只看真实的 wake 或 run/job 记录,`waitingFor` 本身不影响恢复。
|
|
40
38
|
- `wake`:最早回访时间;future wake 会使任务规范为 waiting。
|
|
41
39
|
- `schedule`:五字段 cron;存在即 recurring。
|
|
42
40
|
|
|
@@ -40,3 +40,15 @@ export interface SessionFileHandle {
|
|
|
40
40
|
* the old session) remains authoritative.
|
|
41
41
|
*/
|
|
42
42
|
export declare function commitActiveSessionRef(channelDir: string, session: SessionFileHandle): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Create a durable empty session and atomically make it active for a channel.
|
|
45
|
+
*
|
|
46
|
+
* This deliberately does not touch a live AgentSession. It is the transport-level `/new`
|
|
47
|
+
* primitive: a wedged provider request or compaction in the old runner cannot delay the
|
|
48
|
+
* commit. Materializing and reopening the file makes the SDK write the session header before
|
|
49
|
+
* the active ref points at it, preserving the same file-before-pointer ordering as normal SDK
|
|
50
|
+
* topology changes.
|
|
51
|
+
*/
|
|
52
|
+
export declare function createFreshActiveSession(channelDir: string, cwd: string): Promise<{
|
|
53
|
+
sessionId: string;
|
|
54
|
+
}>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { closeSync, existsSync, openSync, readFileSync } from "node:fs";
|
|
2
2
|
import { basename, dirname, join, resolve } from "node:path";
|
|
3
|
+
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
3
4
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
4
5
|
const REF_FILENAME = "active-session.json";
|
|
5
6
|
const DEFAULT_SESSION_FILENAME = "context.jsonl";
|
|
@@ -98,3 +99,28 @@ export async function commitActiveSessionRef(channelDir, session) {
|
|
|
98
99
|
};
|
|
99
100
|
await writeFileAtomically(getActiveSessionRefPath(channelDir), `${JSON.stringify(ref, null, 2)}\n`);
|
|
100
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a durable empty session and atomically make it active for a channel.
|
|
104
|
+
*
|
|
105
|
+
* This deliberately does not touch a live AgentSession. It is the transport-level `/new`
|
|
106
|
+
* primitive: a wedged provider request or compaction in the old runner cannot delay the
|
|
107
|
+
* commit. Materializing and reopening the file makes the SDK write the session header before
|
|
108
|
+
* the active ref points at it, preserving the same file-before-pointer ordering as normal SDK
|
|
109
|
+
* topology changes.
|
|
110
|
+
*/
|
|
111
|
+
export async function createFreshActiveSession(channelDir, cwd) {
|
|
112
|
+
const provisional = SessionManager.create(cwd, channelDir);
|
|
113
|
+
const sessionFile = provisional.getSessionFile();
|
|
114
|
+
if (!sessionFile) {
|
|
115
|
+
throw new Error("Cannot create a new session: the SDK did not allocate a backing file.");
|
|
116
|
+
}
|
|
117
|
+
const resolvedDir = resolve(channelDir);
|
|
118
|
+
const resolvedFile = resolve(sessionFile);
|
|
119
|
+
if (dirname(resolvedFile) !== resolvedDir) {
|
|
120
|
+
throw new Error(`New session file must live directly under the channel directory: ${sessionFile}`);
|
|
121
|
+
}
|
|
122
|
+
materializeSessionFile(channelDir, basename(resolvedFile));
|
|
123
|
+
const durable = SessionManager.open(resolvedFile, channelDir, cwd);
|
|
124
|
+
await commitActiveSessionRef(channelDir, durable);
|
|
125
|
+
return { sessionId: durable.getSessionId() };
|
|
126
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AgentRunner } from "../agent/index.js";
|
|
2
2
|
import { type Executor } from "../executor.js";
|
|
3
3
|
import { PipiclawSettingsManager } from "../settings.js";
|
|
4
|
-
import {
|
|
4
|
+
import type { WakeTaskTransitionHooks } from "../tasks/store.js";
|
|
5
5
|
import { type BootstrapIO, type BootstrapPaths } from "./app-home.js";
|
|
6
6
|
import type { ChannelEvent } from "./channel-event.js";
|
|
7
7
|
import { DingTalkBot, type DingTalkConfig, type DingTalkHandler } from "./dingtalk.js";
|