@oyasmi/pipiclaw 0.9.2-beta.1 → 0.9.2-beta.3
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 +13 -0
- package/dist/agent/channel-runner.js +67 -19
- package/dist/agent/job-manager.js +3 -0
- package/dist/playbooks/agent-delegation.md +1 -1
- package/dist/playbooks/task-driving.md +3 -3
- package/dist/runtime/bootstrap.js +29 -7
- package/dist/runtime/channel-event.d.ts +8 -0
- package/dist/runtime/subagent-commands.d.ts +8 -0
- package/dist/runtime/subagent-commands.js +28 -4
- package/dist/runtime/task-commands.js +7 -2
- package/dist/runtime/task-wake.d.ts +7 -2
- package/dist/runtime/task-wake.js +22 -3
- package/dist/settings.d.ts +12 -0
- package/dist/settings.js +9 -0
- package/dist/subagents/external/claude-code.js +20 -0
- package/dist/subagents/external/codex-cli.js +33 -0
- package/dist/subagents/external/harness.d.ts +8 -0
- package/dist/subagents/external/progress-tail.d.ts +14 -0
- package/dist/subagents/external/progress-tail.js +84 -0
- package/dist/subagents/external/run.d.ts +6 -0
- package/dist/subagents/external/run.js +123 -58
- package/dist/subagents/external/settlement.d.ts +7 -1
- package/dist/subagents/external/settlement.js +28 -7
- package/dist/subagents/runs.d.ts +80 -8
- package/dist/subagents/runs.js +260 -58
- package/dist/subagents/tool.d.ts +4 -5
- package/dist/subagents/tool.js +73 -40
- package/dist/subagents/verification-outcome.js +1 -1
- package/dist/tasks/artifact-subject.d.ts +38 -4
- package/dist/tasks/artifact-subject.js +282 -25
- package/dist/tasks/verification.d.ts +24 -2
- package/dist/tasks/verification.js +113 -21
- package/dist/tools/grep.js +4 -1
- package/dist/tools/subagent-manage.js +14 -14
- package/dist/tools/task-manage/lifecycle.js +7 -4
- package/dist/tools/task-manage/verification.d.ts +1 -1
- package/dist/tools/task-manage/verification.js +12 -7
- package/dist/tui/pitui-frontend.js +3 -3
- package/examples/sub-agents/README.md +14 -13
- package/examples/sub-agents/builder-hard.md +17 -16
- package/examples/sub-agents/builder.md +16 -12
- package/examples/sub-agents/documenter.md +17 -17
- package/examples/sub-agents/explorer.md +12 -13
- package/examples/sub-agents/git-committer.md +15 -26
- package/examples/sub-agents/log-sifter.md +13 -12
- package/examples/sub-agents/planner.md +11 -11
- package/examples/sub-agents/reviewer.md +21 -12
- package/examples/sub-agents/scout.md +16 -12
- package/examples/sub-agents/verifier.md +18 -13
- package/examples/sub-agents/worker.md +17 -10
- package/package.json +5 -5
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Agent, type ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
|
+
import { AgentSession, SettingsManager as SDKSettingsManager, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
1
4
|
import type { MemoryMaintenanceRuntimeContext } from "../memory/scheduler.js";
|
|
2
5
|
import type { ChannelContext } from "../runtime/channel-context.js";
|
|
3
6
|
import type { ChannelStore } from "../runtime/store.js";
|
|
@@ -6,6 +9,11 @@ import { type SubAgentDiscoveryResult } from "../subagents/discovery.js";
|
|
|
6
9
|
import { type RunnerBuiltInCommand } from "./commands.js";
|
|
7
10
|
import type { RunnerFactoryPaths } from "./runner-factory.js";
|
|
8
11
|
import { type AgentRunner, type RunnerStatusSnapshot, type TurnStatus } from "./types.js";
|
|
12
|
+
/** Apply the pi 0.83 source-model thinking compatibility branch to one real AgentSession. */
|
|
13
|
+
export declare function setModelWithThinkingPreservation(session: AgentSession, manager: SDKSettingsManager, model: Model<Api>): Promise<void>;
|
|
14
|
+
export declare function setThinkingLevelWithConditionalPersist(session: AgentSession, level: ThinkingLevel): void;
|
|
15
|
+
export declare function cycleThinkingLevelWithConditionalPersist(session: AgentSession): ThinkingLevel | undefined;
|
|
16
|
+
export declare function initializeThinkingLevelCompat(agent: Agent, model: Model<Api>, sessionManager: SessionManager, configuredDefault: ThinkingLevel | undefined): ThinkingLevel;
|
|
9
17
|
export declare class ChannelRunner implements AgentRunner {
|
|
10
18
|
private readonly executor;
|
|
11
19
|
private readonly fileStore;
|
|
@@ -25,6 +33,8 @@ export declare class ChannelRunner implements AgentRunner {
|
|
|
25
33
|
*/
|
|
26
34
|
private readonly projectScope;
|
|
27
35
|
private session;
|
|
36
|
+
/** Settings manager owned by the currently bound AgentSession. */
|
|
37
|
+
private sessionSettingsManager;
|
|
28
38
|
private agent;
|
|
29
39
|
private sessionManager;
|
|
30
40
|
private readonly settingsManager;
|
|
@@ -168,6 +178,9 @@ export declare class ChannelRunner implements AgentRunner {
|
|
|
168
178
|
* switch back to the preferred model. Silent — no user notice on recovery.
|
|
169
179
|
*/
|
|
170
180
|
private maybeRestorePrimaryModel;
|
|
181
|
+
private setModelWithThinkingPreservation;
|
|
182
|
+
private setThinkingLevelCompat;
|
|
183
|
+
private cycleThinkingLevelCompat;
|
|
171
184
|
/**
|
|
172
185
|
* Resolve the configured backup model reference against available models.
|
|
173
186
|
* Returns null when unset, unresolvable/ambiguous, or missing an API key —
|
|
@@ -64,12 +64,58 @@ function asSdkSettingsManager(manager) {
|
|
|
64
64
|
return SDKSettingsManager.inMemory({
|
|
65
65
|
defaultProvider: manager.getDefaultProvider(),
|
|
66
66
|
defaultModel: manager.getDefaultModel(),
|
|
67
|
-
defaultThinkingLevel: manager.getDefaultThinkingLevel(),
|
|
67
|
+
defaultThinkingLevel: manager.getDefaultThinkingLevel() ?? DEFAULT_MAIN_THINKING_LEVEL,
|
|
68
68
|
compaction: manager.getCompactionSettings(),
|
|
69
69
|
retry: manager.getRetrySettings(),
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
const DEFAULT_MAIN_THINKING_LEVEL = "medium";
|
|
73
|
+
/** Apply the pi 0.83 source-model thinking compatibility branch to one real AgentSession. */
|
|
74
|
+
export async function setModelWithThinkingPreservation(session, manager, model) {
|
|
75
|
+
const source = session.model;
|
|
76
|
+
if (!source?.reasoning) {
|
|
77
|
+
await session.setModel(model);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const previousDefault = manager.getDefaultThinkingLevel();
|
|
81
|
+
manager.setDefaultThinkingLevel(session.thinkingLevel);
|
|
82
|
+
try {
|
|
83
|
+
await session.setModel(model);
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
manager.setDefaultThinkingLevel(previousDefault ?? DEFAULT_MAIN_THINKING_LEVEL);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export function setThinkingLevelWithConditionalPersist(session, level) {
|
|
90
|
+
const before = session.thinkingLevel;
|
|
91
|
+
session.setThinkingLevel(level);
|
|
92
|
+
const effective = session.thinkingLevel;
|
|
93
|
+
if (effective === before)
|
|
94
|
+
return;
|
|
95
|
+
if (!session.model?.reasoning && effective === "off")
|
|
96
|
+
return;
|
|
97
|
+
session.setThinkingLevel(effective, { persist: true });
|
|
98
|
+
}
|
|
99
|
+
export function cycleThinkingLevelWithConditionalPersist(session) {
|
|
100
|
+
const before = session.thinkingLevel;
|
|
101
|
+
const next = session.cycleThinkingLevel();
|
|
102
|
+
const effective = session.thinkingLevel;
|
|
103
|
+
if (next && effective !== before && (session.model?.reasoning || effective !== "off")) {
|
|
104
|
+
session.setThinkingLevel(effective, { persist: true });
|
|
105
|
+
}
|
|
106
|
+
return next;
|
|
107
|
+
}
|
|
108
|
+
export function initializeThinkingLevelCompat(agent, model, sessionManager, configuredDefault) {
|
|
109
|
+
const branch = sessionManager.getBranch();
|
|
110
|
+
const hasThinkingEntry = branch.some((entry) => entry.type === "thinking_level_change");
|
|
111
|
+
const historical = sessionManager.buildSessionContext().thinkingLevel;
|
|
112
|
+
const requested = hasThinkingEntry ? historical : (configuredDefault ?? DEFAULT_MAIN_THINKING_LEVEL);
|
|
113
|
+
const effective = clampThinkingLevel(model, requested);
|
|
114
|
+
agent.state.thinkingLevel = effective;
|
|
115
|
+
if (!hasThinkingEntry)
|
|
116
|
+
sessionManager.appendThinkingLevelChange(effective);
|
|
117
|
+
return effective;
|
|
118
|
+
}
|
|
73
119
|
/**
|
|
74
120
|
* Ceilings for the two awaited steps of a session-resource reload. Both reach
|
|
75
121
|
* the network (model/auth re-resolution; the SDK session's own reload) and
|
|
@@ -389,7 +435,7 @@ export class ChannelRunner {
|
|
|
389
435
|
getCurrentModelRef: () => formatModelReference(this.session.model ?? this.activeModel),
|
|
390
436
|
resolveFallbackModel: () => this.resolveFallbackModel(),
|
|
391
437
|
setModel: async (model) => {
|
|
392
|
-
await this.
|
|
438
|
+
await this.setModelWithThinkingPreservation(model);
|
|
393
439
|
},
|
|
394
440
|
notifySwitch: (from, to, errorSummary) => {
|
|
395
441
|
fallbackTargetRef = to;
|
|
@@ -930,7 +976,7 @@ export class ChannelRunner {
|
|
|
930
976
|
return;
|
|
931
977
|
}
|
|
932
978
|
try {
|
|
933
|
-
await this.
|
|
979
|
+
await this.setModelWithThinkingPreservation(this.activeModel);
|
|
934
980
|
this.primaryFailedAt = null;
|
|
935
981
|
log.logInfo(`[${this.channelId}] Restored primary model ${formatModelReference(this.activeModel)}`);
|
|
936
982
|
}
|
|
@@ -938,6 +984,15 @@ export class ChannelRunner {
|
|
|
938
984
|
log.logWarning(`[${this.channelId}] Failed to restore primary model`, errorMessage(err));
|
|
939
985
|
}
|
|
940
986
|
}
|
|
987
|
+
async setModelWithThinkingPreservation(model) {
|
|
988
|
+
await setModelWithThinkingPreservation(this.session, this.sessionSettingsManager, model);
|
|
989
|
+
}
|
|
990
|
+
setThinkingLevelCompat(level) {
|
|
991
|
+
setThinkingLevelWithConditionalPersist(this.session, level);
|
|
992
|
+
}
|
|
993
|
+
cycleThinkingLevelCompat() {
|
|
994
|
+
return cycleThinkingLevelWithConditionalPersist(this.session);
|
|
995
|
+
}
|
|
941
996
|
/**
|
|
942
997
|
* Resolve the configured backup model reference against available models.
|
|
943
998
|
* Returns null when unset, unresolvable/ambiguous, or missing an API key —
|
|
@@ -979,10 +1034,11 @@ export class ChannelRunner {
|
|
|
979
1034
|
this.subAgentDiscovery = await this.refreshSubAgentDiscovery();
|
|
980
1035
|
const initialResourceLoader = this.createResourceLoader();
|
|
981
1036
|
const baseToolsOverride = Object.fromEntries(this.currentTools.map((tool) => [tool.name, tool]));
|
|
1037
|
+
this.sessionSettingsManager = asSdkSettingsManager(this.settingsManager);
|
|
982
1038
|
this.session = new AgentSession({
|
|
983
1039
|
agent: this.agent,
|
|
984
1040
|
sessionManager: this.sessionManager,
|
|
985
|
-
settingsManager:
|
|
1041
|
+
settingsManager: this.sessionSettingsManager,
|
|
986
1042
|
cwd: this.projectScope.projectRoot,
|
|
987
1043
|
modelRuntime: this.modelRuntime,
|
|
988
1044
|
resourceLoader: initialResourceLoader,
|
|
@@ -1174,11 +1230,11 @@ export class ChannelRunner {
|
|
|
1174
1230
|
getSessionStats: () => this.session.getSessionStats(),
|
|
1175
1231
|
getThinkingLevel: () => this.session.thinkingLevel,
|
|
1176
1232
|
getAvailableThinkingLevels: () => this.session.getAvailableThinkingLevels(),
|
|
1177
|
-
setThinkingLevel: (level) => this.
|
|
1178
|
-
cycleThinkingLevel: () => this.
|
|
1233
|
+
setThinkingLevel: (level) => this.setThinkingLevelCompat(level),
|
|
1234
|
+
cycleThinkingLevel: () => this.cycleThinkingLevelCompat(),
|
|
1179
1235
|
getLastResponseModel: () => getLastAssistantUsage(this.session.messages)?.responseModel,
|
|
1180
1236
|
switchModel: async (model) => {
|
|
1181
|
-
await this.
|
|
1237
|
+
await this.setModelWithThinkingPreservation(model);
|
|
1182
1238
|
this.activeModel = model;
|
|
1183
1239
|
// Manual /model switch redefines the preferred model and clears fallback state.
|
|
1184
1240
|
this.primaryFailedAt = null;
|
|
@@ -1230,17 +1286,7 @@ export class ChannelRunner {
|
|
|
1230
1286
|
* clamped to the selected model before the session starts.
|
|
1231
1287
|
*/
|
|
1232
1288
|
initializeThinkingLevel(agent, model, sessionManager) {
|
|
1233
|
-
|
|
1234
|
-
const hasThinkingEntry = branch.some((entry) => entry.type === "thinking_level_change");
|
|
1235
|
-
const sessionThinkingLevel = sessionManager.buildSessionContext().thinkingLevel;
|
|
1236
|
-
const requestedLevel = hasThinkingEntry
|
|
1237
|
-
? sessionThinkingLevel
|
|
1238
|
-
: (this.settingsManager.getDefaultThinkingLevel() ?? DEFAULT_MAIN_THINKING_LEVEL);
|
|
1239
|
-
const effectiveLevel = clampThinkingLevel(model, requestedLevel);
|
|
1240
|
-
agent.state.thinkingLevel = effectiveLevel;
|
|
1241
|
-
if (!hasThinkingEntry) {
|
|
1242
|
-
sessionManager.appendThinkingLevelChange(effectiveLevel);
|
|
1243
|
-
}
|
|
1289
|
+
initializeThinkingLevelCompat(agent, model, sessionManager, this.settingsManager.getDefaultThinkingLevel());
|
|
1244
1290
|
}
|
|
1245
1291
|
createSessionRuntime(sessionManager, sessionStartEvent) {
|
|
1246
1292
|
const tools = this.buildRuntimeTools();
|
|
@@ -1257,16 +1303,18 @@ export class ChannelRunner {
|
|
|
1257
1303
|
});
|
|
1258
1304
|
this.initializeThinkingLevel(agent, this.activeModel, sessionManager);
|
|
1259
1305
|
const resourceLoader = this.createResourceLoader();
|
|
1306
|
+
const sessionSettingsManager = asSdkSettingsManager(this.settingsManager);
|
|
1260
1307
|
const session = new AgentSession({
|
|
1261
1308
|
agent,
|
|
1262
1309
|
sessionManager,
|
|
1263
|
-
settingsManager:
|
|
1310
|
+
settingsManager: sessionSettingsManager,
|
|
1264
1311
|
cwd: this.projectScope.projectRoot,
|
|
1265
1312
|
modelRuntime: this.modelRuntime,
|
|
1266
1313
|
resourceLoader,
|
|
1267
1314
|
baseToolsOverride: Object.fromEntries(tools.map((tool) => [tool.name, tool])),
|
|
1268
1315
|
sessionStartEvent,
|
|
1269
1316
|
});
|
|
1317
|
+
this.sessionSettingsManager = sessionSettingsManager;
|
|
1270
1318
|
return { agent, session, resourceLoader };
|
|
1271
1319
|
}
|
|
1272
1320
|
buildRuntimeTools() {
|
|
@@ -365,6 +365,9 @@ export class ChannelJobManager {
|
|
|
365
365
|
ts: String(Date.now()),
|
|
366
366
|
conversationType: this.channelId.startsWith("group_") ? "2" : "1",
|
|
367
367
|
dispatchId: `job:${this.channelId}:${record.id}:done`,
|
|
368
|
+
// P0-2: a user is waiting on this job's result — render the resulting turn's progress
|
|
369
|
+
// instead of the "none" style autonomous check-ins get.
|
|
370
|
+
presentation: "awaited",
|
|
368
371
|
...(record.contract.taskId
|
|
369
372
|
? {
|
|
370
373
|
internalWake: {
|
|
@@ -72,7 +72,7 @@ order: 60
|
|
|
72
72
|
|
|
73
73
|
取回后核对**真实文件、diff 和测试结果**。执行者的完成声明和自验只是第一层证据,代替不了你的独立检查——外部 Agent 尤其如此,它判定"完成"和"通过"的标准不受本 runtime 约束。
|
|
74
74
|
|
|
75
|
-
`purpose=verify`
|
|
75
|
+
`purpose=verify` 的验收者可以声明 `mutates: write`,这样它会在验证期间持有目标工作区的独占 lease,并允许运行可能生成临时产物的测试/构建;但这类 attestation 是 `advisory`,不是完全只读证明。`exec` harness 仍因没有协议终态而被 runtime 直接拒绝。**过了准入门也不等于结论有结构性保证**:内置角色只有在声明 `mutates: read` 且 `tools` 里没有 `bash` 时才标 `enforced`(`write`/`edit` 被结构性移除);带 `bash` 的内置角色、写 verifier 和所有外部角色都标 `advisory`——`bash` 一样能写文件。看到 `advisory` 就按风险抽查,不要看见 `Verdict: PASS` 就放行。协议禁止 verifier 修改被验收实现或为了通过测试而修代码。
|
|
76
76
|
|
|
77
77
|
让验收者只判断、不顺手改产物;改了就得重新验收(细则见 `task-driving.md`)。
|
|
78
78
|
|
|
@@ -47,10 +47,10 @@ task scope 就是 authority:不要扩大目标、渠道、环境或对象范
|
|
|
47
47
|
|
|
48
48
|
1. 只有证据成立后才勾选 DoD / Verification checklist。
|
|
49
49
|
2. 像任何其他委派一样,派发一个 `purpose: verify`、带 `taskId` 的 sub-agent,然后用带 `note` 的 `task_update` 把任务停泊为 `waiting`(不设 wake,`waitingFor: external-signal`)——没有单独的 `request-verification` 动作,也没有 `waiting + waitingFor: verification` 这种状态。
|
|
50
|
-
3. checker
|
|
51
|
-
4. 主回合用 `task_verify` 导入 runId;attestation 必须属于当前 task
|
|
50
|
+
3. checker 只判断、不修复被验收实现,结尾返回 `VERDICT: PASS` 或 `VERDICT: FAIL`;需要运行测试/构建时可以使用声明 `mutates: write` 的 verifier,但它会占用目标工作区独占 lease,并以 `advisory` 强度运行。完成后 runtime 通过完成唤醒恢复所属 task,依据是 run 记录里的 `taskId`。
|
|
51
|
+
4. 主回合用 `task_verify` 导入 runId;attestation 必须属于当前 task、未改变受保护 workspace 内容,且 contract body hash 与 artifact subject 新鲜。新 subject 以验证开始时的 `baseCommit` 为基准:正常提交已验收内容不算变化;明确临时产物范围外的新源文件,以及验证开始前已存在的 untracked 产品文件变化,仍会使验收失败。
|
|
52
52
|
5. PASS/FAIL 都恢复 active;PASS 后 complete 仍会重新校验 attestation、contract hash 和 artifact subject。
|
|
53
|
-
6. attestation 标 `advisory` 时(带 `bash`
|
|
53
|
+
6. attestation 标 `advisory` 时(带 `bash` 的内置验收者、声明 `mutates: write` 的 verifier,以及所有外部验收者),结论只是参考而非结构性保证,仍要按风险抽查;判定强度的来源见 `agent-delegation.md`。
|
|
54
54
|
|
|
55
55
|
PASS 绑定 Goal/DoD/Manual/Verification 这段 contract,不绑定 Plan、Current Cycle 或 History。改动 contract 或被验收产物后必须重新验收;不要让 verifier 顺手修实现。
|
|
56
56
|
|
|
@@ -37,7 +37,7 @@ import { handleProjectCommand as runProjectCommand } from "./project-commands.js
|
|
|
37
37
|
import { resolveProjectScope } from "./project-scope-store.js";
|
|
38
38
|
import { installLlmProxy } from "./proxy.js";
|
|
39
39
|
import { ChannelStore } from "./store.js";
|
|
40
|
-
import { handleSubagentsCommand as runSubagentsCommand } from "./subagent-commands.js";
|
|
40
|
+
import { renderRunNotice, handleSubagentsCommand as runSubagentsCommand } from "./subagent-commands.js";
|
|
41
41
|
import { pauseTask, handleTasksCommand as runTasksCommand } from "./task-commands.js";
|
|
42
42
|
import { createTaskDriverEvent, TaskDriver } from "./task-driver.js";
|
|
43
43
|
import { migrateLegacyTaskScheduleEvents, migrateLegacyTaskState } from "./task-migration.js";
|
|
@@ -480,9 +480,12 @@ export async function createRuntimeContext(options) {
|
|
|
480
480
|
isBot: false,
|
|
481
481
|
skipContextSync: Boolean(builtInCommand),
|
|
482
482
|
}, "user message");
|
|
483
|
-
// Background wakes deliver their result, not their process: no progress card,
|
|
484
|
-
//
|
|
485
|
-
|
|
483
|
+
// Background wakes deliver their result, not their process: no progress card, no
|
|
484
|
+
// thinking stream, nothing to delete when the check-in ends `[SILENT]`. An "awaited"
|
|
485
|
+
// wake (a delegation or job finishing) is the opposite — a human is actually waiting
|
|
486
|
+
// on it — so it renders progress the same way a normal message does (P0-2).
|
|
487
|
+
const backgroundOnly = Boolean(_isEvent) && event.presentation !== "awaited";
|
|
488
|
+
const ctx = createDingTalkContext(event, bot, store, backgroundOnly ? "none" : undefined);
|
|
486
489
|
if (builtInCommand) {
|
|
487
490
|
const commandStartedAt = Date.now();
|
|
488
491
|
const logCtx = { channelId: event.channelId, userName: event.userName };
|
|
@@ -534,7 +537,7 @@ export async function createRuntimeContext(options) {
|
|
|
534
537
|
ctx: { channelId: event.channelId, userName: event.userName },
|
|
535
538
|
fields: { messageLength: event.text.length, source: _isEvent ? "event" : "message" },
|
|
536
539
|
});
|
|
537
|
-
if (!
|
|
540
|
+
if (!backgroundOnly) {
|
|
538
541
|
ctx.primeCard(350);
|
|
539
542
|
}
|
|
540
543
|
// Effects are tallied per channel; the governor needs them per task, so one
|
|
@@ -563,7 +566,11 @@ export async function createRuntimeContext(options) {
|
|
|
563
566
|
recoveredJobTaskId = claimed.taskId;
|
|
564
567
|
await claimed.finish();
|
|
565
568
|
structuredWakeFinalized = true;
|
|
566
|
-
|
|
569
|
+
// Drop without a turn only when something else is still driving this task (a
|
|
570
|
+
// sibling wake in the same fan-out already activated it); every other case —
|
|
571
|
+
// the task is done, archived, disabled, or gone — has nobody left to see this
|
|
572
|
+
// result if it is dropped here, so it must still reach a normal turn (P3-1).
|
|
573
|
+
if (event.internalWake?.kind === "job" && !claimed.activated && claimed.taskStillDriven)
|
|
567
574
|
return;
|
|
568
575
|
}
|
|
569
576
|
else {
|
|
@@ -590,7 +597,9 @@ export async function createRuntimeContext(options) {
|
|
|
590
597
|
recoveredDelegationTaskId = claimed.taskId;
|
|
591
598
|
await claimed.finish();
|
|
592
599
|
structuredWakeFinalized = true;
|
|
593
|
-
|
|
600
|
+
// See the JOB branch above (P3-1): only skip the turn when the task is still
|
|
601
|
+
// driven by something else.
|
|
602
|
+
if (event.internalWake?.kind === "subagent" && !claimed.activated && claimed.taskStillDriven)
|
|
594
603
|
return;
|
|
595
604
|
}
|
|
596
605
|
else {
|
|
@@ -669,6 +678,19 @@ export async function createRuntimeContext(options) {
|
|
|
669
678
|
configureSubAgentRuntime({
|
|
670
679
|
stateDir: join(options.paths.appHomeDir, "state", "subagent-runs"),
|
|
671
680
|
dispatch: (event) => durableDispatch?.dispatch(event) ?? false,
|
|
681
|
+
// P0-1/P1a: a best-effort out-of-band notice, independent of the completion wake — it reaches
|
|
682
|
+
// the channel in roughly the time the run itself takes, not the wake turn's own LLM latency
|
|
683
|
+
// on top of that. `notices: "off"` (settings.json) restores today's silent behavior.
|
|
684
|
+
notify: (channelId, notice) => {
|
|
685
|
+
const level = runtimeSettingsManager.getDelegationSettings().notices;
|
|
686
|
+
if (level === "off")
|
|
687
|
+
return;
|
|
688
|
+
if (level === "settled" && notice.kind !== "settled")
|
|
689
|
+
return;
|
|
690
|
+
const text = renderRunNotice(notice);
|
|
691
|
+
if (text)
|
|
692
|
+
void bot.sendPlain(channelId, text);
|
|
693
|
+
},
|
|
672
694
|
ledger: getUsageLedger(),
|
|
673
695
|
store,
|
|
674
696
|
});
|
|
@@ -32,4 +32,12 @@ export interface ChannelEvent {
|
|
|
32
32
|
taskId: string;
|
|
33
33
|
dispatchId: string;
|
|
34
34
|
};
|
|
35
|
+
/**
|
|
36
|
+
* Purely a display hint: `"awaited"` marks a synthetic wake a human is actually waiting on (a
|
|
37
|
+
* delegation or background job finishing), as opposed to an autonomous check-in (task-driver
|
|
38
|
+
* polling, a scheduled event) that normally has nothing to say. The runtime uses it to decide
|
|
39
|
+
* whether the resulting turn renders progress or stays silent until a final answer — it must
|
|
40
|
+
* never gate task activation or any other trust decision; that stays on `internalWake` alone.
|
|
41
|
+
*/
|
|
42
|
+
presentation?: "awaited";
|
|
35
43
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SubAgentDiscoveryResult } from "../subagents/discovery.js";
|
|
2
|
+
import { type RunNotice } from "../subagents/runs.js";
|
|
2
3
|
/**
|
|
3
4
|
* `/subagents` — the human control path that does not depend on the model (spec 040 D6, polished
|
|
4
5
|
* by spec 041). Mirrors `task-commands.ts`'s shape: pure functions returning markdown, no
|
|
@@ -34,4 +35,11 @@ type SubagentsCommand = {
|
|
|
34
35
|
/** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
|
|
35
36
|
export declare function parseSubagentsCommand(args: string): SubagentsCommand;
|
|
36
37
|
export declare function handleSubagentsCommand(options: HandleSubagentsCommandOptions): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Render a `RunNotice` (P0-1/P1a) as a one-line reply — a confirmation, per the command reply
|
|
40
|
+
* conventions. `notices: "off"` is enforced by the caller not invoking this at all; a `"settled"`
|
|
41
|
+
* caller filters `kind: "progress"` out before calling. Returns `undefined` for a notice with
|
|
42
|
+
* nothing worth showing (a progress step that never resolved to a label).
|
|
43
|
+
*/
|
|
44
|
+
export declare function renderRunNotice(notice: RunNotice): string | undefined;
|
|
37
45
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { renderSubcommandUsage } from "../agent/commands.js";
|
|
4
|
+
import { formatDuration } from "../shared/duration.js";
|
|
4
5
|
import { errorMessage } from "../shared/text-utils.js";
|
|
5
6
|
import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format.js";
|
|
6
7
|
import { getSubAgentRunManager } from "../subagents/runs.js";
|
|
@@ -262,7 +263,10 @@ function formatRoleSummaryLine(agent) {
|
|
|
262
263
|
const kind = agent.runtime === "external" ? `外部/${agent.harness}` : "内置";
|
|
263
264
|
const mutates = agent.mutates ?? (agent.tools.includes("write") || agent.tools.includes("edit") ? "write" : "read");
|
|
264
265
|
const unavailable = agent.unavailable ? ` — ⚠ 不可用:${agent.unavailable}` : "";
|
|
265
|
-
|
|
266
|
+
const modelLabel = agent.runtime === "external" ? (agent.externalModelRef ?? "CLI 决定") : (agent.modelRef ?? "默认");
|
|
267
|
+
const thinkingLabel = agent.thinkingLevel ?? (agent.runtime === "external" ? "未设置" : "默认 medium");
|
|
268
|
+
// Keyless by design: the four positions are fixed — runtime, mutates, model, thinking.
|
|
269
|
+
return `- \`${agent.name}\` (${kind}, ${mutates}, ${modelLabel}, ${thinkingLabel}) — ${agent.description}${unavailable}`;
|
|
266
270
|
}
|
|
267
271
|
function formatRoleDetail(agent) {
|
|
268
272
|
const kind = agent.runtime === "external" ? `外部/${agent.harness}` : "内置";
|
|
@@ -276,12 +280,12 @@ function formatRoleDetail(agent) {
|
|
|
276
280
|
lines.push(`- ⚠ 不可用:${agent.unavailable}`);
|
|
277
281
|
lines.push(`- mutates:${agent.mutates ?? "(未声明,由 tools 推断)"}`);
|
|
278
282
|
if (agent.runtime === "internal") {
|
|
279
|
-
lines.push(`-
|
|
283
|
+
lines.push(`- model:${agent.modelRef ?? "默认"}`, `- thinking:${agent.thinkingLevel ?? "默认 medium"}`, `- tools:${agent.tools.join(", ") || "(none)"}`, `- 预算:maxTurns=${agent.maxTurns} maxToolCalls=${agent.maxToolCalls} maxWallTimeSec=${agent.maxWallTimeSec} bashTimeoutSec=${agent.bashTimeoutSec}`, `- contextMode:${agent.contextMode},memory:${agent.memory}`);
|
|
280
284
|
}
|
|
281
285
|
else {
|
|
282
286
|
lines.push(`- command:\`${agent.command ?? ""}\`${agent.shell ? "(通过 shell 执行)" : ""}`, `- maxWallTimeSec:${agent.maxWallTimeSec}`);
|
|
283
|
-
|
|
284
|
-
|
|
287
|
+
lines.push(`- model:${agent.externalModelRef ?? "CLI 决定"}`);
|
|
288
|
+
lines.push(`- thinking:${agent.thinkingLevel ?? "未设置(verify 派发默认 medium)"}`);
|
|
285
289
|
// spec 042 D4: contextMode/memory are effective for external roles too (memory 默认 none,
|
|
286
290
|
// 显式声明 session/relevant 才会把频道会话状态发给外部进程) — 显示出来而不是只在内置分支里说明。
|
|
287
291
|
lines.push(`- contextMode:${agent.contextMode},memory:${agent.memory}`);
|
|
@@ -361,3 +365,23 @@ export async function handleSubagentsCommand(options) {
|
|
|
361
365
|
return `执行 /subagents ${command.action} 失败:${errorMessage(error)}`;
|
|
362
366
|
}
|
|
363
367
|
}
|
|
368
|
+
/**
|
|
369
|
+
* Render a `RunNotice` (P0-1/P1a) as a one-line reply — a confirmation, per the command reply
|
|
370
|
+
* conventions. `notices: "off"` is enforced by the caller not invoking this at all; a `"settled"`
|
|
371
|
+
* caller filters `kind: "progress"` out before calling. Returns `undefined` for a notice with
|
|
372
|
+
* nothing worth showing (a progress step that never resolved to a label).
|
|
373
|
+
*/
|
|
374
|
+
export function renderRunNotice(notice) {
|
|
375
|
+
if (notice.kind === "progress") {
|
|
376
|
+
return notice.step ? `⏳ ${notice.agent} · ${notice.step}` : undefined;
|
|
377
|
+
}
|
|
378
|
+
const durationText = formatDuration(notice.durationMs);
|
|
379
|
+
switch (notice.status) {
|
|
380
|
+
case "completed":
|
|
381
|
+
return `✅ ${notice.agent} 完成 · ${durationText}`;
|
|
382
|
+
case "cancelled":
|
|
383
|
+
return `🛑 ${notice.agent} 已取消 · ${durationText}`;
|
|
384
|
+
default:
|
|
385
|
+
return `⚠️ ${notice.agent} 失败 · ${durationText}`;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
@@ -6,7 +6,7 @@ import { channelJobTaskIds } from "../agent/job-manager.js";
|
|
|
6
6
|
import { capReply } from "../agent/reply-limits.js";
|
|
7
7
|
import { formatLocalTime, parseLocalTime, parseWakeInput } from "../shared/local-time.js";
|
|
8
8
|
import { errorMessage } from "../shared/text-utils.js";
|
|
9
|
-
import { channelDelegationTaskIds } from "../subagents/runs.js";
|
|
9
|
+
import { channelDelegationTaskIds, getSubAgentRunManager } from "../subagents/runs.js";
|
|
10
10
|
import { applyTaskControlPatch, createDefaultTaskControl, taskBudgetViolation } from "../tasks/control.js";
|
|
11
11
|
import { countTaskDodItems, extractTaskTitle, missingStandardTaskSections, normalizeTaskId, readActiveTasks, recurringTaskMissedOccurrence, } from "../tasks/ledger.js";
|
|
12
12
|
import { withTaskMutation } from "../tasks/mutation-lock.js";
|
|
@@ -425,8 +425,13 @@ async function doctor(options) {
|
|
|
425
425
|
issues.push(issue(`tasks/${entry.id}.md 超出了它的 control 限额:${violation}`, `检查这个任务,明确提高 budget/deadline 或取消它;否则 driver 会升级处理`));
|
|
426
426
|
}
|
|
427
427
|
if (status !== "sleeping" && control.verification.status === "passed") {
|
|
428
|
+
const verificationRun = control.verification.runId && options.channelId
|
|
429
|
+
? getSubAgentRunManager(options.channelId).get(control.verification.runId)
|
|
430
|
+
: undefined;
|
|
428
431
|
const attestationOk = control.verification.runId
|
|
429
|
-
? await readVerificationAttestation(options.channelDir, control.verification.runId
|
|
432
|
+
? await readVerificationAttestation(options.channelDir, control.verification.runId, {
|
|
433
|
+
trustedWorkingDirectory: verificationRun?.workingDirectory,
|
|
434
|
+
})
|
|
430
435
|
.then((attestation) => attestation.taskId === entry.id &&
|
|
431
436
|
attestation.verdict === "pass" &&
|
|
432
437
|
(!storedTask || attestation.bodyHash === taskBodyHash(storedTask.body)))
|
|
@@ -21,8 +21,8 @@ export declare function isVerifiedJobWake(jobs: JobSnapshot[], jobId: string, ta
|
|
|
21
21
|
/**
|
|
22
22
|
* Same check as `isVerifiedJobWake`, for a `[SUBAGENT:<runId>] ... belongs to task <taskId>.`
|
|
23
23
|
* delegation wake. `settledAt` (rather than `status !== "running"`) is the terminal marker here
|
|
24
|
-
* because it is the
|
|
25
|
-
*
|
|
24
|
+
* because it is published with the terminal record before usage/archive/wake side effects — the
|
|
25
|
+
* same idempotency guard the manager itself relies on. A pending settlement intent leaves it unset.
|
|
26
26
|
*/
|
|
27
27
|
export declare function isVerifiedDelegationWake(record: RunRecord | undefined, taskId: string): boolean;
|
|
28
28
|
/** Plain wake text is untrusted. Only an event carrying the producer-created structured envelope
|
|
@@ -34,6 +34,9 @@ export declare function isTrustedInternalWake(event: ChannelEvent, kind: "job" |
|
|
|
34
34
|
export interface ClaimedDelegationWake {
|
|
35
35
|
taskId: string;
|
|
36
36
|
activated: boolean;
|
|
37
|
+
/** True when it is safe to drop this wake without a turn even though it did not activate the
|
|
38
|
+
* task itself — see `isTaskActivelyDriven`. Always true when `activated` is true. */
|
|
39
|
+
taskStillDriven: boolean;
|
|
37
40
|
finish(): Promise<void>;
|
|
38
41
|
rollback(): Promise<void>;
|
|
39
42
|
}
|
|
@@ -44,6 +47,8 @@ export declare function claimVerifiedDelegationWake(event: ChannelEvent, workspa
|
|
|
44
47
|
export interface ClaimedJobWake {
|
|
45
48
|
taskId: string;
|
|
46
49
|
activated: boolean;
|
|
50
|
+
/** See `ClaimedDelegationWake.taskStillDriven`. */
|
|
51
|
+
taskStillDriven: boolean;
|
|
47
52
|
finish(): Promise<void>;
|
|
48
53
|
}
|
|
49
54
|
/** Same shape as `claimVerifiedDelegationWake`, for a `[JOB:<jobId>] ... belongs to task
|
|
@@ -6,8 +6,23 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { getChannelJobManager } from "../agent/job-manager.js";
|
|
8
8
|
import { getSubAgentRunManager } from "../subagents/runs.js";
|
|
9
|
-
import { activateWaitingTask, rollbackWaitingTask } from "../tasks/store.js";
|
|
9
|
+
import { activateWaitingTask, readStoredTask, rollbackWaitingTask, } from "../tasks/store.js";
|
|
10
|
+
import { normalizeStoredStatus } from "../tasks/transitions.js";
|
|
10
11
|
import { getChannelDir } from "./channel-paths.js";
|
|
12
|
+
/**
|
|
13
|
+
* True when `taskId` is currently `active` and enabled — i.e. the task driver already owns
|
|
14
|
+
* advancing it. A completion wake that could not activate the task (because it was not
|
|
15
|
+
* `waiting`) is safe to drop without spending an agent turn only in this case: some other wake in
|
|
16
|
+
* the same fan-out already activated it, and the driver will pick up the result. Every other case
|
|
17
|
+
* — `done`, archived, disabled, or the task missing entirely — has nobody left to look at the
|
|
18
|
+
* wake's result if it is dropped here, so the caller must still route it to a normal turn.
|
|
19
|
+
*/
|
|
20
|
+
async function isTaskActivelyDriven(channelDir, taskId) {
|
|
21
|
+
const document = await readStoredTask(channelDir, taskId, false, true).catch(() => undefined);
|
|
22
|
+
return (document !== undefined &&
|
|
23
|
+
normalizeStoredStatus(document.fields.status) === "active" &&
|
|
24
|
+
document.fields.enabled !== false);
|
|
25
|
+
}
|
|
11
26
|
/**
|
|
12
27
|
* Whether a `[JOB:<jobId>] ... belongs to task <taskId>.` wake actually names a job that: exists
|
|
13
28
|
* on this channel, has actually finished (a still-`running` job cannot have produced this wake —
|
|
@@ -23,8 +38,8 @@ export function isVerifiedJobWake(jobs, jobId, taskId) {
|
|
|
23
38
|
/**
|
|
24
39
|
* Same check as `isVerifiedJobWake`, for a `[SUBAGENT:<runId>] ... belongs to task <taskId>.`
|
|
25
40
|
* delegation wake. `settledAt` (rather than `status !== "running"`) is the terminal marker here
|
|
26
|
-
* because it is the
|
|
27
|
-
*
|
|
41
|
+
* because it is published with the terminal record before usage/archive/wake side effects — the
|
|
42
|
+
* same idempotency guard the manager itself relies on. A pending settlement intent leaves it unset.
|
|
28
43
|
*/
|
|
29
44
|
export function isVerifiedDelegationWake(record, taskId) {
|
|
30
45
|
return record !== undefined && record.settledAt !== undefined && record.taskId === taskId;
|
|
@@ -56,9 +71,11 @@ export async function claimVerifiedDelegationWake(event, workspaceDir, hooks) {
|
|
|
56
71
|
}
|
|
57
72
|
const channelDir = getChannelDir(workspaceDir, event.channelId);
|
|
58
73
|
const activated = await activateWaitingTask(channelDir, wake.taskId, hooks);
|
|
74
|
+
const taskStillDriven = activated !== undefined || (await isTaskActivelyDriven(channelDir, wake.taskId));
|
|
59
75
|
return {
|
|
60
76
|
taskId: wake.taskId,
|
|
61
77
|
activated: activated !== undefined,
|
|
78
|
+
taskStillDriven,
|
|
62
79
|
finish: async () => {
|
|
63
80
|
await runManager.finishWakeConsumption(wake.resourceId, event.dispatchId);
|
|
64
81
|
},
|
|
@@ -81,9 +98,11 @@ export async function claimVerifiedJobWake(event, workspaceDir, executor, hooks)
|
|
|
81
98
|
}
|
|
82
99
|
const channelDir = getChannelDir(workspaceDir, event.channelId);
|
|
83
100
|
const activated = await activateWaitingTask(channelDir, wake.taskId, hooks);
|
|
101
|
+
const taskStillDriven = activated !== undefined || (await isTaskActivelyDriven(channelDir, wake.taskId));
|
|
84
102
|
return {
|
|
85
103
|
taskId: wake.taskId,
|
|
86
104
|
activated: activated !== undefined,
|
|
105
|
+
taskStillDriven,
|
|
87
106
|
finish: async () => {
|
|
88
107
|
await jobManager.finishWakeConsumption(wake.resourceId, event.dispatchId);
|
|
89
108
|
},
|
package/dist/settings.d.ts
CHANGED
|
@@ -71,6 +71,16 @@ export interface PipiclawSessionSearchSettings {
|
|
|
71
71
|
summarizeWithModel: boolean;
|
|
72
72
|
timeoutMs: number;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* How much out-of-band commentary a delegation run (`src/subagents/`) or background job produces
|
|
76
|
+
* outside of its own completion wake — plain text, not an LLM turn, so it reaches the channel in
|
|
77
|
+
* roughly the time the run itself takes rather than waiting on a wake turn's latency.
|
|
78
|
+
* `"off"` is today's behavior; `"settled"` adds only the one-line completion receipt; `"live"`
|
|
79
|
+
* also adds a sparse trickle of running-progress notices for long external runs.
|
|
80
|
+
*/
|
|
81
|
+
export interface PipiclawDelegationSettings {
|
|
82
|
+
notices: "off" | "settled" | "live";
|
|
83
|
+
}
|
|
74
84
|
/**
|
|
75
85
|
* Everything `settings.json` may contain (spec 035 D1).
|
|
76
86
|
*
|
|
@@ -120,6 +130,7 @@ export interface PipiclawSettings {
|
|
|
120
130
|
};
|
|
121
131
|
};
|
|
122
132
|
tui?: Partial<PipiclawTuiSettings>;
|
|
133
|
+
delegation?: Partial<PipiclawDelegationSettings>;
|
|
123
134
|
}
|
|
124
135
|
export interface PipiclawTuiSettings {
|
|
125
136
|
/**
|
|
@@ -168,6 +179,7 @@ export declare class PipiclawSettingsManager {
|
|
|
168
179
|
getSessionSearchSettings(): PipiclawSessionSearchSettings;
|
|
169
180
|
getLoggingSettings(): PipiclawLoggingSettings;
|
|
170
181
|
getTuiSettings(): PipiclawTuiSettings;
|
|
182
|
+
getDelegationSettings(): PipiclawDelegationSettings;
|
|
171
183
|
getRetryEnabled(): boolean;
|
|
172
184
|
setRetryEnabled(enabled: boolean): void;
|
|
173
185
|
/**
|
package/dist/settings.js
CHANGED
|
@@ -15,6 +15,9 @@ import { fileStamp } from "./shared/file-stamp.js";
|
|
|
15
15
|
const DEFAULT_TUI = {
|
|
16
16
|
responseMode: "full_progress_then_plain_final",
|
|
17
17
|
};
|
|
18
|
+
const DEFAULT_DELEGATION = {
|
|
19
|
+
notices: "live",
|
|
20
|
+
};
|
|
18
21
|
const DEFAULT_COMPACTION = {
|
|
19
22
|
enabled: true,
|
|
20
23
|
reserveTokens: 16384,
|
|
@@ -284,6 +287,12 @@ export class PipiclawSettingsManager {
|
|
|
284
287
|
getTuiSettings() {
|
|
285
288
|
return { ...DEFAULT_TUI, ...this.settings.tui };
|
|
286
289
|
}
|
|
290
|
+
getDelegationSettings() {
|
|
291
|
+
return {
|
|
292
|
+
...DEFAULT_DELEGATION,
|
|
293
|
+
notices: this.settings.delegation?.notices ?? DEFAULT_DELEGATION.notices,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
287
296
|
getRetryEnabled() {
|
|
288
297
|
return this.settings.retry?.enabled ?? DEFAULT_RETRY.enabled;
|
|
289
298
|
}
|
|
@@ -193,4 +193,24 @@ export const claudeCodeHarness = {
|
|
|
193
193
|
errorMessage,
|
|
194
194
|
};
|
|
195
195
|
},
|
|
196
|
+
// P1a: the first tool_use block in a streamed assistant message names the step currently
|
|
197
|
+
// running. Text-only assistant messages (reasoning, the final answer) have nothing to show.
|
|
198
|
+
toProgressLabel(line) {
|
|
199
|
+
let event;
|
|
200
|
+
try {
|
|
201
|
+
event = JSON.parse(line.trim());
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
if (!isRecord(event) || event.type !== "assistant" || !isRecord(event.message))
|
|
207
|
+
return undefined;
|
|
208
|
+
const parts = Array.isArray(event.message.content) ? event.message.content : [];
|
|
209
|
+
for (const part of parts) {
|
|
210
|
+
if (isRecord(part) && part.type === "tool_use" && typeof part.name === "string") {
|
|
211
|
+
return part.name;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return undefined;
|
|
215
|
+
},
|
|
196
216
|
};
|