@oyasmi/pipiclaw 0.8.9 → 0.8.10-beta.1

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.
Files changed (66) hide show
  1. package/dist/agent/channel-runner.d.ts +1 -0
  2. package/dist/agent/channel-runner.js +6 -10
  3. package/dist/agent/maintenance-context.d.ts +0 -1
  4. package/dist/agent/maintenance-context.js +0 -7
  5. package/dist/agent/session-events.d.ts +1 -0
  6. package/dist/agent/session-events.js +10 -0
  7. package/dist/agent/types.d.ts +7 -0
  8. package/dist/agent/types.js +2 -0
  9. package/dist/index.d.ts +1 -1
  10. package/dist/memory/consolidation.js +0 -1
  11. package/dist/memory/extraction.d.ts +1 -7
  12. package/dist/memory/extraction.js +2 -46
  13. package/dist/memory/lifecycle.js +3 -3
  14. package/dist/memory/maintenance-gates.d.ts +4 -16
  15. package/dist/memory/maintenance-gates.js +11 -51
  16. package/dist/memory/maintenance-jobs.d.ts +3 -14
  17. package/dist/memory/maintenance-jobs.js +12 -103
  18. package/dist/memory/maintenance-state.d.ts +2 -6
  19. package/dist/memory/maintenance-state.js +14 -10
  20. package/dist/memory/promotion.d.ts +0 -22
  21. package/dist/memory/promotion.js +1 -8
  22. package/dist/memory/review-log.d.ts +1 -1
  23. package/dist/memory/scheduler.d.ts +1 -9
  24. package/dist/memory/scheduler.js +3 -15
  25. package/dist/memory/source-window.d.ts +2 -2
  26. package/dist/memory/task-digest.js +0 -2
  27. package/dist/models/utils.d.ts +5 -0
  28. package/dist/models/utils.js +10 -0
  29. package/dist/playbooks/task-closeout.md +2 -0
  30. package/dist/playbooks/task-delegation.md +3 -3
  31. package/dist/playbooks/task-driving.md +3 -3
  32. package/dist/playbooks/task-planning.md +6 -5
  33. package/dist/runtime/bootstrap.js +1 -4
  34. package/dist/runtime/task-commands.js +35 -16
  35. package/dist/runtime/task-driver.js +3 -1
  36. package/dist/settings.d.ts +4 -14
  37. package/dist/settings.js +2 -26
  38. package/dist/shared/task-ledger.d.ts +11 -0
  39. package/dist/shared/task-ledger.js +185 -3
  40. package/dist/subagents/discovery.d.ts +41 -7
  41. package/dist/subagents/discovery.js +74 -24
  42. package/dist/subagents/tool.d.ts +2 -7
  43. package/dist/subagents/tool.js +17 -19
  44. package/dist/tasks/control.d.ts +17 -6
  45. package/dist/tasks/control.js +42 -19
  46. package/dist/tasks/store.d.ts +1 -0
  47. package/dist/tasks/store.js +8 -0
  48. package/dist/tasks/transitions.d.ts +1 -1
  49. package/dist/tasks/transitions.js +1 -0
  50. package/dist/tools/registry.js +2 -0
  51. package/dist/tools/task-manage/create.js +2 -1
  52. package/dist/tools/task-manage/lifecycle.d.ts +7 -0
  53. package/dist/tools/task-manage/lifecycle.js +55 -14
  54. package/dist/tools/task-manage/schema.d.ts +2 -4
  55. package/dist/tools/task-manage/schema.js +14 -16
  56. package/dist/tools/task-manage/shared.d.ts +1 -0
  57. package/dist/tools/task-manage/shared.js +10 -9
  58. package/dist/tools/task-manage/types.d.ts +3 -1
  59. package/dist/tools/task-manage/verification.js +1 -2
  60. package/dist/tools/task-manage.js +4 -2
  61. package/examples/sub-agents/README.md +1 -1
  62. package/package.json +1 -1
  63. package/dist/memory/post-turn-review.d.ts +0 -43
  64. package/dist/memory/post-turn-review.js +0 -136
  65. package/dist/memory/promotion-signals.d.ts +0 -5
  66. package/dist/memory/promotion-signals.js +0 -33
@@ -7,11 +7,12 @@ import { invalidateTaskVerification } from "../../tasks/control.js";
7
7
  import { dependencyState, taskBodyHash } from "../../tasks/store.js";
8
8
  import { normalizeStoredStatus, resolveTaskTransition } from "../../tasks/transitions.js";
9
9
  import { RecoverableToolError } from "../tool-details.js";
10
- import { appendCompletionEvidence, applySet, cleanupTaskEvents, markdownValue, readTaskDocument, renderTaskFile, requiredField, tasksDir, unfinishedChildren, validateTaskRelations, } from "./shared.js";
10
+ import { appendCompletionEvidence, applySet, assertCostBudgetAvailable, cleanupTaskEvents, markdownValue, readTaskDocument, renderTaskFile, requiredField, tasksDir, unfinishedChildren, validateTaskRelations, } from "./shared.js";
11
11
  import { assertVerificationAttestationMatches } from "./verification.js";
12
12
  export async function setTask(options, request) {
13
13
  if (!request.id)
14
14
  throw new RecoverableToolError('action "set" requires an id.');
15
+ assertCostBudgetAvailable(options, request);
15
16
  const id = normalizeTaskId(request.id);
16
17
  const taskPath = join(tasksDir(options), `${id}.md`);
17
18
  const { fields, body } = await readTaskDocument(taskPath, id, request.control !== undefined);
@@ -47,15 +48,11 @@ export async function progressTask(options, request) {
47
48
  // that PASS/approval bind to, so it no longer invalidates verification or approval. A real
48
49
  // contract change (Goal/DoD/Manual/Verification) goes through write/edit and is caught by the
49
50
  // contract-hash checks in verify/done/approve.
50
- if (nextFields.control) {
51
- if (request.status === "waiting") {
52
- nextFields.control.lastOutcome = "blocked";
53
- }
54
- else if (request.control?.lastOutcome === undefined) {
55
- nextFields.control.lastOutcome = "progress";
56
- if (request.control?.blockedReason === undefined)
57
- nextFields.control.blockedReason = undefined;
58
- }
51
+ // Recording progress clears a stale "why it cannot proceed" note unless this call is parking
52
+ // the task (`waiting`) or states a new reason itself. `lastOutcome` is deliberately untouched:
53
+ // the runtime owns it (attempt claim/finish), so an action never has to keep it in sync.
54
+ if (nextFields.control && request.status !== "waiting" && request.control?.blockedReason === undefined) {
55
+ nextFields.control.blockedReason = undefined;
59
56
  }
60
57
  const nextBody = appendCurrentCycleNote(body, note);
61
58
  await writeFileAtomically(taskPath, renderTaskFile(nextFields, nextBody));
@@ -113,8 +110,16 @@ export async function doneTask(options, request) {
113
110
  }
114
111
  const bodyWithEvidence = appendCompletionEvidence(body, request);
115
112
  if (fields.control) {
116
- fields.control.lastOutcome = "verified";
117
113
  fields.control.blockedReason = undefined;
114
+ if (fields.control.verification.mode === "evidence") {
115
+ fields.control.verification = {
116
+ mode: "evidence",
117
+ status: "passed",
118
+ evidence: requiredField(request.evidence, "evidence", "done"),
119
+ bodyHash: taskBodyHash(bodyWithEvidence),
120
+ checkedAt: new Date().toISOString(),
121
+ };
122
+ }
118
123
  }
119
124
  // A recurring task (schedule frontmatter) sleeps in place until its next occurrence. The
120
125
  // wake is cleared here and refilled to the next cron occurrence by the single time rule
@@ -146,6 +151,44 @@ export async function doneTask(options, request) {
146
151
  notice: `任务 \`${id}\` 已完成(${disposition}${cleanup})。`,
147
152
  };
148
153
  }
154
+ /**
155
+ * Close one recurring occurrence without pretending its DoD was completed.
156
+ *
157
+ * This is the stateful counterpart of a silent/deduplicated wake: merely returning
158
+ * `[SILENT]` would leave the runtime-opened cycle active with no wake and cause retries.
159
+ */
160
+ export async function skipTask(options, request) {
161
+ if (!request.id)
162
+ throw new RecoverableToolError('action "skip" requires an id.');
163
+ const id = normalizeTaskId(request.id);
164
+ const reason = requiredField(request.reason, "reason", "skip");
165
+ const taskPath = join(tasksDir(options), `${id}.md`);
166
+ const { fields, body } = await readTaskDocument(taskPath, id);
167
+ resolveTaskTransition("skip", id, normalizeStoredStatus(fields.status));
168
+ if (!fields.schedule) {
169
+ throw new RecoverableToolError(`Task "${id}" is not recurring; use action "cancel" to abandon it or "done" after satisfying its DoD.`);
170
+ }
171
+ const children = await unfinishedChildren(options, id);
172
+ if (children.length > 0) {
173
+ throw new RecoverableToolError(`Task "${id}" still has unfinished child tasks: ${children.join(", ")}. Finish, cancel, or re-parent them before skipping this occurrence.`);
174
+ }
175
+ const skippedBody = appendCurrentCycleNote(body, `Skipped: ${reason}`);
176
+ if (fields.control) {
177
+ fields.control.blockedReason = undefined;
178
+ fields.control.verification = { mode: fields.control.verification.mode, status: "pending" };
179
+ }
180
+ await writeFileAtomically(taskPath, renderTaskFile({ ...fields, status: "done", wake: undefined }, skippedBody));
181
+ const { deleted } = await cleanupTaskEvents(options, id);
182
+ return {
183
+ action: "skip",
184
+ id,
185
+ path: taskPath,
186
+ status: "done",
187
+ archived: false,
188
+ deletedEvents: deleted,
189
+ notice: `任务 \`${id}\` 本周期已跳过并休眠至下一次计划唤醒;若无需通知用户,请回复 [SILENT]。`,
190
+ };
191
+ }
149
192
  export async function cancelTask(options, request) {
150
193
  if (!request.id)
151
194
  throw new RecoverableToolError('action "cancel" requires an id.');
@@ -159,10 +202,8 @@ export async function cancelTask(options, request) {
159
202
  if (children.length > 0) {
160
203
  throw new RecoverableToolError(`Task "${id}" still has unfinished child tasks: ${children.join(", ")}. Cancel or re-parent them first.`);
161
204
  }
162
- if (fields.control) {
163
- fields.control.lastOutcome = "blocked";
205
+ if (fields.control)
164
206
  fields.control.blockedReason = `Cancelled: ${reason}`;
165
- }
166
207
  const cancelledBody = `${body.replace(/\n+$/, "\n")}\n## Cancellation\n\n- Reason: ${markdownValue(reason)}\n`;
167
208
  await writeFileAtomically(taskPath, renderTaskFile({ ...fields, status: "cancelled", wake: undefined }, cancelledBody));
168
209
  const { deleted } = await cleanupTaskEvents(options, id);
@@ -3,7 +3,7 @@ import type { TaskManageAction } from "./types.js";
3
3
  export declare const SETTABLE_STATUSES: readonly ["active", "waiting", "paused"];
4
4
  export declare const taskManageSchema: Type.TObject<{
5
5
  label: Type.TString;
6
- action: Type.TUnion<[Type.TLiteral<"create">, Type.TLiteral<"progress">, Type.TLiteral<"set">, Type.TLiteral<"verify">, Type.TLiteral<"done">, Type.TLiteral<"cancel">, Type.TLiteral<"candidate">, Type.TLiteral<"list">]>;
6
+ action: Type.TUnion<[Type.TLiteral<"create">, Type.TLiteral<"progress">, Type.TLiteral<"set">, Type.TLiteral<"verify">, Type.TLiteral<"done">, Type.TLiteral<"skip">, Type.TLiteral<"cancel">, Type.TLiteral<"candidate">, Type.TLiteral<"list">]>;
7
7
  id: Type.TOptional<Type.TString>;
8
8
  title: Type.TOptional<Type.TString>;
9
9
  goal: Type.TOptional<Type.TString>;
@@ -14,12 +14,10 @@ export declare const taskManageSchema: Type.TObject<{
14
14
  priority: Type.TOptional<Type.TUnion<[Type.TLiteral<"low">, Type.TLiteral<"normal">, Type.TLiteral<"high">, Type.TLiteral<"critical">]>>;
15
15
  deadline: Type.TOptional<Type.TString>;
16
16
  nextAction: Type.TOptional<Type.TString>;
17
- lastOutcome: Type.TOptional<Type.TUnion<[Type.TLiteral<"pending">, Type.TLiteral<"running">, Type.TLiteral<"progress">, Type.TLiteral<"blocked">, Type.TLiteral<"failed">, Type.TLiteral<"verified">]>>;
18
17
  blockedReason: Type.TOptional<Type.TString>;
19
18
  parent: Type.TOptional<Type.TString>;
20
19
  dependsOn: Type.TOptional<Type.TArray<Type.TString>>;
21
- isolation: Type.TOptional<Type.TUnion<[Type.TLiteral<"shared">, Type.TLiteral<"worktree">]>>;
22
- sideEffects: Type.TOptional<Type.TUnion<[Type.TLiteral<"read-only">, Type.TLiteral<"workspace">, Type.TLiteral<"external">]>>;
20
+ sideEffects: Type.TOptional<Type.TUnion<[Type.TLiteral<"workspace">, Type.TLiteral<"external">]>>;
23
21
  externalApproval: Type.TOptional<Type.TUnion<[Type.TLiteral<"not-required">, Type.TLiteral<"required">]>>;
24
22
  maxAttempts: Type.TOptional<Type.TInteger>;
25
23
  maxTokens: Type.TOptional<Type.TNumber>;
@@ -6,26 +6,22 @@ const taskControlSchema = Type.Object({
6
6
  priority: Type.Optional(Type.Union([Type.Literal("low"), Type.Literal("normal"), Type.Literal("high"), Type.Literal("critical")])),
7
7
  deadline: Type.Optional(Type.String({ description: "ISO8601 deadline; empty string clears it." })),
8
8
  nextAction: Type.Optional(Type.String({ description: "Concrete next executable step; empty string clears it." })),
9
- lastOutcome: Type.Optional(Type.Union([
10
- Type.Literal("pending"),
11
- Type.Literal("running"),
12
- Type.Literal("progress"),
13
- Type.Literal("blocked"),
14
- Type.Literal("failed"),
15
- Type.Literal("verified"),
16
- ])),
17
9
  blockedReason: Type.Optional(Type.String({ description: "Why work cannot currently proceed; empty clears it." })),
18
10
  parent: Type.Optional(Type.String({ description: "Parent task id; empty clears it." })),
19
11
  dependsOn: Type.Optional(Type.Array(Type.String(), { description: "Task ids that must be done first." })),
20
- isolation: Type.Optional(Type.Union([Type.Literal("shared"), Type.Literal("worktree")])),
21
- sideEffects: Type.Optional(Type.Union([Type.Literal("read-only"), Type.Literal("workspace"), Type.Literal("external")])),
12
+ sideEffects: Type.Optional(Type.Union([Type.Literal("workspace"), Type.Literal("external")], {
13
+ description: '"external" (sending, publishing, deploying, changing an outside system) requires user approval via "/tasks approve" before done.',
14
+ })),
22
15
  externalApproval: Type.Optional(Type.Union([Type.Literal("not-required"), Type.Literal("required")], {
23
16
  description: 'External approval can only be granted by a user with "/tasks approve <id>".',
24
17
  })),
25
18
  maxAttempts: Type.Optional(Type.Integer({ minimum: 1 })),
26
- maxTokens: Type.Optional(Type.Number({ minimum: 0, description: "0 clears this budget." })),
27
- maxCostUsd: Type.Optional(Type.Number({ minimum: 0, description: "0 clears this budget." })),
28
- maxWallTimeMinutes: Type.Optional(Type.Number({ minimum: 0, description: "0 clears this budget." })),
19
+ maxTokens: Type.Optional(Type.Number({ minimum: 0, description: "Per-cycle boundary budget; 0 clears it." })),
20
+ maxCostUsd: Type.Optional(Type.Number({
21
+ minimum: 0,
22
+ description: "Per-cycle boundary budget; requires current-model pricing metadata; 0 clears it.",
23
+ })),
24
+ maxWallTimeMinutes: Type.Optional(Type.Number({ minimum: 0, description: "Per-cycle boundary budget; 0 clears it." })),
29
25
  verificationMode: Type.Optional(Type.Union([Type.Literal("evidence"), Type.Literal("independent")], {
30
26
  description: 'On create, defaults to "evidence" (maker self-checks the DoD against concrete evidence). Set "independent" only when the task produces a checkable artifact (code, config, a runnable command) that a separate read-only verifier sub-agent can inspect — for research/writing/reminder-style tasks, "evidence" is cheaper and just as trustworthy.',
31
27
  })),
@@ -40,11 +36,12 @@ export const taskManageSchema = Type.Object({
40
36
  Type.Literal("set"),
41
37
  Type.Literal("verify"),
42
38
  Type.Literal("done"),
39
+ Type.Literal("skip"),
43
40
  Type.Literal("cancel"),
44
41
  Type.Literal("candidate"),
45
42
  Type.Literal("list"),
46
43
  ], {
47
- description: '"create" writes a governed task; "progress" atomically checkpoints work; "candidate" requests independent verification; "set" repairs metadata; "verify" imports an independent verifier attestation; "done" closes verified work; "cancel" closes abandoned work; "list" returns tasks. Recurring cycles are reopened automatically by the runtime.',
44
+ description: '"create" writes a governed task; "progress" atomically checkpoints work; "candidate" requests independent verification; "set" repairs metadata; "verify" imports an independent verifier attestation; "done" closes verified work; "skip" closes one recurring occurrence without claiming completion; "cancel" closes abandoned work; "list" returns tasks. Recurring cycles are reopened automatically by the runtime.',
48
45
  }),
49
46
  id: Type.Optional(Type.String({ description: "Task id (filename without .md). Required for create/progress/set/done." })),
50
47
  title: Type.Optional(Type.String({ description: "Required for create: task title used as the H1 heading." })),
@@ -73,7 +70,7 @@ export const taskManageSchema = Type.Object({
73
70
  description: "Required for done: verification evidence (tests, commands, review result, external confirmation, or a clear not-run reason).",
74
71
  })),
75
72
  residualRisk: Type.Optional(Type.String({ description: "Optional for done: remaining risk or follow-up note." })),
76
- reason: Type.Optional(Type.String({ description: "Required for cancel: why the task was abandoned." })),
73
+ reason: Type.Optional(Type.String({ description: "Required for skip/cancel: why this occurrence was skipped or the task abandoned." })),
77
74
  });
78
75
  export function parseAction(action) {
79
76
  if (action === "create" ||
@@ -82,9 +79,10 @@ export function parseAction(action) {
82
79
  action === "set" ||
83
80
  action === "verify" ||
84
81
  action === "done" ||
82
+ action === "skip" ||
85
83
  action === "cancel" ||
86
84
  action === "list") {
87
85
  return action;
88
86
  }
89
- throw new RecoverableToolError("Unsupported task action. Use create, progress, candidate, set, verify, done, cancel, or list.");
87
+ throw new RecoverableToolError("Unsupported task action. Use create, progress, candidate, set, verify, done, skip, cancel, or list.");
90
88
  }
@@ -1,5 +1,6 @@
1
1
  import type { TaskFields, TaskManageRequest, TaskManageToolOptions } from "./types.js";
2
2
  export declare function tasksDir(options: TaskManageToolOptions): string;
3
+ export declare function assertCostBudgetAvailable(options: TaskManageToolOptions, request: TaskManageRequest): void;
3
4
  export declare function eventsDir(options: TaskManageToolOptions): string;
4
5
  export declare function renderTaskFile(fields: TaskFields, body: string): string;
5
6
  export declare function requiredField(value: string | undefined, field: string, action: string): string;
@@ -3,7 +3,7 @@ import { readdir, readFile, unlink } from "node:fs/promises";
3
3
  import { join } from "node:path";
4
4
  import { parseScheduledEventContent } from "../../runtime/events.js";
5
5
  import { taskEventPrefix } from "../../shared/task-events.js";
6
- import { parseTaskFrontmatter, readActiveTasks, renderStandardTaskBody, renderTaskDocument, taskBody, } from "../../shared/task-ledger.js";
6
+ import { parseTaskFrontmatter, readActiveTasks, renderStandardTaskBody, renderTaskDocument, taskBody, upsertCurrentCycleCompletionEvidence, } from "../../shared/task-ledger.js";
7
7
  import { nextTaskWake, validateTaskSchedule } from "../../shared/task-schedule.js";
8
8
  import { applyTaskControlPatch, createDefaultTaskControl } from "../../tasks/control.js";
9
9
  import { readStoredTask } from "../../tasks/store.js";
@@ -13,6 +13,13 @@ import { SETTABLE_STATUSES } from "./schema.js";
13
13
  export function tasksDir(options) {
14
14
  return join(options.channelDir, "tasks");
15
15
  }
16
+ export function assertCostBudgetAvailable(options, request) {
17
+ if (request.control?.maxCostUsd !== undefined &&
18
+ request.control.maxCostUsd > 0 &&
19
+ options.costTrackingAvailable === false) {
20
+ throw new RecoverableToolError("maxCostUsd requires model pricing, but the current model has no price metadata. Configure model pricing or use maxTokens instead.");
21
+ }
22
+ }
16
23
  export function eventsDir(options) {
17
24
  return join(options.workspaceDir, "events");
18
25
  }
@@ -38,18 +45,12 @@ export function markdownValue(value) {
38
45
  export function appendCompletionEvidence(body, request) {
39
46
  const summary = requireNonEmpty(request.summary, "summary");
40
47
  const evidence = requireNonEmpty(request.evidence, "evidence");
41
- const lines = [
42
- "## Completion Evidence",
43
- "",
44
- `- Summary: ${markdownValue(summary)}`,
45
- `- Evidence: ${markdownValue(evidence)}`,
46
- ];
48
+ const lines = [`- Summary: ${markdownValue(summary)}`, `- Evidence: ${markdownValue(evidence)}`];
47
49
  const residualRisk = request.residualRisk?.trim();
48
50
  if (residualRisk) {
49
51
  lines.push(`- Residual risk: ${markdownValue(residualRisk)}`);
50
52
  }
51
- const normalizedBody = body.endsWith("\n") ? body.replace(/\n+$/, "\n") : `${body}\n`;
52
- return `${normalizedBody}\n${lines.join("\n")}\n`;
53
+ return upsertCurrentCycleCompletionEvidence(body, lines);
53
54
  }
54
55
  function normalizeCreateStatus(status) {
55
56
  if (status === undefined)
@@ -1,5 +1,5 @@
1
1
  import type { TaskControl, TaskControlPatch } from "../../tasks/control.js";
2
- export type TaskManageAction = "create" | "progress" | "candidate" | "set" | "verify" | "done" | "cancel" | "list";
2
+ export type TaskManageAction = "create" | "progress" | "candidate" | "set" | "verify" | "done" | "skip" | "cancel" | "list";
3
3
  export interface TaskManageResult {
4
4
  action: TaskManageAction;
5
5
  id?: string;
@@ -43,6 +43,8 @@ export interface TaskManageToolOptions {
43
43
  channelId: string;
44
44
  /** Project checkout whose artifact state an independent verifier binds to. */
45
45
  workingDirectory?: string;
46
+ /** Whether the current main model has usable price metadata for maxCostUsd. */
47
+ costTrackingAvailable?: boolean;
46
48
  }
47
49
  export interface TaskFields {
48
50
  status: string;
@@ -27,7 +27,6 @@ export async function candidateTask(options, request) {
27
27
  }
28
28
  const control = fields.control ?? createDefaultTaskControl("independent");
29
29
  control.verification = { mode: "independent", status: "pending" };
30
- control.lastOutcome = "progress";
31
30
  control.blockedReason = undefined;
32
31
  control.nextAction = "Run a purpose=verify sub-agent and import its attestation.";
33
32
  const nextBody = appendCurrentCycleNote(body, note);
@@ -77,7 +76,7 @@ export async function verifyTask(options, request) {
77
76
  subjectHash: attestation.subjectHash,
78
77
  checkedAt: attestation.checkedAt,
79
78
  };
80
- control.lastOutcome = attestation.verdict === "pass" ? "verified" : "failed";
79
+ // The verdict lives in `control.verification`; `lastOutcome` stays runtime-owned telemetry.
81
80
  control.blockedReason = attestation.verdict === "fail" ? attestation.evidence : undefined;
82
81
  task.fields.control = control;
83
82
  await writeFileAtomically(task.path, renderTaskFile(task.fields, task.body));
@@ -1,5 +1,5 @@
1
1
  import { createTask } from "./task-manage/create.js";
2
- import { cancelTask, doneTask, listTasks, progressTask, setTask } from "./task-manage/lifecycle.js";
2
+ import { cancelTask, doneTask, listTasks, progressTask, setTask, skipTask } from "./task-manage/lifecycle.js";
3
3
  import { parseAction, taskManageSchema } from "./task-manage/schema.js";
4
4
  import { candidateTask, verifyTask } from "./task-manage/verification.js";
5
5
  /**
@@ -22,6 +22,8 @@ export async function manageTask(options, request) {
22
22
  return verifyTask(options, request);
23
23
  case "done":
24
24
  return doneTask(options, request);
25
+ case "skip":
26
+ return skipTask(options, request);
25
27
  case "cancel":
26
28
  return cancelTask(options, request);
27
29
  case "list":
@@ -33,7 +35,7 @@ export function createTaskManageTool(options) {
33
35
  name: "task_manage",
34
36
  label: "task_manage",
35
37
  description: "Manage governed persistent tasks: create, atomically checkpoint progress/control state, import an independent " +
36
- "verifier attestation, complete verified work, cancel abandoned work, or list tasks. Use progress for routine " +
38
+ "verifier attestation, complete verified work, skip one recurring occurrence, cancel abandoned work, or list tasks. Use progress for routine " +
37
39
  "end-of-turn checkpoints; use write/edit only for substantial Goal/DoD/Manual/Verification changes.",
38
40
  parameters: taskManageSchema,
39
41
  execute: async (_toolCallId, args) => {
@@ -19,7 +19,7 @@ cp examples/sub-agents/{explorer,researcher,reviewer,verifier,git-committer}.md
19
19
  - `description` 会进入主代理的子代理目录,必须写清楚“何时使用、何时不用、调用前提和是否修改状态”。
20
20
  - 正文是子代理的 system prompt,应明确职责、禁止事项、证据标准、停止条件和输出契约。
21
21
  - 子代理默认看不到主会话。委派时的 `task` 仍须包含目标、范围、相关路径、约束、验收方法和期望返回格式,不能只写“按上文处理”。
22
- - `thinkingLevel`、上下文模式和执行预算在这些模板中显式配置,方便审查和按成本调整;不要依赖隐藏默认值。
22
+ - `thinkingLevel`、上下文模式和执行预算在这些模板中显式配置,方便审查和按成本调整;不要依赖隐藏默认值。这四个数值预算只在 frontmatter 里精确设置——调用时主代理只能选 `effort` 的 quick/standard/deep 三档,传了就整组替换这里的数值。
23
23
  - `tools` 只是工具白名单,不等同于只读沙箱。拥有 `bash` 的角色仍须遵守正文和应用级 `security.json` 的限制。
24
24
  - `git-committer` 只有在任务明确转述用户要求 push 时才能推送;创建了 commit 不代表自动获得 push 授权。
25
25
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.8.9",
3
+ "version": "0.8.10-beta.1",
4
4
  "description": "An AI assistant runtime for coding and team workflows, with DingTalk AI Cards, sub-agents, memory, and scheduled events.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,43 +0,0 @@
1
- import type { AgentMessage } from "@earendil-works/pi-agent-core";
2
- import type { Api, Model } from "@earendil-works/pi-ai";
3
- import { parseMemoryExtractionResult } from "./extraction.js";
4
- import { type PostTurnReviewResult } from "./promotion.js";
5
- export interface PostTurnReviewOptions {
6
- channelId: string;
7
- channelDir: string;
8
- workspaceDir: string;
9
- messages: AgentMessage[];
10
- model: Model<Api>;
11
- resolveApiKey: (model: Model<Api>) => Promise<string>;
12
- timeoutMs: number;
13
- autoWriteChannelMemory: boolean;
14
- autoWriteWorkspaceSkills: boolean;
15
- minMemoryAutoWriteConfidence: number;
16
- minSkillAutoWriteConfidence: number;
17
- loadedSkills: Array<{
18
- name: string;
19
- description?: string;
20
- }>;
21
- emitNotice?: (notice: string) => Promise<void>;
22
- refreshWorkspaceResources?: () => Promise<void>;
23
- sourceEntryIds?: string[];
24
- suppressAutomaticWrites?: boolean;
25
- correlationId?: string;
26
- }
27
- export interface PostTurnReviewApplyResult {
28
- actions: unknown[];
29
- suggestions: unknown[];
30
- skipped: unknown[];
31
- notices: string[];
32
- }
33
- export type PostTurnReviewRunResult = {
34
- status: "applied" | "empty";
35
- result: PostTurnReviewApplyResult;
36
- } | {
37
- status: "failed";
38
- error: string;
39
- };
40
- /** Re-exported so existing callers and tests keep one parser for the shared schema. */
41
- export declare const parsePostTurnReviewResult: typeof parseMemoryExtractionResult;
42
- export declare function applyPostTurnReviewResult(options: PostTurnReviewOptions, review: PostTurnReviewResult): Promise<PostTurnReviewApplyResult>;
43
- export declare function runPostTurnReview(options: PostTurnReviewOptions): Promise<PostTurnReviewRunResult>;
@@ -1,136 +0,0 @@
1
- import { errorMessage } from "../shared/text-utils.js";
2
- import { manageWorkspaceSkill } from "../tools/skill-manage.js";
3
- import { parseMemoryExtractionResult, runMemoryExtraction, toMemoryOp } from "./extraction.js";
4
- import { applyChannelMemoryOps } from "./files.js";
5
- import { containsSecret } from "./policy.js";
6
- import { shouldAutoWriteMemory, shouldAutoWriteSkill, } from "./promotion.js";
7
- import { appendMemoryReviewLog } from "./review-log.js";
8
- const POST_TURN_TRANSCRIPT_MAX_CHARS = 22_000;
9
- /** Re-exported so existing callers and tests keep one parser for the shared schema. */
10
- export const parsePostTurnReviewResult = parseMemoryExtractionResult;
11
- async function runPostTurnReviewWorker(options) {
12
- return runMemoryExtraction({
13
- name: "memory-post-turn-review",
14
- channelId: options.channelId,
15
- channelDir: options.channelDir,
16
- messages: options.messages,
17
- model: options.model,
18
- resolveApiKey: options.resolveApiKey,
19
- timeoutMs: options.timeoutMs,
20
- transcriptMaxChars: POST_TURN_TRANSCRIPT_MAX_CHARS,
21
- // The growth review is the only path that proposes procedural memory, and the only one
22
- // that does not summarize into HISTORY.md.
23
- includeHistoryBlock: false,
24
- includeSkills: true,
25
- loadedSkills: options.loadedSkills,
26
- usageContext: { channelId: options.channelId, correlationId: options.correlationId },
27
- });
28
- }
29
- async function applyMemoryCandidate(options, candidate, result, timestamp) {
30
- if (options.suppressAutomaticWrites ||
31
- !options.autoWriteChannelMemory ||
32
- !shouldAutoWriteMemory(candidate, options.minMemoryAutoWriteConfidence)) {
33
- result.suggestions.push({ type: "memory", candidate });
34
- return;
35
- }
36
- if (candidate.content && containsSecret(candidate.content)) {
37
- result.skipped.push({ type: "memory", candidate: { ...candidate, content: "[REDACTED]" }, reason: "secret" });
38
- return;
39
- }
40
- const op = toMemoryOp(candidate, {
41
- sourceEntryIds: options.sourceEntryIds,
42
- correlationId: options.correlationId,
43
- });
44
- const applied = await applyChannelMemoryOps(options.channelDir, [op], timestamp);
45
- if (applied.blockedByPolicy > 0 || applied.blockedByTombstone > 0) {
46
- result.skipped.push({ type: "memory", entry: candidate.targetId, reason: "blocked by memory policy" });
47
- return;
48
- }
49
- const action = { target: "MEMORY.md", action: candidate.op, entry: candidate.targetId, reason: candidate.reason };
50
- result.actions.push(action);
51
- result.notices.push("已沉淀:更新 channel memory。");
52
- }
53
- async function applySkillCandidate(options, candidate, result) {
54
- if (options.suppressAutomaticWrites ||
55
- !options.autoWriteWorkspaceSkills ||
56
- !shouldAutoWriteSkill(candidate, options.minSkillAutoWriteConfidence)) {
57
- result.suggestions.push({ type: "skill", candidate });
58
- return;
59
- }
60
- try {
61
- const managed = await manageWorkspaceSkill({ workspaceDir: options.workspaceDir }, {
62
- action: candidate.action,
63
- name: candidate.name,
64
- content: candidate.content,
65
- filePath: candidate.filePath,
66
- find: candidate.find,
67
- replace: candidate.replace,
68
- });
69
- result.actions.push({ target: "workspace-skill", ...managed, reason: candidate.reason });
70
- result.notices.push(managed.notice);
71
- if (managed.requiresResourceRefresh && options.refreshWorkspaceResources) {
72
- await options.refreshWorkspaceResources();
73
- }
74
- }
75
- catch (error) {
76
- const message = errorMessage(error);
77
- result.skipped.push({ type: "skill", candidate, reason: message });
78
- result.suggestions.push({ type: "skill", candidate, blockedReason: message });
79
- }
80
- }
81
- export async function applyPostTurnReviewResult(options, review) {
82
- const timestamp = new Date().toISOString();
83
- const result = {
84
- actions: [],
85
- suggestions: [],
86
- skipped: [],
87
- notices: [],
88
- };
89
- for (const candidate of review.memoryOps) {
90
- await applyMemoryCandidate(options, candidate, result, timestamp);
91
- }
92
- for (const candidate of review.skillCandidates) {
93
- await applySkillCandidate(options, candidate, result);
94
- }
95
- for (const discarded of review.discarded) {
96
- result.skipped.push({ type: "discarded", ...discarded });
97
- }
98
- await appendMemoryReviewLog(options.channelDir, {
99
- timestamp,
100
- channelId: options.channelId,
101
- reason: "post-turn",
102
- correlationId: options.correlationId,
103
- candidates: [...review.memoryOps, ...review.skillCandidates],
104
- actions: result.actions,
105
- suggestions: result.suggestions,
106
- skipped: result.skipped,
107
- });
108
- for (const notice of Array.from(new Set(result.notices))) {
109
- try {
110
- await options.emitNotice?.(notice);
111
- }
112
- catch {
113
- /* best effort */
114
- }
115
- }
116
- return result;
117
- }
118
- export async function runPostTurnReview(options) {
119
- try {
120
- const review = await runPostTurnReviewWorker(options);
121
- const result = await applyPostTurnReviewResult(options, review);
122
- return { status: result.actions.length > 0 ? "applied" : "empty", result };
123
- }
124
- catch (error) {
125
- const message = errorMessage(error);
126
- await appendMemoryReviewLog(options.channelDir, {
127
- timestamp: new Date().toISOString(),
128
- channelId: options.channelId,
129
- reason: "post-turn",
130
- correlationId: options.correlationId,
131
- error: message,
132
- skipped: [{ target: "post-turn-review", reason: "failed" }],
133
- });
134
- return { status: "failed", error: message };
135
- }
136
- }
@@ -1,5 +0,0 @@
1
- export interface PromotionSignalScanResult {
2
- hasSignal: boolean;
3
- matchedSignals: string[];
4
- }
5
- export declare function scanPromotionSignals(text: string): PromotionSignalScanResult;
@@ -1,33 +0,0 @@
1
- const PROMOTION_SIGNAL_PATTERNS = [
2
- /以后/,
3
- /默认/,
4
- /记住/,
5
- /偏好/,
6
- /决定/,
7
- /采用/,
8
- /不再/,
9
- /流程/,
10
- /步骤/,
11
- /规范/,
12
- /checklist/i,
13
- /每次/,
14
- /后续/,
15
- /待办/,
16
- /需要跟进/,
17
- /\bprefer(?:s|red|ence)?\b/i,
18
- /\bdefault\b/i,
19
- /\bremember\b/i,
20
- /\bdecision\b/i,
21
- /\badopt\b/i,
22
- /\bworkflow\b/i,
23
- /\bprocess\b/i,
24
- /\bnext steps?\b/i,
25
- /\bfollow[- ]?up\b/i,
26
- ];
27
- export function scanPromotionSignals(text) {
28
- const matchedSignals = PROMOTION_SIGNAL_PATTERNS.filter((pattern) => pattern.test(text)).map((pattern) => pattern.toString());
29
- return {
30
- hasSignal: matchedSignals.length > 0,
31
- matchedSignals,
32
- };
33
- }