@oyasmi/pipiclaw 0.9.0-beta.7 → 0.9.0-beta.9
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 +1 -0
- package/dist/agent/channel-runner.js +21 -2
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/agent/job-manager.d.ts +3 -3
- package/dist/agent/job-manager.js +0 -1
- package/dist/agent/runner-factory.d.ts +16 -4
- package/dist/agent/runner-factory.js +9 -23
- package/dist/agent/types.d.ts +9 -1
- package/dist/agent/types.js +3 -16
- 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/playbooks/agent-delegation.md +2 -2
- package/dist/runtime/bootstrap.d.ts +10 -2
- package/dist/runtime/bootstrap.js +83 -55
- 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/dingtalk.d.ts +9 -31
- package/dist/runtime/durable-dispatch.d.ts +4 -2
- package/dist/runtime/durable-dispatch.js +36 -25
- package/dist/runtime/events.d.ts +3 -2
- package/dist/runtime/events.js +2 -3
- package/dist/runtime/subagent-commands.js +48 -10
- package/dist/runtime/task-commands.js +2 -2
- 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 +4 -4
- package/dist/settings.d.ts +0 -106
- package/dist/settings.js +0 -224
- package/dist/shared/host-process.d.ts +25 -9
- package/dist/shared/host-process.js +59 -10
- package/dist/shared/types.d.ts +1 -0
- package/dist/shared/types.js +10 -1
- package/dist/subagents/discovery.d.ts +24 -0
- package/dist/subagents/discovery.js +103 -17
- package/dist/subagents/external/claude-code.js +10 -3
- package/dist/subagents/external/codex-cli.js +9 -3
- package/dist/subagents/external/exec.js +1 -0
- package/dist/subagents/external/harness.d.ts +22 -0
- package/dist/subagents/external/harness.js +22 -4
- package/dist/subagents/external/run.d.ts +23 -3
- package/dist/subagents/external/run.js +112 -131
- package/dist/subagents/external/settlement.d.ts +50 -0
- package/dist/subagents/external/settlement.js +123 -0
- package/dist/subagents/format.d.ts +4 -0
- package/dist/subagents/format.js +7 -0
- package/dist/subagents/runs.d.ts +73 -16
- package/dist/subagents/runs.js +197 -120
- package/dist/subagents/tool.d.ts +38 -6
- package/dist/subagents/tool.js +93 -61
- package/dist/subagents/verification-outcome.d.ts +26 -0
- package/dist/subagents/verification-outcome.js +16 -0
- package/dist/subagents/workspace-lease.d.ts +10 -1
- package/dist/subagents/workspace-lease.js +15 -2
- package/dist/tasks/ledger.js +1 -1
- package/dist/{shared → tasks}/task-schedule.js +1 -1
- package/dist/tools/bash.js +1 -1
- package/dist/tools/event-manage.js +1 -4
- package/dist/tools/grep.js +2 -3
- package/dist/tools/index.js +6 -0
- package/dist/tools/job.js +5 -5
- package/dist/tools/memory-manage.js +3 -6
- package/dist/tools/session-search.js +0 -1
- package/dist/tools/skill-manage.js +3 -3
- package/dist/tools/subagent-manage.d.ts +20 -6
- package/dist/tools/subagent-manage.js +88 -18
- package/dist/tools/task-manage/shared.js +2 -2
- package/dist/tools/task-manage.js +1 -4
- package/dist/tools/web-fetch.js +0 -1
- package/dist/tui/app.js +4 -4
- package/package.json +1 -1
- /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;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type RuntimeCommandName } from "../agent/commands.js";
|
|
2
2
|
import type { FinalDelivery, MediaSender, MediaSendResult, OutboundMedia, ProgressStyle } from "./channel-context.js";
|
|
3
|
+
import type { ChannelEvent } from "./channel-event.js";
|
|
3
4
|
import type { ChannelObservation } from "./channel-index.js";
|
|
4
5
|
export type BusyMessageMode = "steer" | "followUp";
|
|
5
6
|
export type BusyMessageDefaultConfig = BusyMessageMode | "followup";
|
|
@@ -22,37 +23,14 @@ export interface DingTalkConfig {
|
|
|
22
23
|
responseMode?: ResponseMode;
|
|
23
24
|
cardAutoLayout?: boolean;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
conversationType: string;
|
|
34
|
-
/**
|
|
35
|
-
* Human-readable channel name: the group title, or the peer's nickname for a DM. Absent on
|
|
36
|
-
* synthetic events (scheduled events, task-driver wakes), which carry no conversation payload.
|
|
37
|
-
*/
|
|
38
|
-
channelName?: string;
|
|
39
|
-
/** Runtime-owned durable-dispatch record, absent for normal inbound messages. */
|
|
40
|
-
dispatchId?: string;
|
|
41
|
-
/** Structured wake provenance created only by in-process producers. DingTalk inbound parsing
|
|
42
|
-
* never copies arbitrary payload fields into this event, so user text cannot manufacture it. */
|
|
43
|
-
internalWake?: {
|
|
44
|
-
kind: "job" | "subagent";
|
|
45
|
-
resourceId: string;
|
|
46
|
-
taskId: string;
|
|
47
|
-
dispatchId: string;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* The `attemptGeneration` this event's claim recorded, for `[TASK_DRIVER:id]` events only.
|
|
51
|
-
* Carried through durable dispatch so `finishTaskAttempt` can tell a stale, superseded claim's
|
|
52
|
-
* turn from the current one, even when redelivery or claim races reorder completions.
|
|
53
|
-
*/
|
|
54
|
-
taskAttemptGeneration?: number;
|
|
55
|
-
}
|
|
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;
|
|
56
34
|
export type BusyMessageResult = {
|
|
57
35
|
kind: "handled";
|
|
58
36
|
} | {
|
|
@@ -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,7 +30,7 @@ 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>;
|
|
@@ -39,6 +40,7 @@ export declare class DurableDispatchService {
|
|
|
39
40
|
* can retry the same dispatch id instead of losing the only completion signal. */
|
|
40
41
|
markRetryable(id: string | undefined): Promise<void>;
|
|
41
42
|
drainOnce(now?: number): Promise<void>;
|
|
43
|
+
private drainRecord;
|
|
42
44
|
private read;
|
|
43
45
|
private write;
|
|
44
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
|
}
|
|
@@ -186,32 +188,41 @@ export class DurableDispatchService {
|
|
|
186
188
|
}
|
|
187
189
|
for (const filename of filenames) {
|
|
188
190
|
const id = filename.slice(0, -".json".length);
|
|
189
|
-
await this.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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) {
|
|
196
207
|
record.leaseExpiresAt = new Date(now + this.leaseMs).toISOString();
|
|
197
208
|
await this.write(record);
|
|
198
|
-
return;
|
|
199
209
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
+
});
|
|
215
226
|
}
|
|
216
227
|
async read(id) {
|
|
217
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
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { errorMessage } from "../shared/text-utils.js";
|
|
4
|
-
import {
|
|
4
|
+
import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format.js";
|
|
5
5
|
import { getSubAgentRunManager } from "../subagents/runs.js";
|
|
6
6
|
function usage() {
|
|
7
7
|
return `# 委派 Run
|
|
@@ -69,7 +69,7 @@ function statusLabel(status) {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
function formatRunLine(record) {
|
|
72
|
-
const bits = [harnessLabel(record),
|
|
72
|
+
const bits = [harnessLabel(record), formatRunDuration(record)];
|
|
73
73
|
if (record.taskId)
|
|
74
74
|
bits.push(`task ${record.taskId}`);
|
|
75
75
|
if (record.leaseKey)
|
|
@@ -108,6 +108,18 @@ function formatRolesTail(discovery) {
|
|
|
108
108
|
return line;
|
|
109
109
|
}
|
|
110
110
|
const DEFAULT_LIST_COMPLETED_LIMIT = 5;
|
|
111
|
+
/** Spec 042 D9: `running`/`failed`/`all` had no cap at all — a long-lived channel with thousands
|
|
112
|
+
* of historical runs (GC now reclaims them after 7 days, but that is still a lot in a busy week)
|
|
113
|
+
* would otherwise dump an unbounded list into a single reply. */
|
|
114
|
+
const LIST_FILTER_CAP = 50;
|
|
115
|
+
function capListForDisplay(records) {
|
|
116
|
+
if (records.length <= LIST_FILTER_CAP)
|
|
117
|
+
return { shown: records };
|
|
118
|
+
return {
|
|
119
|
+
shown: records.slice(0, LIST_FILTER_CAP),
|
|
120
|
+
truncatedNote: `显示最近 ${LIST_FILTER_CAP} 条,共 ${records.length} 条——用更具体的筛选缩小范围。`,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
111
123
|
async function listRuns(options, filter) {
|
|
112
124
|
const records = getSubAgentRunManager(options.channelId).list();
|
|
113
125
|
if (records.length === 0)
|
|
@@ -118,17 +130,25 @@ async function listRuns(options, filter) {
|
|
|
118
130
|
.sort((a, b) => (b.finishedAt ?? b.startedAt) - (a.finishedAt ?? a.startedAt));
|
|
119
131
|
const sections = [];
|
|
120
132
|
if (filter === "running") {
|
|
121
|
-
|
|
122
|
-
|
|
133
|
+
const { shown, truncatedNote } = capListForDisplay(running);
|
|
134
|
+
sections.push(shown.length === 0 ? "没有正在运行的 run。" : shown.map(formatRunLine).join("\n"));
|
|
135
|
+
if (truncatedNote)
|
|
136
|
+
sections.push(truncatedNote);
|
|
137
|
+
return `# 委派 Run — 运行中\n\n${sections.join("\n\n")}`;
|
|
123
138
|
}
|
|
124
139
|
if (filter === "failed") {
|
|
125
|
-
const
|
|
126
|
-
sections.push(
|
|
127
|
-
|
|
140
|
+
const { shown, truncatedNote } = capListForDisplay(terminal.filter((record) => record.status === "failed"));
|
|
141
|
+
sections.push(shown.length === 0 ? "没有失败的 run。" : shown.map(formatRunLine).join("\n"));
|
|
142
|
+
if (truncatedNote)
|
|
143
|
+
sections.push(truncatedNote);
|
|
144
|
+
return `# 委派 Run — 失败\n\n${sections.join("\n\n")}`;
|
|
128
145
|
}
|
|
129
146
|
if (filter === "all") {
|
|
130
|
-
|
|
131
|
-
|
|
147
|
+
const { shown, truncatedNote } = capListForDisplay([...running, ...terminal]);
|
|
148
|
+
sections.push(shown.map(formatRunLine).join("\n"));
|
|
149
|
+
if (truncatedNote)
|
|
150
|
+
sections.push(truncatedNote);
|
|
151
|
+
return `# 委派 Run — 全部(${records.length})\n\n${sections.join("\n\n")}`;
|
|
132
152
|
}
|
|
133
153
|
// default: an overview — every running run, plus a capped tail of recent completions.
|
|
134
154
|
if (running.length > 0) {
|
|
@@ -169,7 +189,7 @@ async function showRun(channelId, ref) {
|
|
|
169
189
|
"",
|
|
170
190
|
`角色:${record.agent} (${harnessLabel(record)}, ${record.source})`,
|
|
171
191
|
`标签:${record.label}`,
|
|
172
|
-
`状态:${statusLabel(record.status)}(耗时 ${
|
|
192
|
+
`状态:${statusLabel(record.status)}(耗时 ${formatRunDuration(record)})`,
|
|
173
193
|
];
|
|
174
194
|
if (record.failureReason)
|
|
175
195
|
lines.push(`失败原因:${record.failureReason}`);
|
|
@@ -190,6 +210,18 @@ async function showRun(channelId, ref) {
|
|
|
190
210
|
lines.push(`usage:input=${record.usage.input} output=${record.usage.output}${cost ? ` cost=${cost}` : record.costKnown ? "" : "(cost 未知)"}`);
|
|
191
211
|
if (record.argv)
|
|
192
212
|
lines.push("", "实际 argv:", "```", JSON.stringify(record.argv), "```");
|
|
213
|
+
if (record.parserVersion !== undefined || record.cliVersion) {
|
|
214
|
+
// Spec 042 D12: lets a human tell "the target CLI's own protocol drifted out from under this
|
|
215
|
+
// adapter" apart from "the agent itself failed" — the two look identical from status alone.
|
|
216
|
+
const parts = [];
|
|
217
|
+
if (record.parserVersion !== undefined)
|
|
218
|
+
parts.push(`parserVersion=${record.parserVersion}`);
|
|
219
|
+
parts.push(`cliVersion=${record.cliVersion ?? "(未知)"}`);
|
|
220
|
+
lines.push(`适配器/CLI:${parts.join(",")}`);
|
|
221
|
+
}
|
|
222
|
+
if (record.invocationWarnings?.length) {
|
|
223
|
+
lines.push("", "⚠ 派发时的警告:", ...record.invocationWarnings.map((warning) => `- ${warning}`));
|
|
224
|
+
}
|
|
193
225
|
if (record.sessionId)
|
|
194
226
|
lines.push(`sessionId:\`${record.sessionId}\`(可用于 subagent_manage op=follow_up)`);
|
|
195
227
|
if (record.runtime === "external") {
|
|
@@ -261,6 +293,12 @@ function formatRoleDetail(agent) {
|
|
|
261
293
|
lines.push(`command:\`${agent.command ?? ""}\`${agent.shell ? "(通过 shell 执行)" : ""}`, `maxWallTimeSec:${agent.maxWallTimeSec}`);
|
|
262
294
|
if (agent.externalModelRef)
|
|
263
295
|
lines.push(`模型:${agent.externalModelRef}`);
|
|
296
|
+
// spec 042 D4: contextMode/memory are effective for external roles too (memory 默认 none,
|
|
297
|
+
// 显式声明 session/relevant 才会把频道会话状态发给外部进程) — 显示出来而不是只在内置分支里说明。
|
|
298
|
+
lines.push(`contextMode:${agent.contextMode},memory:${agent.memory}`);
|
|
299
|
+
if (agent.memory !== "none") {
|
|
300
|
+
lines.push(`⚠ 该角色会把频道会话状态/记忆片段发送给外部进程(memory: ${agent.memory})`);
|
|
301
|
+
}
|
|
264
302
|
}
|
|
265
303
|
if (agent.paths.length > 0)
|
|
266
304
|
lines.push(`paths:${agent.paths.join(", ")}`);
|
|
@@ -3,8 +3,6 @@ import { readdir, readFile } from "node:fs/promises";
|
|
|
3
3
|
import { join, resolve, sep } from "node:path";
|
|
4
4
|
import { channelJobTaskIds } from "../agent/job-manager.js";
|
|
5
5
|
import { formatLocalTime, parseLocalTime, parseWakeInput } from "../shared/local-time.js";
|
|
6
|
-
import { parseTaskEventName, taskEventPrefix } from "../shared/task-events.js";
|
|
7
|
-
import { nextTaskWake, validateTaskSchedule } from "../shared/task-schedule.js";
|
|
8
6
|
import { errorMessage } from "../shared/text-utils.js";
|
|
9
7
|
import { isRecord } from "../shared/type-guards.js";
|
|
10
8
|
import { channelDelegationTaskIds } from "../subagents/runs.js";
|
|
@@ -12,6 +10,8 @@ import { applyTaskControlPatch, createDefaultTaskControl, retiredTaskControlKeys
|
|
|
12
10
|
import { countTaskDodItems, extractTaskTitle, isTaskParked, missingStandardTaskSections, normalizeTaskId, readActiveTasks, recurringTaskMissedOccurrence, } from "../tasks/ledger.js";
|
|
13
11
|
import { withTaskMutation } from "../tasks/mutation-lock.js";
|
|
14
12
|
import { claimTaskAttempt, openRecurringTaskCycle, readStoredTask, releaseTaskAttemptClaim, taskBodyHash, writeStoredTask, } from "../tasks/store.js";
|
|
13
|
+
import { parseTaskEventName, taskEventPrefix } from "../tasks/task-events.js";
|
|
14
|
+
import { nextTaskWake, validateTaskSchedule } from "../tasks/task-schedule.js";
|
|
15
15
|
import { normalizeStoredStatus, resolveTaskTransition } from "../tasks/transitions.js";
|
|
16
16
|
import { readVerificationAttestation } from "../tasks/verification.js";
|
|
17
17
|
import { parseScheduledEventContent } from "./events.js";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { PipiclawTaskDriverSettings } from "../settings.js";
|
|
2
2
|
import { type TaskLedgerEntry } from "../tasks/ledger.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ChannelEvent } from "./channel-event.js";
|
|
4
4
|
export interface TaskDriverOptions {
|
|
5
5
|
workspaceDir: string;
|
|
6
6
|
getKnownChannelIds?: () => Iterable<string>;
|
|
7
7
|
isChannelActive: (channelId: string) => boolean;
|
|
8
|
-
dispatch: (event:
|
|
8
|
+
dispatch: (event: ChannelEvent) => boolean | Promise<boolean>;
|
|
9
9
|
/** Optional observability hook. It runs after every production dispatch attempt. */
|
|
10
|
-
onDispatch?: (event:
|
|
10
|
+
onDispatch?: (event: ChannelEvent, accepted: boolean) => void;
|
|
11
11
|
getSettings: () => PipiclawTaskDriverSettings;
|
|
12
12
|
/**
|
|
13
13
|
* Externally visible effects produced by this task's own turns so far (spec 031, D7).
|
|
@@ -19,13 +19,13 @@ export interface TaskDriverOptions {
|
|
|
19
19
|
/** Test-only override for the idle-sleep cap; production uses `settings.maxSleepMinutes`. */
|
|
20
20
|
intervalMs?: number;
|
|
21
21
|
/** Direct, non-LLM receipt for deterministic governor stops. */
|
|
22
|
-
notify?: (event:
|
|
22
|
+
notify?: (event: ChannelEvent) => boolean | Promise<boolean>;
|
|
23
23
|
}
|
|
24
24
|
export declare function discoverTaskChannels(workspaceDir: string, knownChannelIds?: Iterable<string>): Promise<string[]>;
|
|
25
|
-
export declare function createTaskDriverEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number, attemptGeneration?: number):
|
|
25
|
+
export declare function createTaskDriverEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number, attemptGeneration?: number): ChannelEvent;
|
|
26
26
|
/** Durable checker wake created by request-verification; it is a normal main-agent turn. */
|
|
27
|
-
export declare function createTaskVerificationEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number):
|
|
28
|
-
export declare function taskGovernorReceipt(channelId: string, entry: TaskLedgerEntry, reason: string, nowMs: number):
|
|
27
|
+
export declare function createTaskVerificationEvent(channelId: string, entry: TaskLedgerEntry, nowMs: number): ChannelEvent;
|
|
28
|
+
export declare function taskGovernorReceipt(channelId: string, entry: TaskLedgerEntry, reason: string, nowMs: number): ChannelEvent;
|
|
29
29
|
/**
|
|
30
30
|
* Native, token-gated driver for the persistent task ledger.
|
|
31
31
|
*
|
|
@@ -3,11 +3,11 @@ import { join } from "node:path";
|
|
|
3
3
|
import * as log from "../log.js";
|
|
4
4
|
import { PLAYBOOKS_DIR } from "../paths.js";
|
|
5
5
|
import { parseLocalTime } from "../shared/local-time.js";
|
|
6
|
-
import { nextTaskWake } from "../shared/task-schedule.js";
|
|
7
6
|
import { errorMessage } from "../shared/text-utils.js";
|
|
8
7
|
import { taskBudgetViolation } from "../tasks/control.js";
|
|
9
8
|
import { normalizeTaskFields, readActiveTasks, recurringTaskMissedOccurrence, } from "../tasks/ledger.js";
|
|
10
9
|
import { activateWaitingTask, claimTaskAttempt, escalateTask, openRecurringTaskCycle, releaseTaskAttemptClaim, updateStoredTask, } from "../tasks/store.js";
|
|
10
|
+
import { nextTaskWake } from "../tasks/task-schedule.js";
|
|
11
11
|
import { discoverWorkspaceChannelIds } from "./channel-index.js";
|
|
12
12
|
import { isChannelId } from "./channel-paths.js";
|
|
13
13
|
/** Short debounce so a burst of nudges collapses into a single rescan. */
|
|
@@ -146,7 +146,6 @@ export function createTaskDriverEvent(channelId, entry, nowMs, attemptGeneration
|
|
|
146
146
|
"For a recurring occurrence intentionally not run because it is duplicate or already satisfied, call task_manage skip with the reason, then respond with exactly [SILENT]. " +
|
|
147
147
|
"If no task state or tool action is needed and this wake produces no user-visible result, respond with exactly [SILENT].",
|
|
148
148
|
ts: String(nowMs),
|
|
149
|
-
conversationId: "",
|
|
150
149
|
conversationType: channelId.startsWith("group_") ? "2" : "1",
|
|
151
150
|
dispatchId: taskDispatchId(channelId, entry, nowMs),
|
|
152
151
|
taskAttemptGeneration: attemptGeneration,
|
|
@@ -165,7 +164,6 @@ export function createTaskVerificationEvent(channelId, entry, nowMs) {
|
|
|
165
164
|
`subagent with purpose=verify. Import its attestation with task_manage verify using the returned run id. ` +
|
|
166
165
|
`Do not modify the workspace or task contract; if verification fails, record the failure and leave the task recoverable.`,
|
|
167
166
|
ts: String(nowMs),
|
|
168
|
-
conversationId: "",
|
|
169
167
|
conversationType: channelId.startsWith("group_") ? "2" : "1",
|
|
170
168
|
dispatchId: `task:${channelId}:${entry.id}:verification:${control?.cycleId ?? `t${nowMs}`}`,
|
|
171
169
|
};
|
|
@@ -192,7 +190,6 @@ export function taskGovernorReceipt(channelId, entry, reason, nowMs) {
|
|
|
192
190
|
`当前阶段:${entry.frontmatter.status ?? "active"}${entry.frontmatter.control?.cycleId ? `;周期:${entry.frontmatter.control.cycleId}` : ""}\n` +
|
|
193
191
|
`继续:/tasks resume ${entry.id}\n立即执行:/tasks run ${entry.id}\n不再需要:让 Agent cancel 该任务。`,
|
|
194
192
|
ts: String(nowMs),
|
|
195
|
-
conversationId: "",
|
|
196
193
|
conversationType: channelId.startsWith("group_") ? "2" : "1",
|
|
197
194
|
// Keyed on the cause, not the moment: re-detecting the same violation before the user has
|
|
198
195
|
// acted must not queue a second identical escalation, while a different cause still does.
|
|
@@ -2,12 +2,12 @@ import { mkdir, readdir, readFile, rename, stat, unlink } from "node:fs/promises
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import * as log from "../log.js";
|
|
4
4
|
import { formatLocalTime } from "../shared/local-time.js";
|
|
5
|
-
import { parseTaskEventName, taskEventPrefix } from "../shared/task-events.js";
|
|
6
5
|
import { errorMessage } from "../shared/text-utils.js";
|
|
7
6
|
import { createDefaultTaskControl } from "../tasks/control.js";
|
|
8
7
|
import { appendCurrentCycleNote, parseTaskFrontmatter } from "../tasks/ledger.js";
|
|
9
8
|
import { withTaskMutation } from "../tasks/mutation-lock.js";
|
|
10
9
|
import { readStoredTask, updateStoredTask, writeStoredTask } from "../tasks/store.js";
|
|
10
|
+
import { parseTaskEventName, taskEventPrefix } from "../tasks/task-events.js";
|
|
11
11
|
import { parseScheduledEventContent } from "./events.js";
|
|
12
12
|
import { discoverTaskChannels } from "./task-driver.js";
|
|
13
13
|
/**
|
|
@@ -8,7 +8,7 @@ import { type JobSnapshot } from "../agent/job-manager.js";
|
|
|
8
8
|
import type { Executor } from "../executor.js";
|
|
9
9
|
import { type RunRecord } from "../subagents/runs.js";
|
|
10
10
|
import { type WakeTaskTransitionHooks } from "../tasks/store.js";
|
|
11
|
-
import type {
|
|
11
|
+
import type { ChannelEvent } from "./channel-event.js";
|
|
12
12
|
/**
|
|
13
13
|
* Whether a `[JOB:<jobId>] ... belongs to task <taskId>.` wake actually names a job that: exists
|
|
14
14
|
* on this channel, has actually finished (a still-`running` job cannot have produced this wake —
|
|
@@ -28,7 +28,7 @@ export declare function isVerifiedDelegationWake(record: RunRecord | undefined,
|
|
|
28
28
|
/** Plain wake text is untrusted. Only an event carrying the producer-created structured envelope
|
|
29
29
|
* and its exact durable dispatch id may enter task activation; normal DingTalk inbound events do
|
|
30
30
|
* not populate `internalWake`, so copying a real wake's text is insufficient. */
|
|
31
|
-
export declare function isTrustedInternalWake(event:
|
|
31
|
+
export declare function isTrustedInternalWake(event: ChannelEvent, kind: "job" | "subagent", resourceId: string, taskId: string): event is ChannelEvent & {
|
|
32
32
|
dispatchId: string;
|
|
33
33
|
};
|
|
34
34
|
export interface ClaimedDelegationWake {
|
|
@@ -41,7 +41,7 @@ export interface ClaimedDelegationWake {
|
|
|
41
41
|
/** Claim and activate a producer-created delegation wake without consuming it yet. Keeping the
|
|
42
42
|
* final marker separate lets transports such as TUI mark it consumed only after they have accepted
|
|
43
43
|
* the corresponding turn; a rejected submit remains replayable in the same or next process. */
|
|
44
|
-
export declare function claimVerifiedDelegationWake(event:
|
|
44
|
+
export declare function claimVerifiedDelegationWake(event: ChannelEvent, workspaceDir: string, hooks?: WakeTaskTransitionHooks): Promise<ClaimedDelegationWake | undefined>;
|
|
45
45
|
export interface ClaimedJobWake {
|
|
46
46
|
taskId: string;
|
|
47
47
|
generation?: number;
|
|
@@ -51,4 +51,4 @@ export interface ClaimedJobWake {
|
|
|
51
51
|
/** Same shape as `claimVerifiedDelegationWake`, for a `[JOB:<jobId>] ... belongs to task
|
|
52
52
|
* <taskId>.` completion wake. A background job has no handoff/rollback bookkeeping — its wake
|
|
53
53
|
* activation is a single unconditional step — so `ClaimedJobWake` omits `rollback`. */
|
|
54
|
-
export declare function claimVerifiedJobWake(event:
|
|
54
|
+
export declare function claimVerifiedJobWake(event: ChannelEvent, workspaceDir: string, executor: Executor, hooks?: WakeTaskTransitionHooks): Promise<ClaimedJobWake | undefined>;
|
package/dist/settings.d.ts
CHANGED
|
@@ -7,44 +7,13 @@
|
|
|
7
7
|
* This module currently provides only PipiclawSettingsManager.
|
|
8
8
|
*/
|
|
9
9
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
10
|
-
import type { Transport } from "@earendil-works/pi-ai";
|
|
11
10
|
import { type MemoryMaintenanceTuning } from "./memory/maintenance-tuning.js";
|
|
12
11
|
import type { ResponseMode } from "./runtime/dingtalk.js";
|
|
13
12
|
import type { ConfigDiagnostic } from "./shared/config-diagnostic.js";
|
|
14
|
-
type PackageSource = string | {
|
|
15
|
-
source: string;
|
|
16
|
-
extensions?: string[];
|
|
17
|
-
skills?: string[];
|
|
18
|
-
prompts?: string[];
|
|
19
|
-
themes?: string[];
|
|
20
|
-
};
|
|
21
|
-
type ThinkingBudgetsSettings = {
|
|
22
|
-
minimal?: number;
|
|
23
|
-
low?: number;
|
|
24
|
-
medium?: number;
|
|
25
|
-
high?: number;
|
|
26
|
-
};
|
|
27
|
-
type Settings = {
|
|
28
|
-
defaultProvider?: string;
|
|
29
|
-
defaultModel?: string;
|
|
30
|
-
defaultThinkingLevel?: ThinkingLevel;
|
|
31
|
-
compaction?: {
|
|
32
|
-
enabled?: boolean;
|
|
33
|
-
reserveTokens?: number;
|
|
34
|
-
keepRecentTokens?: number;
|
|
35
|
-
};
|
|
36
|
-
retry?: {
|
|
37
|
-
enabled?: boolean;
|
|
38
|
-
maxRetries?: number;
|
|
39
|
-
baseDelayMs?: number;
|
|
40
|
-
maxDelayMs?: number;
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
13
|
type SettingsError = {
|
|
44
14
|
scope: "global" | "project";
|
|
45
15
|
error: Error;
|
|
46
16
|
};
|
|
47
|
-
type TransportSetting = Transport;
|
|
48
17
|
export interface PipiclawCompactionSettings {
|
|
49
18
|
enabled: boolean;
|
|
50
19
|
reserveTokens: number;
|
|
@@ -216,80 +185,5 @@ export declare class PipiclawSettingsManager {
|
|
|
216
185
|
setDefaultModelAndProvider(provider: string, modelId: string): void;
|
|
217
186
|
getDefaultThinkingLevel(): ThinkingLevel | undefined;
|
|
218
187
|
setDefaultThinkingLevel(level: ThinkingLevel): void;
|
|
219
|
-
getSteeringMode(): "all" | "one-at-a-time";
|
|
220
|
-
setSteeringMode(_mode: "all" | "one-at-a-time"): void;
|
|
221
|
-
getFollowUpMode(): "all" | "one-at-a-time";
|
|
222
|
-
setFollowUpMode(_mode: "all" | "one-at-a-time"): void;
|
|
223
|
-
getHookPaths(): string[];
|
|
224
|
-
getHookTimeout(): number;
|
|
225
|
-
getImageAutoResize(): boolean;
|
|
226
|
-
setImageAutoResize(_enabled: boolean): void;
|
|
227
|
-
getBlockImages(): boolean;
|
|
228
|
-
setBlockImages(_blocked: boolean): void;
|
|
229
|
-
getShowImages(): boolean;
|
|
230
|
-
setShowImages(_show: boolean): void;
|
|
231
|
-
getBranchSummarySettings(): {
|
|
232
|
-
reserveTokens: number;
|
|
233
|
-
};
|
|
234
|
-
getBranchSummarySkipPrompt(): boolean;
|
|
235
|
-
getHideThinkingBlock(): boolean;
|
|
236
|
-
setHideThinkingBlock(_hide: boolean): void;
|
|
237
|
-
getThinkingBudgets(): ThinkingBudgetsSettings | undefined;
|
|
238
|
-
getShellPath(): string | undefined;
|
|
239
|
-
setShellPath(_path: string | undefined): void;
|
|
240
|
-
getShellCommandPrefix(): string | undefined;
|
|
241
|
-
setShellCommandPrefix(_prefix: string | undefined): void;
|
|
242
|
-
getQuietStartup(): boolean;
|
|
243
|
-
setQuietStartup(_quiet: boolean): void;
|
|
244
|
-
getCollapseChangelog(): boolean;
|
|
245
|
-
setCollapseChangelog(_collapse: boolean): void;
|
|
246
|
-
getTransport(): TransportSetting;
|
|
247
|
-
setTransport(_transport: TransportSetting): void;
|
|
248
|
-
getTheme(): string | undefined;
|
|
249
|
-
setTheme(_theme: string): void;
|
|
250
|
-
getPackages(): PackageSource[];
|
|
251
|
-
setPackages(_packages: PackageSource[]): void;
|
|
252
|
-
setProjectPackages(_packages: PackageSource[]): void;
|
|
253
|
-
getExtensionPaths(): string[];
|
|
254
|
-
setExtensionPaths(_paths: string[]): void;
|
|
255
|
-
setProjectExtensionPaths(_paths: string[]): void;
|
|
256
|
-
getSkillPaths(): string[];
|
|
257
|
-
setSkillPaths(_paths: string[]): void;
|
|
258
|
-
setProjectSkillPaths(_paths: string[]): void;
|
|
259
|
-
getPromptTemplatePaths(): string[];
|
|
260
|
-
setPromptTemplatePaths(_paths: string[]): void;
|
|
261
|
-
setProjectPromptTemplatePaths(_paths: string[]): void;
|
|
262
|
-
getThemePaths(): string[];
|
|
263
|
-
setThemePaths(_paths: string[]): void;
|
|
264
|
-
setProjectThemePaths(_paths: string[]): void;
|
|
265
|
-
getEnableSkillCommands(): boolean;
|
|
266
|
-
setEnableSkillCommands(_enabled: boolean): void;
|
|
267
|
-
getEnabledModels(): string[] | undefined;
|
|
268
|
-
setEnabledModels(_patterns: string[] | undefined): void;
|
|
269
|
-
getDoubleEscapeAction(): "none";
|
|
270
|
-
setDoubleEscapeAction(_action: "fork" | "tree" | "none"): void;
|
|
271
|
-
getTreeFilterMode(): "default" | "no-tools" | "user-only" | "labeled-only" | "all";
|
|
272
|
-
setTreeFilterMode(_mode: "default" | "no-tools" | "user-only" | "labeled-only" | "all"): void;
|
|
273
|
-
getShowHardwareCursor(): boolean;
|
|
274
|
-
setShowHardwareCursor(_enabled: boolean): void;
|
|
275
|
-
getClearOnShrink(): boolean;
|
|
276
|
-
setClearOnShrink(_enabled: boolean): void;
|
|
277
|
-
getEditorPaddingX(): number;
|
|
278
|
-
setEditorPaddingX(_padding: number): void;
|
|
279
|
-
getAutocompleteMaxVisible(): number;
|
|
280
|
-
setAutocompleteMaxVisible(_maxVisible: number): void;
|
|
281
|
-
getCodeBlockIndent(): string;
|
|
282
|
-
getLastChangelogVersion(): string | undefined;
|
|
283
|
-
setLastChangelogVersion(_version: string): void;
|
|
284
|
-
setDefaultProvider(_provider: string): void;
|
|
285
|
-
setDefaultModel(_modelId: string): void;
|
|
286
|
-
getSessionDir(): string | undefined;
|
|
287
|
-
getNpmCommand(): string[] | undefined;
|
|
288
|
-
setNpmCommand(_command: string[] | undefined): void;
|
|
289
|
-
getGlobalSettings(): Settings;
|
|
290
|
-
getProjectSettings(): Settings;
|
|
291
|
-
isProjectTrusted(): boolean;
|
|
292
|
-
setProjectTrusted(_trusted: boolean): void;
|
|
293
|
-
flush(): Promise<void>;
|
|
294
188
|
}
|
|
295
189
|
export {};
|