@ai-setting/roy-task-plugin 0.7.10 → 0.7.12

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/cli.js CHANGED
@@ -456,6 +456,62 @@ import {
456
456
  TASK_DISCIPLINE_LIFECYCLE,
457
457
  TASK_DISCIPLINE_OPERATION
458
458
  } from "@ai-setting/roy-agent-core/env/task/prompt";
459
+
460
+ // ../agent/src/trim-permission.ts
461
+ var TRIM_RULES = Object.freeze([
462
+ {
463
+ name: "complete-禁止调用",
464
+ match: (line) => /不要调用/.test(line) && /task_complete/.test(line) && /权限/.test(line)
465
+ },
466
+ {
467
+ name: "track-禁止置终态",
468
+ match: (line) => /终态由验收方落/.test(line) || /不要/.test(line) && /置为/.test(line) && /completed/.test(line)
469
+ },
470
+ {
471
+ name: "lifecycle-角色二分标题",
472
+ match: (line) => /收尾分两种角色/.test(line),
473
+ replace: () => "6. COMPLETE — 收尾:用 `task_complete` after item-by-item verification",
474
+ dropFollowing: 5
475
+ },
476
+ {
477
+ name: "complete-标题角色限定",
478
+ match: (line) => /^#{1,6}\s/.test(line) && /仅验收方适用/.test(line),
479
+ replace: (line) => line.replace(/\s*(\*\*仅验收方适用\*\*)/, "")
480
+ },
481
+ {
482
+ name: "complete-角色作用域引用块",
483
+ match: (line) => /角色作用域/.test(line) || /若你是/.test(line) && /执行方/.test(line) && /权限/.test(line) || /你的收尾动作是/.test(line) && /验收由主智能体负责/.test(line)
484
+ }
485
+ ]);
486
+ function trimTaskCompletePermissionText(text) {
487
+ if (!text)
488
+ return text;
489
+ const lines = text.split(`
490
+ `);
491
+ const out = [];
492
+ for (let i = 0;i < lines.length; i++) {
493
+ const line = lines[i];
494
+ const rule = TRIM_RULES.find((r) => r.match(line));
495
+ if (!rule) {
496
+ out.push(line);
497
+ continue;
498
+ }
499
+ if (rule.replace)
500
+ out.push(rule.replace(line));
501
+ const drop = rule.dropFollowing ?? 0;
502
+ for (let k = 0;k < drop && i + 1 < lines.length; k++) {
503
+ i++;
504
+ }
505
+ }
506
+ return out.join(`
507
+ `);
508
+ }
509
+
510
+ // ../agent/src/roy-prompt-core.ts
511
+ var TRIMMED_LIFECYCLE = trimTaskCompletePermissionText(TASK_DISCIPLINE_LIFECYCLE);
512
+ var TRIMMED_GOALS = trimTaskCompletePermissionText(TASK_DISCIPLINE_GOALS);
513
+ var TRIMMED_OPERATION = trimTaskCompletePermissionText(TASK_DISCIPLINE_OPERATION);
514
+ var TRIMMED_COMPLETE = trimTaskCompletePermissionText(TASK_DISCIPLINE_COMPLETE);
459
515
  var ROY_PROMPT_COMMON = `# Roy — task-first-class-citizen agent
460
516
 
461
517
  You are **Roy**, an agent whose defining rule is simple:
@@ -465,16 +521,16 @@ You are **Roy**, an agent whose defining rule is simple:
465
521
  You are a worker agent: you act through the tools, and your output is what
466
522
  the user sees.
467
523
 
468
- ${TASK_DISCIPLINE_LIFECYCLE}
524
+ ${TRIMMED_LIFECYCLE}
469
525
 
470
- ${TASK_DISCIPLINE_GOALS}
526
+ ${TRIMMED_GOALS}
471
527
 
472
528
  The tool returns a **numeric task id** — that number is your handle for the
473
529
  rest of the conversation.
474
530
 
475
- ${TASK_DISCIPLINE_OPERATION}
531
+ ${TRIMMED_OPERATION}
476
532
 
477
- ${TASK_DISCIPLINE_COMPLETE}
533
+ ${TRIMMED_COMPLETE}
478
534
 
479
535
  #### Several deliverables in one field
480
536
  \`deliverable_storage_path\` may name **multiple paths**, space-separated
@@ -510,7 +566,78 @@ if it is not in the task store, it is not tracked.
510
566
  - Report the task id and its state whenever you finish a step.
511
567
  - If a task is blocked, mark it (\`task_update(status="paused")\`) and record a
512
568
  \`problem\` milestone explaining the blocker instead of going silent.`;
569
+ var ROY_PROMPT_CLAUDE_DISCIPLINE = `
570
+ ## Milestone discipline (Claude runtime)
571
+
572
+ The task card renders **your** milestones. A run that calls tools but
573
+ records nothing leaves the card empty, and the user sees a failed task with
574
+ no trace of the work. Measured failure: 67 tool calls, 2 automatic hooks,
575
+ 0 real milestones, then the run was killed and the card froze in a failed
576
+ state. Read this section as binding.
577
+
578
+ ### Record per stage, immediately
579
+
580
+ - Every time you finish a **阶段** — a sub-goal, an investigation, a file
581
+ written, a test that passed, a decision, a blocker — call
582
+ \`task_operation_create\` **立即**, in that same turn.
583
+ - Do **not** batch. A milestone written after six tool calls reads as
584
+ retrospective filler; the point is that the card shows the work *as it
585
+ happens*.
586
+ - If a single tool call produced a stage-level result, that call is
587
+ followed by exactly one milestone — no more, no less.
588
+ - Long-running work (> 5 minutes) still records as it goes, exactly as the
589
+ shared contract requires.
590
+
591
+ ### The shape of a milestone
592
+
593
+ \`milestone_title\` — a **短语**, ≤ 20 字, verb-first, naming what was
594
+ locked down. Not a sentence, not a label like "progress".
595
+
596
+ - ✅ \`泄漏源锁定\`, \`测试全绿\`, \`缓存层落地\`, \`回滚路径确认\`
597
+ - ❌ \`进度更新\`, \`继续处理\`, \`做了一些工作\`, \`阶段完成\`
598
+
599
+ Those ❌ examples are **空壳** milestones: they carry no information about
600
+ what changed, so they are worse than useless — they make the card look
601
+ busy while hiding the work. Never write a title like those.
602
+
603
+ \`milestone_description\` — a dense **技术叙述** of the state you reached.
604
+ Name the concrete things, so a reader can reconstruct the work without
605
+ re-running it:
606
+
607
+ - the **文件路径** you wrote or read
608
+ - the **函数名** / symbol you changed or traced
609
+ - the **命令** you ran and its result
610
+ - the numbers: pass/fail counts, line counts, exit codes, sizes, timings
611
+
612
+ Example (title + description):
613
+
614
+ \`\`\`
615
+ milestone_title: "泄漏源锁定"
616
+ milestone_description: "test_workflow_error_handling 的生成器被放弃 → registry 由 GC 延迟回收;泄漏路径锁定在 WorkflowRegistry.dispose(),packages/core/src/registry.ts:412"
617
+ \`\`\`
618
+
619
+ \`process_description\` (100–500 字符) — how it was reached (**如何达到**):
620
+ the strategy and the tool steps. It must **not** repeat the description —
621
+ the description is the *state*, the process is the *route*. Repeating
622
+ one in the other is a second ❌.
623
+
624
+ ### Tool-call budget
625
+
626
+ If you have made several **连续的工具调用** without recording a
627
+ milestone, the next action is \`task_operation_create\` — not another
628
+ tool call. Two, three tool calls in a row is normal exploration; a long
629
+ streak without a milestone is the failure mode measured above. When the
630
+ streak is getting long, write down what you have already established, then
631
+ continue.
632
+
633
+ ### What good looks like
634
+
635
+ For a task with 3–4 stages you should end up with **3–4 hand-written
636
+ milestones** in the card — not 2 automatic hooks and nothing else. The
637
+ automatic \`收到消息\` / \`Task 完成\` hooks are not a substitute for yours.
638
+ `;
513
639
  var ROY_PROMPT_CLAUDE_TAIL = `
640
+ ${ROY_PROMPT_CLAUDE_DISCIPLINE}
514
641
  ## Tool surface on Claude Code
515
642
 
516
643
  The \`task_*\` tools are served by the **\`roy-task\` MCP server** this runtime
@@ -1084,6 +1211,7 @@ function errMsg(err) {
1084
1211
 
1085
1212
  // ../../../packages/cli/src/daemon/discipline.ts
1086
1213
  import { TASK_DISCIPLINE_PROMPT } from "@ai-setting/roy-agent-core/env/task/prompt";
1214
+ var PLUGIN_TASK_DISCIPLINE_PROMPT = trimTaskCompletePermissionText(TASK_DISCIPLINE_PROMPT);
1087
1215
  var RUNTIMES_WITH_AGENT_SYSTEM_PROMPT = Object.freeze([
1088
1216
  "opencode",
1089
1217
  "claude"
@@ -1152,7 +1280,7 @@ function buildCodexArgs(input) {
1152
1280
  return args;
1153
1281
  }
1154
1282
  function withDiscipline(prompt, systemPrompt) {
1155
- const contract = systemPrompt === undefined ? TASK_DISCIPLINE_PROMPT : systemPrompt;
1283
+ const contract = systemPrompt === undefined ? PLUGIN_TASK_DISCIPLINE_PROMPT : systemPrompt;
1156
1284
  if (!contract)
1157
1285
  return prompt;
1158
1286
  if (prompt.includes(contract))
@@ -1692,7 +1820,7 @@ function buildDispatchPrompt(input) {
1692
1820
  ""
1693
1821
  ];
1694
1822
  if (needsDispatchInjection(input.runtime)) {
1695
- parts.push("## 任务纪律(Task #4889 — 来自 roy-agent core 单一真相源)", "", TASK_DISCIPLINE_PROMPT, "");
1823
+ parts.push("## 任务纪律(Task #4889 — 来自 roy-agent core 单一真相源)", "", PLUGIN_TASK_DISCIPLINE_PROMPT, "");
1696
1824
  }
1697
1825
  parts.push("## 硬性规则", "", "1. **不要**自己调用 `lark-cli` 发送回复。守护进程会在你结束后,把你的", " **最终回答文本**用 `lark-cli im +messages-reply` 一次性发回飞书。", " 你自己发会造成重复消息。", "2. 把**最终回答**写成给发件人看的**普通散文 / Markdown**。", " 不要输出 JSON 包裹、不要输出“我调用了某某工具”的过程流水账。", " 这段文本会**原样**成为飞书里的回复正文。", "3. 需要落任务就用 `task_*` 工具(task_create / task_update / …),", " 这是你的主要职责;不要只在回答里“描述”你打算做什么。", "", "## 什么时候该建任务(Task #4433)", "", "任务由**你**决定建不建,守护进程不会替你建。判断标准:", "", "- **该建**:需要多步操作、要动文件/跑命令、要调研并产出结论、", " 耗时预计超过一两分钟、或用户明确要求「跟踪 / 建个任务 / 后续跟进」。", " → 用 `task_create` 建任务,**然后**再开始干活(先立任务,再动手)。", "- **不必建**:寒暄、谢谢、纯问答(「今天几号」「这个参数叫啥」)、", " 一两句话就能答完且不需要任何工具的问题。", " → 直接回答,不要为了「显得勤快」而建一个空任务。", "- **建完要更新**:动手过程中用 `task_update` 推进度 / 改 current_status,", " 干完用 `task_complete` 收尾。建了任务却从不更新,比不建更糟——", " 看板上会留下一个卡住的任务。", "", "⚠️ **卡片与任务一一对应**:只有你建了任务,用户才会收到一张进展卡片;", "没建任务就只有文字回复。所以**不要**为了「想要一张卡片」而去建任务,", "也不要建了任务又不用它——卡片上显示的就是你建的那个任务的真 id 和标题。", "", "## 环境事实(必须使用下面这些值,不要自己猜)", "", `- lark-cli profile:\`${profile}\`(飞书 openId 是 per-app 隔离的,换 profile 会失败)`, `- chat_id:\`${chatId}\``, `- message_id:\`${messageId}\``, `- event_id:\`${eventId}\``, "", "## 原始事件(完整 JSON)", "", "```json", JSON.stringify(input.rawEvent, null, 2), "```");
1698
1826
  if (input.recommendedAction) {
@@ -1710,6 +1838,25 @@ function buildOpencodeArgs(input) {
1710
1838
  }
1711
1839
 
1712
1840
  // ../../../packages/cli/src/daemon/task-card.ts
1841
+ async function hydrateCardTimeline(notifier, input) {
1842
+ try {
1843
+ if (typeof notifier.hydrateState !== "function")
1844
+ return;
1845
+ const taskId = taskIdOf(input.meta);
1846
+ if (taskId === undefined)
1847
+ return;
1848
+ const store = await loadLedger();
1849
+ if (!store)
1850
+ return;
1851
+ const record = store.get(taskId);
1852
+ if (!record?.messageId || !record.timeline)
1853
+ return;
1854
+ if (record.messageId !== input.messageId)
1855
+ return;
1856
+ const snapshot = JSON.parse(record.timeline);
1857
+ notifier.hydrateState(record.messageId, snapshot);
1858
+ } catch {}
1859
+ }
1713
1860
  var CARD_OP_TIMEOUT_MS = 15000;
1714
1861
 
1715
1862
  class CardTimeoutError extends Error {
@@ -1735,11 +1882,14 @@ function withTimeout(op, promise, ms) {
1735
1882
  });
1736
1883
  }
1737
1884
  var ledgerStores = new Map;
1885
+ var ledgerOverride;
1738
1886
  var ledgerInFlight;
1739
1887
  function ledgerPathKey() {
1740
1888
  return process.env.ROY_AGENT_LARK_CARD_DB ?? "";
1741
1889
  }
1742
1890
  async function loadLedger() {
1891
+ if (ledgerOverride)
1892
+ return ledgerOverride();
1743
1893
  const key = ledgerPathKey();
1744
1894
  if (ledgerStores.has(key))
1745
1895
  return ledgerStores.get(key);
@@ -1826,6 +1976,8 @@ function createRoyAgentCardPort(options = {}) {
1826
1976
  const opTimeoutMs = options.opTimeoutMs ?? CARD_OP_TIMEOUT_MS;
1827
1977
  let notifier;
1828
1978
  let inFlight;
1979
+ if (options.loadLedger)
1980
+ ledgerOverride = options.loadLedger;
1829
1981
  const loadNotifier = async () => {
1830
1982
  const mod = await import("@ai-setting/roy-agent-core/env/task/plugins");
1831
1983
  if (typeof mod.LarkCardPatchNotifier !== "function") {
@@ -1879,6 +2031,7 @@ function createRoyAgentCardPort(options = {}) {
1879
2031
  },
1880
2032
  async finish(input) {
1881
2033
  const n = await withTimeout("load", getNotifier(), opTimeoutMs);
2034
+ await hydrateCardTimeline(n, input);
1882
2035
  await withTimeout("finish", n.finishTask({
1883
2036
  messageId: input.messageId,
1884
2037
  chatId: input.chatId,
@@ -3406,7 +3559,7 @@ function formatStatus(report) {
3406
3559
  }
3407
3560
 
3408
3561
  // ../../../packages/cli/src/main.ts
3409
- var VERSION = "0.7.9";
3562
+ var VERSION = "0.7.12";
3410
3563
  async function main(argv) {
3411
3564
  const parsed = parseArgs(argv);
3412
3565
  switch (parsed.command) {