@oyasmi/pipiclaw 0.9.5-beta.2 → 0.9.5-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +9 -11
- package/README.md +9 -11
- package/dist/agent/channel-runner.d.ts +12 -24
- package/dist/agent/channel-runner.js +74 -30
- package/dist/agent/maintenance-context.d.ts +2 -0
- package/dist/agent/maintenance-context.js +15 -0
- package/dist/agent/prompt/sections.js +8 -6
- package/dist/agent/prompt/types.d.ts +1 -1
- package/dist/agent/runner-factory.js +1 -1
- package/dist/agent/session/command-extension.js +11 -0
- package/dist/agent/session/compaction-summary.js +6 -2
- package/dist/agent/session/execution-trace.d.ts +14 -0
- package/dist/agent/session/execution-trace.js +57 -0
- package/dist/agent/session/session-events.d.ts +2 -7
- package/dist/agent/session/session-events.js +35 -12
- package/dist/agent/session/session-host.d.ts +12 -22
- package/dist/agent/session/session-host.js +46 -65
- package/dist/agent/turn/task-digest.d.ts +1 -2
- package/dist/agent/turn/task-digest.js +33 -33
- package/dist/agent/turn/turn-context.d.ts +1 -1
- package/dist/agent/turn/turn-context.js +1 -1
- package/dist/agent/turn/turn-finish.d.ts +2 -2
- package/dist/agent/turn/turn-finish.js +3 -2
- package/dist/agent/turn/turn-pipeline.d.ts +4 -2
- package/dist/agent/turn/turn-pipeline.js +33 -5
- package/dist/agent/types.d.ts +64 -14
- package/dist/agent/types.js +3 -0
- package/dist/app/home.js +3 -4
- package/dist/channel/channel-event.d.ts +4 -12
- package/dist/channel/ingress.d.ts +1 -9
- package/dist/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +25 -19
- package/dist/commands/router.d.ts +5 -2
- package/dist/commands/router.js +9 -4
- package/dist/config/settings.d.ts +5 -12
- package/dist/config/settings.js +0 -7
- package/dist/config/tools.d.ts +2 -2
- package/dist/config/tools.js +2 -2
- package/dist/dingtalk/bot.d.ts +2 -0
- package/dist/dingtalk/bot.js +4 -0
- package/dist/dingtalk/cards.d.ts +7 -0
- package/dist/dingtalk/cards.js +32 -2
- package/dist/dingtalk/delivery.d.ts +4 -1
- package/dist/dingtalk/delivery.js +104 -191
- package/dist/dingtalk/progress.d.ts +41 -6
- package/dist/dingtalk/progress.js +173 -16
- package/dist/file-store.d.ts +4 -0
- package/dist/file-store.js +6 -1
- package/dist/jobs/completion-observer.d.ts +20 -0
- package/dist/jobs/completion-observer.js +107 -0
- package/dist/jobs/completion-signal.d.ts +9 -0
- package/dist/jobs/completion-signal.js +32 -0
- package/dist/jobs/completion-wake.d.ts +1 -1
- package/dist/jobs/completion-wake.js +2 -13
- package/dist/jobs/manager.d.ts +11 -29
- package/dist/jobs/manager.js +103 -176
- package/dist/jobs/probe.d.ts +3 -0
- package/dist/jobs/probe.js +42 -0
- package/dist/jobs/record.d.ts +3 -6
- package/dist/jobs/runtime.d.ts +28 -0
- package/dist/jobs/runtime.js +69 -0
- package/dist/memory/boundary-work.d.ts +2 -0
- package/dist/memory/boundary-work.js +79 -37
- package/dist/memory/commands.js +4 -1
- package/dist/memory/index-budget.js +18 -15
- package/dist/memory/journal.js +2 -1
- package/dist/memory/lifecycle.d.ts +4 -8
- package/dist/memory/lifecycle.js +21 -51
- package/dist/memory/reflect-job.d.ts +0 -6
- package/dist/memory/reflect-job.js +13 -34
- package/dist/memory/reflect.d.ts +4 -0
- package/dist/memory/reflect.js +32 -5
- package/dist/memory/review-log.d.ts +13 -0
- package/dist/memory/review-log.js +49 -0
- package/dist/memory/search.js +7 -4
- package/dist/memory/source-window.d.ts +18 -1
- package/dist/memory/source-window.js +59 -9
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +45 -13
- package/dist/playbooks/agent-delegation.md +10 -4
- package/dist/playbooks/background-jobs.md +4 -4
- package/dist/playbooks/event-scheduling.md +2 -2
- package/dist/playbooks/memory-and-learning.md +3 -3
- package/dist/playbooks/outbound-media.md +2 -2
- package/dist/playbooks/runtime-orientation.md +10 -6
- package/dist/playbooks/task-lead.md +54 -33
- package/dist/runtime/bootstrap.d.ts +11 -24
- package/dist/runtime/bootstrap.js +92 -59
- package/dist/runtime/channel-queue.d.ts +2 -0
- package/dist/runtime/channel-queue.js +5 -1
- package/dist/runtime/durable-dispatch.d.ts +7 -0
- package/dist/runtime/durable-dispatch.js +66 -7
- package/dist/runtime/ingress-busy.d.ts +1 -2
- package/dist/runtime/ingress-busy.js +2 -35
- package/dist/runtime/ingress-commands.d.ts +1 -1
- package/dist/runtime/ingress-commands.js +28 -20
- package/dist/runtime/ingress-deps.d.ts +4 -7
- package/dist/runtime/ingress.js +23 -13
- package/dist/runtime/shutdown.d.ts +1 -1
- package/dist/runtime/shutdown.js +2 -2
- package/dist/runtime/task-close.d.ts +4 -0
- package/dist/runtime/task-close.js +102 -0
- package/dist/runtime/task-control.d.ts +34 -0
- package/dist/runtime/task-control.js +225 -0
- package/dist/runtime/task-input.d.ts +13 -0
- package/dist/runtime/task-input.js +129 -0
- package/dist/runtime/task-lane-types.d.ts +123 -0
- package/dist/runtime/task-lane-types.js +14 -0
- package/dist/runtime/task-lane.d.ts +99 -0
- package/dist/runtime/task-lane.js +703 -0
- package/dist/runtime/task-pending.d.ts +8 -0
- package/dist/runtime/task-pending.js +40 -0
- package/dist/runtime/task-spawn.d.ts +4 -4
- package/dist/runtime/task-spawn.js +4 -4
- package/dist/runtime/task-step.d.ts +32 -0
- package/dist/runtime/task-step.js +276 -0
- package/dist/runtime/turn-run.d.ts +4 -16
- package/dist/runtime/turn-run.js +17 -155
- package/dist/runtime/wake-coalescing.d.ts +1 -3
- package/dist/runtime/wake-coalescing.js +2 -4
- package/dist/shared/format.d.ts +0 -6
- package/dist/shared/format.js +0 -17
- package/dist/shared/host-process.d.ts +2 -0
- package/dist/shared/host-process.js +16 -1
- package/dist/shared/jsonl-appender.d.ts +5 -0
- package/dist/shared/jsonl-appender.js +25 -2
- package/dist/skills/catalog.d.ts +9 -0
- package/dist/skills/catalog.js +34 -0
- package/dist/skills/commands.d.ts +3 -12
- package/dist/skills/commands.js +36 -22
- package/dist/skills/loader.d.ts +2 -31
- package/dist/skills/loader.js +101 -68
- package/dist/skills/roots.d.ts +12 -0
- package/dist/skills/roots.js +18 -0
- package/dist/skills/types.d.ts +24 -0
- package/dist/skills/types.js +1 -0
- package/dist/subagents/completion-wake.js +0 -10
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +10 -16
- package/dist/subagents/dispatch.js +8 -16
- package/dist/subagents/external/cursor-cli.d.ts +2 -0
- package/dist/subagents/external/cursor-cli.js +256 -0
- package/dist/subagents/external/harness.d.ts +5 -5
- package/dist/subagents/external/reconciliation.d.ts +7 -0
- package/dist/subagents/external/reconciliation.js +105 -0
- package/dist/subagents/external/recovery.d.ts +20 -0
- package/dist/subagents/external/recovery.js +71 -0
- package/dist/subagents/external/registry.js +2 -0
- package/dist/subagents/external/role-warnings.d.ts +17 -0
- package/dist/subagents/external/role-warnings.js +42 -0
- package/dist/subagents/external/run.js +18 -22
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/grace.d.ts +2 -2
- package/dist/subagents/grace.js +3 -3
- package/dist/subagents/internal/run.js +7 -5
- package/dist/subagents/internal/worker.js +31 -2
- package/dist/subagents/result.js +2 -3
- package/dist/subagents/run-record.d.ts +4 -7
- package/dist/subagents/run-record.js +2 -2
- package/dist/subagents/runs.d.ts +33 -46
- package/dist/subagents/runs.js +126 -245
- package/dist/subagents/task-settlement.d.ts +3 -0
- package/dist/subagents/task-settlement.js +20 -0
- package/dist/subagents/types.d.ts +1 -2
- package/dist/subagents/workspace-summary.js +5 -1
- package/dist/tasks/archive.d.ts +11 -0
- package/dist/tasks/archive.js +141 -0
- package/dist/tasks/board.d.ts +5 -12
- package/dist/tasks/board.js +4 -30
- package/dist/tasks/bound-work.d.ts +12 -6
- package/dist/tasks/bound-work.js +37 -24
- package/dist/tasks/brief.d.ts +38 -14
- package/dist/tasks/brief.js +128 -70
- package/dist/tasks/budget.d.ts +3 -3
- package/dist/tasks/budget.js +9 -4
- package/dist/tasks/commands.d.ts +14 -9
- package/dist/tasks/commands.js +190 -121
- package/dist/tasks/completion.d.ts +12 -0
- package/dist/tasks/completion.js +35 -0
- package/dist/tasks/contract.d.ts +8 -17
- package/dist/tasks/contract.js +41 -43
- package/dist/tasks/control.d.ts +138 -0
- package/dist/tasks/control.js +1 -0
- package/dist/tasks/create.d.ts +1 -1
- package/dist/tasks/create.js +3 -3
- package/dist/tasks/delivery.d.ts +24 -0
- package/dist/tasks/delivery.js +221 -0
- package/dist/tasks/file-mutation.d.ts +5 -0
- package/dist/tasks/file-mutation.js +38 -0
- package/dist/tasks/frontmatter.d.ts +43 -28
- package/dist/tasks/frontmatter.js +83 -40
- package/dist/tasks/input-receipts.d.ts +7 -0
- package/dist/tasks/input-receipts.js +60 -0
- package/dist/tasks/loop-log.d.ts +147 -28
- package/dist/tasks/loop-log.js +239 -28
- package/dist/tasks/receipts.d.ts +19 -0
- package/dist/tasks/receipts.js +48 -0
- package/dist/tasks/state.d.ts +93 -0
- package/dist/tasks/state.js +156 -0
- package/dist/tasks/store.d.ts +81 -49
- package/dist/tasks/store.js +244 -147
- package/dist/tools/bash.d.ts +3 -5
- package/dist/tools/bash.js +8 -22
- package/dist/tools/contract/details.d.ts +6 -6
- package/dist/tools/contract/details.js +6 -6
- package/dist/tools/contract/execution-trace.d.ts +4 -0
- package/dist/tools/contract/execution-trace.js +23 -0
- package/dist/tools/contract/presentation.js +6 -2
- package/dist/tools/edit.d.ts +1 -0
- package/dist/tools/edit.js +45 -42
- package/dist/tools/index.d.ts +8 -12
- package/dist/tools/index.js +16 -6
- package/dist/tools/memory-manage.js +8 -1
- package/dist/tools/registry.d.ts +7 -11
- package/dist/tools/registry.js +52 -25
- package/dist/tools/skill.d.ts +2 -2
- package/dist/tools/skill.js +24 -10
- package/dist/tools/subagent-manage.js +7 -4
- package/dist/tools/subagent.d.ts +0 -2
- package/dist/tools/subagent.js +2 -7
- package/dist/tools/task-manage/control-tools.d.ts +4 -0
- package/dist/tools/task-manage/control-tools.js +65 -0
- package/dist/tools/task-manage/create.js +2 -1
- package/dist/tools/task-manage/factory.d.ts +12 -6
- package/dist/tools/task-manage/factory.js +72 -57
- package/dist/tools/task-manage/lifecycle.d.ts +7 -12
- package/dist/tools/task-manage/lifecycle.js +118 -66
- package/dist/tools/task-manage/log-view.js +8 -5
- package/dist/tools/task-manage/schema.d.ts +21 -26
- package/dist/tools/task-manage/schema.js +29 -35
- package/dist/tools/task-manage/shared.d.ts +8 -39
- package/dist/tools/task-manage/shared.js +19 -68
- package/dist/tools/task-manage/step-tools.d.ts +5 -0
- package/dist/tools/task-manage/step-tools.js +103 -0
- package/dist/tools/task-manage/types.d.ts +25 -18
- package/dist/tools/write-content.d.ts +1 -0
- package/dist/tools/write-content.js +6 -1
- package/dist/tools/write.d.ts +1 -0
- package/dist/tools/write.js +1 -0
- package/dist/usage/ledger.d.ts +4 -4
- package/dist/usage/render.js +2 -2
- package/dist/web/search-providers.js +0 -33
- package/dist/webapi/request-policy.js +1 -1
- package/examples/sub-agents/README.md +23 -16
- package/examples/sub-agents/agents/claude-high.md +1 -1
- package/examples/sub-agents/agents/claude-main.md +1 -1
- package/examples/sub-agents/agents/codex-flash.md +1 -1
- package/examples/sub-agents/agents/codex-high.md +1 -1
- package/examples/sub-agents/agents/codex-main.md +4 -4
- package/examples/sub-agents/agents/cursor-high.md +22 -0
- package/examples/sub-agents/agents/cursor-main.md +22 -0
- package/examples/sub-agents/agents/glm-flash.md +1 -1
- package/examples/sub-agents/agents/glm-high.md +2 -2
- package/examples/sub-agents/agents/scout.md +30 -0
- package/package.json +6 -6
- package/dist/runtime/task-driver.d.ts +0 -116
- package/dist/runtime/task-driver.js +0 -443
- package/dist/runtime/task-wake.d.ts +0 -48
- package/dist/runtime/task-wake.js +0 -32
- package/dist/shared/wake-claim.d.ts +0 -23
- package/dist/shared/wake-claim.js +0 -26
- package/dist/skills/validation.d.ts +0 -8
- package/dist/skills/validation.js +0 -91
- package/dist/skills/workspace.d.ts +0 -33
- package/dist/skills/workspace.js +0 -116
- package/dist/tasks/steer.d.ts +0 -8
- package/dist/tasks/steer.js +0 -81
- package/dist/tasks/ticket.d.ts +0 -71
- package/dist/tasks/ticket.js +0 -138
- package/dist/tools/task-manage/step-end.d.ts +0 -11
- package/dist/tools/task-manage/step-end.js +0 -117
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { formatLocalTime } from "../shared/local-time.js";
|
|
2
2
|
import { errorMessage } from "../shared/text-utils.js";
|
|
3
|
-
import { drainBoundaryReflectWork } from "./boundary-work.js";
|
|
3
|
+
import { drainBoundaryReflectWork, hasBoundaryReflectWork } from "./boundary-work.js";
|
|
4
4
|
import { getDeskMemoryQueue } from "./desk-memory-queue.js";
|
|
5
5
|
import { shouldRunReflect } from "./maintenance-gates.js";
|
|
6
6
|
import { readMemoryMaintenanceState, updateMemoryMaintenanceState } from "./maintenance-state.js";
|
|
7
7
|
import { resolveMemoryMaintenanceSettings, } from "./maintenance-tuning.js";
|
|
8
8
|
import { runReflect } from "./reflect.js";
|
|
9
|
-
import {
|
|
9
|
+
import { reviewLogEntryFor, tryAppendMemoryReviewLog } from "./review-log.js";
|
|
10
10
|
import { buildIncrementalMemorySourceWindow } from "./source-window.js";
|
|
11
11
|
import { hasMeaningfulExchange, sanitizeMessagesForMemory } from "./transcript.js";
|
|
12
12
|
function backoffUntil(now, settings) {
|
|
@@ -16,10 +16,15 @@ export async function runReflectJob(input) {
|
|
|
16
16
|
const queue = input.queue ?? getDeskMemoryQueue();
|
|
17
17
|
const { conversation } = input;
|
|
18
18
|
const { channelId, deskDir } = conversation;
|
|
19
|
-
await
|
|
19
|
+
if (await hasBoundaryReflectWork(conversation)) {
|
|
20
|
+
await drainBoundaryReflectWork({ ...input, queue });
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
20
23
|
if (!input.settings.memoryMaintenance.enabled)
|
|
21
24
|
return;
|
|
22
25
|
return queue.run(conversation, async () => {
|
|
26
|
+
if (await hasBoundaryReflectWork(conversation))
|
|
27
|
+
return;
|
|
23
28
|
const now = input.now ?? new Date();
|
|
24
29
|
const maintenance = resolveMemoryMaintenanceSettings(input.settings.memoryMaintenance);
|
|
25
30
|
const state = await readMemoryMaintenanceState(input.appHomeDir, conversation);
|
|
@@ -47,7 +52,7 @@ export async function runReflectJob(input) {
|
|
|
47
52
|
},
|
|
48
53
|
});
|
|
49
54
|
if (!decision.allowed) {
|
|
50
|
-
await
|
|
55
|
+
await tryAppendMemoryReviewLog(deskDir, {
|
|
51
56
|
timestamp: formatLocalTime(now),
|
|
52
57
|
channelId: channelId,
|
|
53
58
|
reason: "reflect",
|
|
@@ -68,16 +73,16 @@ export async function runReflectJob(input) {
|
|
|
68
73
|
});
|
|
69
74
|
await updateMemoryMaintenanceState(input.appHomeDir, conversation, (current) => ({
|
|
70
75
|
...current,
|
|
71
|
-
lastReflectAt: formatLocalTime(now),
|
|
76
|
+
lastReflectAt: sourceWindow.hasMore ? current.lastReflectAt : formatLocalTime(now),
|
|
72
77
|
lastReflectedEntryId: sourceWindow.throughEntryId ?? current.lastReflectedEntryId,
|
|
73
78
|
failureBackoffUntil: null,
|
|
74
79
|
}));
|
|
75
|
-
await
|
|
80
|
+
await tryAppendMemoryReviewLog(deskDir, {
|
|
76
81
|
timestamp: formatLocalTime(now),
|
|
77
82
|
channelId: channelId,
|
|
78
83
|
reason: "reflect",
|
|
79
84
|
correlationId: sourceWindow.windowId,
|
|
80
|
-
...reviewLogEntryFor(result),
|
|
85
|
+
...reviewLogEntryFor(result, sourceWindow),
|
|
81
86
|
});
|
|
82
87
|
}
|
|
83
88
|
catch (error) {
|
|
@@ -86,7 +91,7 @@ export async function runReflectJob(input) {
|
|
|
86
91
|
failureBackoffUntil: backoffUntil(now, maintenance),
|
|
87
92
|
}));
|
|
88
93
|
const message = errorMessage(error);
|
|
89
|
-
await
|
|
94
|
+
await tryAppendMemoryReviewLog(deskDir, {
|
|
90
95
|
timestamp: formatLocalTime(now),
|
|
91
96
|
channelId: channelId,
|
|
92
97
|
reason: "reflect",
|
|
@@ -95,29 +100,3 @@ export async function runReflectJob(input) {
|
|
|
95
100
|
}
|
|
96
101
|
});
|
|
97
102
|
}
|
|
98
|
-
/** Shared by the idle job and `lifecycle.ts`'s boundary calls, so both write the same shape. */
|
|
99
|
-
export function reviewLogEntryFor(result) {
|
|
100
|
-
if (result.skipped) {
|
|
101
|
-
return { skipped: [{ target: "reflect", reason: "no meaningful exchange" }] };
|
|
102
|
-
}
|
|
103
|
-
const actions = [];
|
|
104
|
-
if (result.added.length || result.updated.length || result.deleted.length || result.touched.length) {
|
|
105
|
-
actions.push({
|
|
106
|
-
target: "memory",
|
|
107
|
-
action: "reflect",
|
|
108
|
-
added: result.added,
|
|
109
|
-
updated: result.updated,
|
|
110
|
-
deleted: result.deleted,
|
|
111
|
-
touched: result.touched,
|
|
112
|
-
condensed: result.condensed,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
if (result.journalAppended > 0) {
|
|
116
|
-
actions.push({ target: "journal", action: "append", count: result.journalAppended });
|
|
117
|
-
}
|
|
118
|
-
if (result.expiredProbation.length > 0) {
|
|
119
|
-
actions.push({ target: "memory", action: "expire", entries: result.expiredProbation });
|
|
120
|
-
}
|
|
121
|
-
const skipped = result.rejected.map((item) => ({ target: "memory", ...item }));
|
|
122
|
-
return { actions, skipped: skipped.length > 0 ? skipped : undefined };
|
|
123
|
-
}
|
package/dist/memory/reflect.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ export interface ReflectRunOptions {
|
|
|
9
9
|
/** The conversation window to reflect on (already extracted by the caller's source window). */
|
|
10
10
|
messages: AgentMessage[];
|
|
11
11
|
timeoutMs?: number;
|
|
12
|
+
/** Closed boundary snapshots cannot wait for an answer from the outgoing session. */
|
|
13
|
+
sourceClosed?: boolean;
|
|
12
14
|
usageContext?: {
|
|
13
15
|
channelId: string;
|
|
14
16
|
desk?: string;
|
|
@@ -44,6 +46,8 @@ export interface ReflectRunResult {
|
|
|
44
46
|
content: string;
|
|
45
47
|
reason: string;
|
|
46
48
|
}>;
|
|
49
|
+
/** Accepted destructive operations, for the review log. */
|
|
50
|
+
decisions?: ReflectOpOutcome[];
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* Run one reflect pass over `options.messages`. Deterministic invariants (write tier, per-run
|
package/dist/memory/reflect.js
CHANGED
|
@@ -7,8 +7,9 @@ import { buildMemoryIndexForBootstrap, MEMORY_INDEX_MAX_UNITS } from "./index-bu
|
|
|
7
7
|
import { appendJournalEntries } from "./journal.js";
|
|
8
8
|
import { MEMORY_INPUT_SAFETY_RULES } from "./prompt-safety.js";
|
|
9
9
|
import { runRetriedSidecarTask } from "./sidecar-worker.js";
|
|
10
|
+
import { MEMORY_TRANSCRIPT_MAX_CHARS } from "./source-window.js";
|
|
10
11
|
import { applyMemoryOps, expireProbationaryEntries, isValidMemoryName, listMemoryEntries, renderMemoryIndex, } from "./store.js";
|
|
11
|
-
import { hasMeaningfulExchange, sanitizeMessagesForMemory } from "./transcript.js";
|
|
12
|
+
import { hasMeaningfulExchange, messageText, sanitizeMessagesForMemory } from "./transcript.js";
|
|
12
13
|
/**
|
|
13
14
|
* Spec 050, D7: the single background pass that replaces session-refresh, memory-checkpoint,
|
|
14
15
|
* and structural-maintenance (cleanup + fold). One LLM call reads a conversation window plus the
|
|
@@ -23,7 +24,6 @@ const MAX_ADD_PER_RUN = 8;
|
|
|
23
24
|
const MAX_PROBATIONARY_ADD_PER_RUN = 5;
|
|
24
25
|
const MAX_DELETE_PER_RUN = 3;
|
|
25
26
|
const MAX_DELETE_PER_RUN_CONDENSE = 8;
|
|
26
|
-
const TRANSCRIPT_MAX_CHARS = 28_000;
|
|
27
27
|
const WORKSPACE_MEMORY_MAX_CHARS = 3_000;
|
|
28
28
|
const JOURNAL_TAIL_MAX_CHARS = 3_000;
|
|
29
29
|
function probationDeadline(today) {
|
|
@@ -113,7 +113,7 @@ async function buildPrompt(options, today) {
|
|
|
113
113
|
readOptionalTextFile(`${options.deskDir}/journal/${today}.md`),
|
|
114
114
|
]);
|
|
115
115
|
const tiered = buildMemoryIndexForBootstrap(entries, MEMORY_INDEX_MAX_UNITS);
|
|
116
|
-
const transcript = clipText(serializeConversation(sanitizeMessagesForMemory(options.messages)),
|
|
116
|
+
const transcript = clipText(serializeConversation(sanitizeMessagesForMemory(options.messages)), MEMORY_TRANSCRIPT_MAX_CHARS, { headRatio: 0.35 });
|
|
117
117
|
const sections = [
|
|
118
118
|
`Desk memory index (full):\n${renderMemoryIndex(entries) || "(empty)"}`,
|
|
119
119
|
`Workspace background (read-only; do not target it with ops):\n${clipText(workspaceMemory, WORKSPACE_MEMORY_MAX_CHARS, { headRatio: 0.35 }) || "(empty)"}`,
|
|
@@ -149,7 +149,8 @@ export async function runReflect(options) {
|
|
|
149
149
|
// Deterministic pre-step, independent of whether the window has meaningful material.
|
|
150
150
|
const expiredProbation = await expireProbationaryEntries(options.deskDir, today);
|
|
151
151
|
const sanitized = sanitizeMessagesForMemory(options.messages);
|
|
152
|
-
if (!hasMeaningfulExchange(sanitized)
|
|
152
|
+
if (!hasMeaningfulExchange(sanitized) &&
|
|
153
|
+
!(options.sourceClosed && sanitized.some((message) => message.role === "user" && messageText(message).trim()))) {
|
|
153
154
|
return { ...empty, skipped: true, expiredProbation };
|
|
154
155
|
}
|
|
155
156
|
const { prompt, condense } = await buildPrompt(options, today);
|
|
@@ -287,7 +288,32 @@ export async function runReflect(options) {
|
|
|
287
288
|
if (touchNames.length > 0) {
|
|
288
289
|
storeOps.push({ op: "touch", names: touchNames });
|
|
289
290
|
}
|
|
290
|
-
|
|
291
|
+
// Apply replacements before deleting originals. Any rejected content write makes the
|
|
292
|
+
// entire automatic deletion phase unsafe; delaying unrelated cleanup is intentional.
|
|
293
|
+
const writes = storeOps.filter((op) => op.op !== "delete");
|
|
294
|
+
const deletes = storeOps.filter((op) => op.op === "delete");
|
|
295
|
+
const updatedTargets = new Set(writes.flatMap((op) => (op.op === "update" ? [op.name] : [])));
|
|
296
|
+
const applied = await applyMemoryOps(options.deskDir, writes, { today });
|
|
297
|
+
const unsafe = rejected.some((op) => op.op === "add" || op.op === "update") ||
|
|
298
|
+
applied.skippedSecret > 0 ||
|
|
299
|
+
applied.skippedTombstone > 0 ||
|
|
300
|
+
applied.missingTarget > 0 ||
|
|
301
|
+
deletes.some((op) => updatedTargets.has(op.name));
|
|
302
|
+
if (unsafe) {
|
|
303
|
+
rejected.push(...deletes.map((op) => ({
|
|
304
|
+
op: "delete",
|
|
305
|
+
name: op.name,
|
|
306
|
+
reason: "deletion deferred: a replacement failed or targets conflict",
|
|
307
|
+
})));
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
const removed = await applyMemoryOps(options.deskDir, deletes, { today });
|
|
311
|
+
applied.deleted.push(...removed.deleted);
|
|
312
|
+
}
|
|
313
|
+
// Keep the accepted destructive decisions inspectable, not just a list of names.
|
|
314
|
+
const decisions = deletes
|
|
315
|
+
.filter((op) => applied.deleted.includes(op.name))
|
|
316
|
+
.map((op) => ({ op: "delete", name: op.name, reason: op.reason ?? "reflect" }));
|
|
291
317
|
const journalResult = await appendJournalEntries(options.deskDir, today, parsed.journal);
|
|
292
318
|
return {
|
|
293
319
|
skipped: false,
|
|
@@ -310,5 +336,6 @@ export async function runReflect(options) {
|
|
|
310
336
|
: []),
|
|
311
337
|
],
|
|
312
338
|
discarded: parsed.discarded,
|
|
339
|
+
decisions,
|
|
313
340
|
};
|
|
314
341
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReflectRunResult } from "./reflect.js";
|
|
1
2
|
/** Spec 050, D10: the idle reflect job, a boundary-triggered reflect run, or a memory tool event. */
|
|
2
3
|
export type MemoryReviewReason = "reflect" | "reflect-boundary" | "memory-save" | "memory-forget";
|
|
3
4
|
export interface MemoryReviewLogEntry {
|
|
@@ -10,5 +11,17 @@ export interface MemoryReviewLogEntry {
|
|
|
10
11
|
skipped?: unknown[];
|
|
11
12
|
error?: string;
|
|
12
13
|
}
|
|
14
|
+
/** An audit failure must not replay an already committed reflection. */
|
|
15
|
+
export declare function tryAppendMemoryReviewLog(deskDir: string, entry: MemoryReviewLogEntry): Promise<void>;
|
|
13
16
|
export declare function getMemoryReviewLogPath(deskDir: string): string;
|
|
14
17
|
export declare function appendMemoryReviewLog(deskDir: string, entry: MemoryReviewLogEntry): Promise<void>;
|
|
18
|
+
/** Shared by the idle job and `lifecycle.ts`'s boundary calls, so both write the same shape. */
|
|
19
|
+
export declare function reviewLogEntryFor(result: ReflectRunResult, source?: {
|
|
20
|
+
fromEntryId?: string;
|
|
21
|
+
throughEntryId?: string;
|
|
22
|
+
hasMore: boolean;
|
|
23
|
+
sampledChars: number;
|
|
24
|
+
}): {
|
|
25
|
+
actions?: unknown[];
|
|
26
|
+
skipped?: unknown[];
|
|
27
|
+
};
|
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
import { appendFile, mkdir, readFile, stat } from "node:fs/promises";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
|
+
import * as log from "../log.js";
|
|
3
4
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
4
5
|
import { createSerialQueue } from "../shared/serial-queue.js";
|
|
6
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
7
|
+
/** An audit failure must not replay an already committed reflection. */
|
|
8
|
+
export async function tryAppendMemoryReviewLog(deskDir, entry) {
|
|
9
|
+
try {
|
|
10
|
+
await appendMemoryReviewLog(deskDir, entry);
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
log.logWarn("memory.review_log.write_failed", "Memory review log write failed", {
|
|
14
|
+
channelId: entry.channelId,
|
|
15
|
+
reason: errorMessage(error),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
5
19
|
const REVIEW_LOG_MAX_BYTES = 1_024 * 1_024; // 1 MB
|
|
6
20
|
// Three job kinds share a log per desk (path), so the key space is path x reason.
|
|
7
21
|
const MAX_GATE_SKIP_KEYS = 768;
|
|
@@ -59,3 +73,38 @@ export async function appendMemoryReviewLog(deskDir, entry) {
|
|
|
59
73
|
await appendFile(path, line, "utf-8");
|
|
60
74
|
});
|
|
61
75
|
}
|
|
76
|
+
/** Shared by the idle job and `lifecycle.ts`'s boundary calls, so both write the same shape. */
|
|
77
|
+
export function reviewLogEntryFor(result, source) {
|
|
78
|
+
const actions = [...(result.decisions ?? [])];
|
|
79
|
+
if (source?.hasMore || source?.sampledChars) {
|
|
80
|
+
actions.push({
|
|
81
|
+
target: "source",
|
|
82
|
+
action: source.sampledChars ? "sample" : "batch",
|
|
83
|
+
fromEntryId: source.fromEntryId,
|
|
84
|
+
throughEntryId: source.throughEntryId,
|
|
85
|
+
hasMore: source.hasMore,
|
|
86
|
+
sampledChars: source.sampledChars,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (result.added.length || result.updated.length || result.deleted.length || result.touched.length) {
|
|
90
|
+
actions.push({
|
|
91
|
+
target: "memory",
|
|
92
|
+
action: "reflect",
|
|
93
|
+
added: result.added,
|
|
94
|
+
updated: result.updated,
|
|
95
|
+
deleted: result.deleted,
|
|
96
|
+
touched: result.touched,
|
|
97
|
+
condensed: result.condensed,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
if (result.journalAppended > 0) {
|
|
101
|
+
actions.push({ target: "journal", action: "append", count: result.journalAppended });
|
|
102
|
+
}
|
|
103
|
+
if (result.expiredProbation.length > 0) {
|
|
104
|
+
actions.push({ target: "memory", action: "expire", entries: result.expiredProbation });
|
|
105
|
+
}
|
|
106
|
+
const skipped = result.rejected.map((item) => ({ target: "memory", ...item }));
|
|
107
|
+
if (result.skipped)
|
|
108
|
+
skipped.push({ target: "reflect", reason: "no meaningful exchange" });
|
|
109
|
+
return { actions, skipped: skipped.length > 0 ? skipped : undefined };
|
|
110
|
+
}
|
package/dist/memory/search.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { parseLocalTime } from "../shared/local-time.js";
|
|
2
|
-
import { splitH2Sections } from "../shared/markdown-sections.js";
|
|
3
2
|
import { HAN_REGEX } from "../shared/text-utils.js";
|
|
4
3
|
import { COMMON_CHINESE_WORDS } from "./chinese-words.js";
|
|
5
4
|
/**
|
|
@@ -289,10 +288,14 @@ export function searchMemory(input) {
|
|
|
289
288
|
}
|
|
290
289
|
}
|
|
291
290
|
if (input.workspaceMemory) {
|
|
292
|
-
|
|
293
|
-
|
|
291
|
+
// Keep the preamble and empty headings searchable without changing the shared parser.
|
|
292
|
+
for (const block of input.workspaceMemory.split(/(?=^## )/m)) {
|
|
293
|
+
if (!block.trim())
|
|
294
|
+
continue;
|
|
295
|
+
const heading = /^## ([^\n]+)/.exec(block)?.[1]?.trim() ?? "Background";
|
|
296
|
+
const { score, line } = scoreText(queryTokens, block);
|
|
294
297
|
if (score > 0) {
|
|
295
|
-
hits.push({ kind: "workspace", label:
|
|
298
|
+
hits.push({ kind: "workspace", label: heading, line, score });
|
|
296
299
|
}
|
|
297
300
|
}
|
|
298
301
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import type
|
|
2
|
+
import { type SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
export declare const MEMORY_TRANSCRIPT_MAX_CHARS = 28000;
|
|
3
4
|
export type MemorySourceKind = "idle" | "compaction" | "new-session" | "shutdown";
|
|
4
5
|
export interface MemorySourceWindow {
|
|
5
6
|
sourceKind: MemorySourceKind;
|
|
@@ -8,11 +9,27 @@ export interface MemorySourceWindow {
|
|
|
8
9
|
entries: SessionEntry[];
|
|
9
10
|
messages: AgentMessage[];
|
|
10
11
|
windowId: string;
|
|
12
|
+
hasMore: boolean;
|
|
13
|
+
/** An indivisible exchange exceeds the budget and will be explicitly sampled. */
|
|
14
|
+
sampledChars: number;
|
|
11
15
|
}
|
|
16
|
+
interface SourceEntry {
|
|
17
|
+
id: string;
|
|
18
|
+
message?: AgentMessage;
|
|
19
|
+
}
|
|
20
|
+
/** Select a contiguous prefix of complete exchanges; never acknowledge a trailing unanswered user. */
|
|
21
|
+
export declare function selectMemorySourceBatch<T extends SourceEntry>(entries: T[], closed?: boolean): {
|
|
22
|
+
entries: T[];
|
|
23
|
+
messages: AgentMessage[];
|
|
24
|
+
hasMore: boolean;
|
|
25
|
+
sampledChars: number;
|
|
26
|
+
};
|
|
12
27
|
export declare function entriesSince(entries: SessionEntry[], lastEntryId: string | undefined): SessionEntry[];
|
|
13
28
|
export declare function buildIncrementalMemorySourceWindow(options: {
|
|
14
29
|
entries: SessionEntry[];
|
|
15
30
|
lastEntryId?: string;
|
|
16
31
|
sourceKind: Extract<MemorySourceKind, "idle" | "new-session" | "shutdown">;
|
|
17
32
|
fallbackMessages?: AgentMessage[];
|
|
33
|
+
closed?: boolean;
|
|
18
34
|
}): MemorySourceWindow;
|
|
35
|
+
export {};
|
|
@@ -1,9 +1,53 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { serializeConversation } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { messageText, sanitizeMessagesForMemory } from "./transcript.js";
|
|
4
|
+
export const MEMORY_TRANSCRIPT_MAX_CHARS = 28_000;
|
|
5
|
+
/** Select a contiguous prefix of complete exchanges; never acknowledge a trailing unanswered user. */
|
|
6
|
+
export function selectMemorySourceBatch(entries, closed = false) {
|
|
7
|
+
const ends = [];
|
|
8
|
+
let groupStart = 0;
|
|
9
|
+
let userSeen = false;
|
|
10
|
+
let answered = false;
|
|
11
|
+
for (let index = 0; index < entries.length; index++) {
|
|
12
|
+
const raw = entries[index].message;
|
|
13
|
+
const message = raw ? sanitizeMessagesForMemory([raw])[0] : undefined;
|
|
14
|
+
if (!message || !messageText(message).trim())
|
|
15
|
+
continue;
|
|
16
|
+
if (message.role === "user") {
|
|
17
|
+
if (userSeen && answered) {
|
|
18
|
+
ends.push(index);
|
|
19
|
+
groupStart = index;
|
|
20
|
+
answered = false;
|
|
21
|
+
}
|
|
22
|
+
userSeen = true;
|
|
23
|
+
}
|
|
24
|
+
else if (message.role === "assistant" && userSeen)
|
|
25
|
+
answered = true;
|
|
26
|
+
}
|
|
27
|
+
const openTail = !closed && userSeen && !answered;
|
|
28
|
+
const end = openTail ? groupStart : entries.length;
|
|
29
|
+
if (end > (ends.at(-1) ?? 0))
|
|
30
|
+
ends.push(end);
|
|
31
|
+
let count = 0;
|
|
32
|
+
let messages = [];
|
|
33
|
+
let size = 0;
|
|
34
|
+
for (const candidate of ends) {
|
|
35
|
+
const next = entries.slice(0, candidate).flatMap((entry) => (entry.message ? [entry.message] : []));
|
|
36
|
+
const chars = serializeConversation(sanitizeMessagesForMemory(next)).length;
|
|
37
|
+
if (count > 0 && chars > MEMORY_TRANSCRIPT_MAX_CHARS)
|
|
38
|
+
break;
|
|
39
|
+
count = candidate;
|
|
40
|
+
messages = next;
|
|
41
|
+
size = chars;
|
|
42
|
+
if (chars > MEMORY_TRANSCRIPT_MAX_CHARS)
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
entries: entries.slice(0, count),
|
|
47
|
+
messages,
|
|
48
|
+
hasMore: count < entries.length,
|
|
49
|
+
sampledChars: size > MEMORY_TRANSCRIPT_MAX_CHARS ? size : 0,
|
|
50
|
+
};
|
|
7
51
|
}
|
|
8
52
|
function createWindowId(sourceKind, fromEntryId, throughEntryId, messages) {
|
|
9
53
|
const fallbackFingerprint = throughEntryId === undefined
|
|
@@ -22,10 +66,14 @@ export function entriesSince(entries, lastEntryId) {
|
|
|
22
66
|
return index >= 0 ? entries.slice(index + 1) : [...entries];
|
|
23
67
|
}
|
|
24
68
|
export function buildIncrementalMemorySourceWindow(options) {
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
?
|
|
69
|
+
const remaining = entriesSince(options.entries, options.lastEntryId);
|
|
70
|
+
const batch = selectMemorySourceBatch(remaining.map((entry) => ({
|
|
71
|
+
...entry,
|
|
72
|
+
message: entry.type === "message" ? entry.message : undefined,
|
|
73
|
+
})), options.closed);
|
|
74
|
+
const entries = remaining.slice(0, batch.entries.length);
|
|
75
|
+
const messages = remaining.length > 0 || options.lastEntryId !== undefined
|
|
76
|
+
? batch.messages
|
|
29
77
|
: [...(options.fallbackMessages ?? [])];
|
|
30
78
|
const throughEntryId = entries.at(-1)?.id;
|
|
31
79
|
return {
|
|
@@ -35,5 +83,7 @@ export function buildIncrementalMemorySourceWindow(options) {
|
|
|
35
83
|
entries,
|
|
36
84
|
messages,
|
|
37
85
|
windowId: createWindowId(options.sourceKind, options.lastEntryId, throughEntryId, messages),
|
|
86
|
+
hasMore: batch.hasMore,
|
|
87
|
+
sampledChars: batch.sampledChars,
|
|
38
88
|
};
|
|
39
89
|
}
|
package/dist/memory/store.d.ts
CHANGED
package/dist/memory/store.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { appendFile, mkdir, readdir, readFile, rm
|
|
2
|
+
import { appendFile, lstat, mkdir, readdir, readFile, rm } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
5
5
|
import { localDayKey } from "../shared/local-time.js";
|
|
6
6
|
import { readOptionalTextFile } from "../shared/os.js";
|
|
7
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
7
8
|
import { containsSecret } from "./secret-redaction.js";
|
|
8
9
|
import { hashMemoryContent } from "./tombstones.js";
|
|
9
10
|
const MEMORY_TYPES = ["user", "feedback", "project", "reference"];
|
|
@@ -20,6 +21,9 @@ export function getMemoryIndexPath(deskDir) {
|
|
|
20
21
|
return join(deskDir, "MEMORY.md");
|
|
21
22
|
}
|
|
22
23
|
export function getMemoryEntryPath(deskDir, name) {
|
|
24
|
+
if (!isValidMemoryName(name)) {
|
|
25
|
+
throw new RecoverableToolError("Invalid memory name. Use a lowercase kebab-case name from memory_search.");
|
|
26
|
+
}
|
|
23
27
|
return join(getMemoryDir(deskDir), `${name}.md`);
|
|
24
28
|
}
|
|
25
29
|
function getTombstonesPath(deskDir) {
|
|
@@ -54,7 +58,8 @@ export function dedupeMemoryName(name, existing) {
|
|
|
54
58
|
return name;
|
|
55
59
|
}
|
|
56
60
|
for (let suffix = 2;; suffix++) {
|
|
57
|
-
const
|
|
61
|
+
const tail = `-${suffix}`;
|
|
62
|
+
const candidate = `${name.slice(0, MAX_NAME_LENGTH - tail.length).replace(/-+$/g, "")}${tail}`;
|
|
58
63
|
if (!taken.has(candidate)) {
|
|
59
64
|
return candidate;
|
|
60
65
|
}
|
|
@@ -171,13 +176,13 @@ export async function listMemoryEntries(deskDir) {
|
|
|
171
176
|
}
|
|
172
177
|
const entries = [];
|
|
173
178
|
for (const fileName of names) {
|
|
174
|
-
if (!fileName.endsWith(".md") || fileName.
|
|
179
|
+
if (!fileName.endsWith(".md") || !isValidMemoryName(fileName.slice(0, -3))) {
|
|
175
180
|
continue;
|
|
176
181
|
}
|
|
177
182
|
const path = join(dir, fileName);
|
|
178
183
|
let info;
|
|
179
184
|
try {
|
|
180
|
-
info = await
|
|
185
|
+
info = await lstat(path);
|
|
181
186
|
}
|
|
182
187
|
catch {
|
|
183
188
|
continue;
|
|
@@ -191,7 +196,15 @@ export async function listMemoryEntries(deskDir) {
|
|
|
191
196
|
entries.push(cached.entry);
|
|
192
197
|
continue;
|
|
193
198
|
}
|
|
194
|
-
|
|
199
|
+
let raw;
|
|
200
|
+
try {
|
|
201
|
+
raw = await readFile(path, "utf-8");
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
if (error.code === "ENOENT")
|
|
205
|
+
continue;
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
195
208
|
const entry = parseMemoryFile(name, raw, localDayKey(info.mtime));
|
|
196
209
|
fileCache.set(path, { mtimeMs: info.mtimeMs, entry });
|
|
197
210
|
entries.push(entry);
|
|
@@ -201,18 +214,22 @@ export async function listMemoryEntries(deskDir) {
|
|
|
201
214
|
}
|
|
202
215
|
export async function readMemoryEntry(deskDir, name) {
|
|
203
216
|
const path = getMemoryEntryPath(deskDir, name);
|
|
217
|
+
let info;
|
|
218
|
+
try {
|
|
219
|
+
info = await lstat(path);
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
if (error.code === "ENOENT")
|
|
223
|
+
return undefined;
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
if (!info.isFile())
|
|
227
|
+
return undefined;
|
|
204
228
|
const raw = await readOptionalTextFile(path);
|
|
205
229
|
if (!raw) {
|
|
206
230
|
return undefined;
|
|
207
231
|
}
|
|
208
|
-
|
|
209
|
-
try {
|
|
210
|
-
fallback = localDayKey((await stat(path)).mtime);
|
|
211
|
-
}
|
|
212
|
-
catch {
|
|
213
|
-
/* use today */
|
|
214
|
-
}
|
|
215
|
-
return parseMemoryFile(name, raw, fallback);
|
|
232
|
+
return parseMemoryFile(name, raw, localDayKey(info.mtime));
|
|
216
233
|
}
|
|
217
234
|
// -------------------------------------------------------------------------------------------------
|
|
218
235
|
// Index generation
|
|
@@ -366,9 +383,15 @@ export async function applyMemoryOps(deskDir, ops, options = {}) {
|
|
|
366
383
|
result.skippedSecret++;
|
|
367
384
|
continue;
|
|
368
385
|
}
|
|
386
|
+
const tombstoned = await isDescriptionTombstoned(deskDir, description);
|
|
387
|
+
if (tombstoned && op.source !== "user") {
|
|
388
|
+
result.skippedTombstone++;
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
369
391
|
const next = {
|
|
370
392
|
...entry,
|
|
371
393
|
description,
|
|
394
|
+
source: op.source ?? entry.source,
|
|
372
395
|
type: op.type ?? entry.type,
|
|
373
396
|
body: op.details !== undefined ? op.details.trim() : entry.body,
|
|
374
397
|
updated: today,
|
|
@@ -376,6 +399,8 @@ export async function applyMemoryOps(deskDir, ops, options = {}) {
|
|
|
376
399
|
malformed: false,
|
|
377
400
|
};
|
|
378
401
|
await writeEntryFile(deskDir, next);
|
|
402
|
+
if (tombstoned && op.source === "user")
|
|
403
|
+
await revokeMemoryTombstone(deskDir, description, today);
|
|
379
404
|
byName.set(op.name, next);
|
|
380
405
|
result.updated.push(op.name);
|
|
381
406
|
continue;
|
|
@@ -398,6 +423,13 @@ export async function applyMemoryOps(deskDir, ops, options = {}) {
|
|
|
398
423
|
result.skippedTombstone++;
|
|
399
424
|
continue;
|
|
400
425
|
}
|
|
426
|
+
// Background retries may revisit an already-applied add. Preserve the existing entry,
|
|
427
|
+
// including its source/expiry; a replay is not independent confirmation or a touch.
|
|
428
|
+
if (op.source === "agent" &&
|
|
429
|
+
[...byName.values()].some((entry) => hashMemoryContent(entry.description) === hashMemoryContent(description) &&
|
|
430
|
+
entry.type === (op.type ?? "project") &&
|
|
431
|
+
entry.body.trim() === (op.details?.trim() ?? "")))
|
|
432
|
+
continue;
|
|
401
433
|
const requested = op.name && isValidMemoryName(op.name) ? op.name : slugifyMemoryName(op.name || description);
|
|
402
434
|
const name = dedupeMemoryName(requested, liveNames);
|
|
403
435
|
if (name !== requested) {
|
|
@@ -18,7 +18,7 @@ order: 60
|
|
|
18
18
|
|
|
19
19
|
需要独立判断时(评审、验收、复核别人的结论),**独立性必须写进任务文本**:给同一份要求和验收口径、指明待检版本与检查入口,并写明「你是检查者,不修实现,不把实现者的总结当作预期行为的来源」。换一个条目不会自动带来独立性;能选时让不同家的模型检查。
|
|
20
20
|
|
|
21
|
-
先使用匹配的已配置条目;目录没有合适条目时,才用 `subagent_inline` 做一次性内置工作并自行提供 systemPrompt、工具和 effort。按条目调用只提供 `task`、`workingDirectory` 和 purpose/
|
|
21
|
+
先使用匹配的已配置条目;目录没有合适条目时,才用 `subagent_inline` 做一次性内置工作并自行提供 systemPrompt、工具和 effort。按条目调用只提供 `task`、`workingDirectory` 和 purpose/item,模型、推理档和预算由条目文件决定。聊天中的内置委派共享 10 秒快速返回窗口,超出或回合被 /stop 时自动转异步;task 内置委派确认启动后立即异步,结果由 runtime 持久化并在安全工具边界送回同一步骤,或唤起后续步骤;外部条目一律异步。收到 dispatched 后继续处理独立工作;只剩等待时结束当前回合,不轮询、不重复派发。内置遇到供应商瞬时错误会自动重试并可切备用模型,不必为此重派。
|
|
22
22
|
|
|
23
23
|
条目 unavailable 时先判断主代理或其他可用条目能否以相同验收标准完成,必要时拆成独立小分片;缺少必需能力才说明需要部署者补什么。light/heavy 不是能力证明。
|
|
24
24
|
|
|
@@ -51,9 +51,13 @@ order: 60
|
|
|
51
51
|
|
|
52
52
|
## 返回、等待与恢复
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
**结果已返回**:读取并检查,不再等第二次通知。**仍在运行**:记录 runId,完成其他独立工作/派发;只剩等待时结束回合,不轮询、重派或用后台 job/event 包一层等待。DingTalk 和 Web API 的完成唤醒都由运行时负责;宿主的持续运行要求见 `runtime-orientation.md`。
|
|
55
55
|
|
|
56
|
-
**在 task 步骤内**派发自动绑定到本任务,带上对应工作项 `item
|
|
56
|
+
**在 task 步骤内**派发自动绑定到本任务,带上对应工作项 `item`;只剩等待时结束回合,任一在途委派或作业结算或卡住都会叫醒你(细节见 `task-lead.md`)。聊天里派发的委派不属于任何任务,`item` 只在任务步骤里有效;要让任务处理某件事,用 `task_message` 告诉它,由它的负责人派发。
|
|
57
|
+
|
|
58
|
+
**卡住**:外部执行者连续 10 分钟没有输出,任务会收到卡顿报告。用 `subagent_run op=show` 看上次输出时间和 stderr:长时间安静的正常工作就继续等;明显卡死就 `subagent_run op=cancel`,换方式、缩小范围或换执行者重派,不要干等到 wall time。
|
|
59
|
+
|
|
60
|
+
**取消**:`/stop` 和 `task_pause` 都不取消委派;取消任务(`task_close outcome=cancel`)会连带取消它的在途委派和作业。
|
|
57
61
|
|
|
58
62
|
需要作出进度判断时用 `subagent_list`。它列出整个工位的委派,同工位其他频道发起的也在其中(标 `started in <频道>`),同样可以管理;但它们完成时唤醒的是发起频道,不会唤醒你,不要等它们。运行中委派按工位合计最多 6 个、宿主共 20 个;满额时等待已有结果,不为腾名额取消仍有用的工作。
|
|
59
63
|
|
|
@@ -61,9 +65,11 @@ order: 60
|
|
|
61
65
|
|
|
62
66
|
daemon 重启后内置 run 判 lost,外部通常继续;外部启动信息尚未落盘也可能 lost。lost 是结局未知,先查产物再重派。重连耗时带 `≈` 是估算。失败原因不清用 `subagent_run op=show` 查看 argv、警告、版本与 stderr,不猜原因反复重派。
|
|
63
67
|
|
|
68
|
+
委派记录与运行时管理产物(含 `output.md`)在结算满 30 天后按每日批次清理。需要长期复核的关键证据及时保存到任务工作目录或目标项目,不把临时输出路径当作永久证据。
|
|
69
|
+
|
|
64
70
|
## 纠偏:续接还是重开
|
|
65
71
|
|
|
66
|
-
`subagent_run op=follow_up` 只支持已结束的 claude-code/codex-cli run,产生新的 runId(归属发起续接的频道);追加内容只写原契约的变化。目标不变、反馈局部、旧上下文可靠时续接,避免重建背景。换方向、反复沿错误假设尝试、需要独立判断时开新委派。
|
|
72
|
+
`subagent_run op=follow_up` 只支持已结束的 claude-code/codex-cli/cursor-cli run,产生新的 runId(归属发起续接的频道);追加内容只写原契约的变化。目标不变、反馈局部、旧上下文可靠时续接,避免重建背景。换方向、反复沿错误假设尝试、需要独立判断时开新委派。
|
|
67
73
|
|
|
68
74
|
内置和 exec 不支持续接,带已有产出重新委派。条目 command/model/shell 改过时续接会拒绝,也应新开。明确阻塞、循环、崩溃、需纠偏或用户要求时才 cancel,耗时长不是理由。取消不再唤醒;用户 `/stop` 不会取消委派。
|
|
69
75
|
|
|
@@ -15,13 +15,13 @@ order: 50
|
|
|
15
15
|
{"command":"npm run test","async":true,"timeout":1800}
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
需要结果就保留默认通知;`notify:false` 只用于以后不需要结果的 fire-and-forget
|
|
18
|
+
需要结果就保留默认通知;`notify:false` 只用于以后不需要结果的 fire-and-forget 工作,task 步骤里的作业不能关通知。
|
|
19
19
|
|
|
20
20
|
## 派发与收尾
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
启动后先完成互不依赖的工作或派发,只剩等待时结束回合,不连续 poll 或建回访事件。DingTalk 和 Web API 的完成唤醒都由运行时负责;宿主的持续运行要求见 `runtime-orientation.md`。作业终态会带回退出码、耗时、输出尾部和完整输出路径。
|
|
23
23
|
|
|
24
|
-
**task
|
|
24
|
+
**task 步骤里**启动的作业自动绑定到本任务,只剩等待时结束回合,作业结算会叫醒任务;聊天里启动的作业不属于任何任务。带超时的作业也是任务等外部条件的传感器(见 `task-lead.md` 的“等待”)。
|
|
25
25
|
|
|
26
26
|
`job op=list` 用于需要当前状态的判断;`poll ids=[...]` 只适合一次短等待或取回结果,最多约 30 秒,仍在运行不代表失败。明确取消用 `cancel ids=[...]`,取消由你发起,不再发送完成唤醒。
|
|
27
27
|
|
|
@@ -29,4 +29,4 @@ order: 50
|
|
|
29
29
|
|
|
30
30
|
运行中作业按工位合计最多 5 个;满额先等待已有结果,只有工作已不需要才取消。daemon 重启后会恢复跟踪并补发完成通知。
|
|
31
31
|
|
|
32
|
-
重要产物让命令写入目标文件。stdout 保留
|
|
32
|
+
重要产物让命令写入目标文件。stdout 保留 7 天后清理;收到失败或 lost 时先查真实产物和错误,再决定是否重跑。
|