@abelxiaoxing/cadence 1.8.0 → 1.8.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.
package/README.md CHANGED
@@ -14,6 +14,23 @@
14
14
  4. 首次进入项目先运行 `/abel-init`,然后 `/abel-design <需求>`,确认集中呈现的目标与方案,设计完成后运行 `/abel-implement <change>`。
15
15
  5. 暂停时先查看原因和建议,不要靠反复 resume 或重启“碰运气”;未完成的工作会保留。
16
16
 
17
+ ### Pi / Web UI 阶段启动约定
18
+
19
+ 阶段命令需要 Cadence 扩展与包内 prompts 同时加载;只有提示正文可见,不代表 `abel_dispatch` 已注册或已激活。
20
+ Web UI / SDK 集成应在会话空闲时提交原始命令:`session.prompt("/abel-design <需求>", { source: "rpc" })`。
21
+ 不要在客户端预展开模板,也不要通过 `steer()`、`followUp()` 或运行中的排队请求启动阶段。
22
+ 运行中的显式阶段命令会被拒绝并报告 `abel-stage-requires-idle`,等待当前请求结束后重新提交即可;原有阶段不会因此被退出或丢弃。
23
+
24
+ 启动失败有明确错误码:`abel-stage-provenance-invalid`(包来源不匹配)、`abel-stage-unverified-input`(缺少可验证的原始调用)和 `abel-stage-tools-unavailable`(工具未暴露或 Design 工具边界设置失败)。
25
+ 扩展会阻止失败请求的工具执行;不能改用 bash、subagent 或 terminal 工具绕过。
26
+ 空闲时正常启动会在首次模型请求前启用 `abel_dispatch` 并限制 Design 工具集合,显式退出后恢复进入前的工具集合。
27
+ 恢复会话或重载不会从历史提示自动激活阶段。
28
+
29
+ 如果扩展根本没有加载,扩展自身无法执行检查;提示中的缺失工具说明只是模型侧兜底,不是宿主级拦截。
30
+ Web UI 必须展示资源加载器的 `getExtensions().errors`,核实当前会话已绑定扩展,并在发送阶段提示前检查 `session.getAllTools()` 中的 `abel_dispatch`;不存在时直接报告配置错误,不发送阶段正文。
31
+ 请检查包资源过滤是否禁用了 extensions、实际运行的 Node / Pi 版本,以及是否恢复了旧的工具清单。
32
+ 诊断时只记录工具名、命令来源和脱敏错误,不记录密钥或完整需求。
33
+
17
34
  ### 先检查环境,不先花模型调用
18
35
 
19
36
  在 Cadence 开发仓库中可用:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abelxiaoxing/cadence",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "Four explicit Abel workflow prompts with stage-isolated design and diagnosis, durable resumable implementation, and three package-owned professional Agents.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -16,6 +16,12 @@ $ARGUMENTS
16
16
 
17
17
  <!-- ABEL:PROMPT:abel-design -->
18
18
 
19
+ Before following this procedure, check that `abel_dispatch` is actually callable in this model request.
20
+ If it is missing, stop and report `Cadence configuration error: abel-stage-tools-unavailable`.
21
+ Do not substitute bash, subagent, or terminal tools, and do not claim the stage started.
22
+ Ask the operator to enable the Cadence extension together with its package prompts, inspect extension-load errors and tool filters, then resubmit the original slash command while the session is idle.
23
+ A prompt marker or historical active/inactive message is not evidence that the tool is available.
24
+
19
25
  This stage is scoped to the invoked task.
20
26
  Direct answers and same-task continuations stay in this stage.
21
27
  If the user ends the workflow or requests an unrelated task, first send `{"action":"finish"}` to `abel_dispatch`, then handle the new task normally with the restored tools.
@@ -13,6 +13,12 @@ $ARGUMENTS
13
13
 
14
14
  <!-- ABEL:PROMPT:abel-diagnose -->
15
15
 
16
+ Before following this procedure, check that `abel_dispatch` is actually callable in this model request.
17
+ If it is missing, stop and report `Cadence configuration error: abel-stage-tools-unavailable`.
18
+ Do not substitute bash, subagent, or terminal tools, and do not claim the stage started.
19
+ Ask the operator to enable the Cadence extension together with its package prompts, inspect extension-load errors and tool filters, then resubmit the original slash command while the session is idle.
20
+ A prompt marker or historical active/inactive message is not evidence that the tool is available.
21
+
16
22
  This stage is scoped to the invoked task.
17
23
  Direct answers and same-task continuations stay in this stage.
18
24
  If the user ends the workflow or requests an unrelated task, first send `{"action":"finish"}` to `abel_dispatch`, then handle the new task normally with the restored tools.
@@ -16,6 +16,12 @@ $ARGUMENTS
16
16
 
17
17
  <!-- ABEL:PROMPT:abel-implement -->
18
18
 
19
+ Before following this procedure, check that `abel_dispatch` is actually callable in this model request.
20
+ If it is missing, stop and report `Cadence configuration error: abel-stage-tools-unavailable`.
21
+ Do not substitute bash, subagent, or terminal tools, and do not claim the stage started.
22
+ Ask the operator to enable the Cadence extension together with its package prompts, inspect extension-load errors and tool filters, then resubmit the original slash command while the session is idle.
23
+ A prompt marker or historical active/inactive message is not evidence that the tool is available.
24
+
19
25
  This stage is scoped to the invoked task.
20
26
  Direct answers and same-task continuations stay in this stage.
21
27
  If the user ends the workflow or requests an unrelated task, first send `{"action":"finish"}` to `abel_dispatch`, then handle the new task normally with the restored tools.
package/src/index.ts CHANGED
@@ -21,6 +21,7 @@ export { executePackageVerification } from "./package-verification.ts";
21
21
  // workflow routing (abel-design/implement/diagnose provenance) in the prompts
22
22
  // integration; abel-init and ordinary prompts never activate dispatch.
23
23
 
24
+ import { createHash } from "node:crypto";
24
25
  import { dirname, join } from "node:path";
25
26
  import { fileURLToPath } from "node:url";
26
27
  import type {
@@ -369,6 +370,27 @@ function hasExpandedPromptMarker(
369
370
  );
370
371
  }
371
372
 
373
+ // A marker is never authority. Recognize only the expanded entrypoint shape
374
+ // here so quoted documentation and ordinary command discussions stay ordinary.
375
+ function expandedStagePrompt(text: string): EligiblePrompt | undefined {
376
+ return ELIGIBLE_PROMPTS.find(
377
+ (name) =>
378
+ text.startsWith(
379
+ `This procedure applies only when the user explicitly invokes \`/${name}\`.`,
380
+ ) && hasExpandedPromptMarker(text, name),
381
+ );
382
+ }
383
+
384
+ type StageStartupError =
385
+ | "abel-stage-requires-idle"
386
+ | "abel-stage-provenance-invalid"
387
+ | "abel-stage-unverified-input"
388
+ | "abel-stage-tools-unavailable";
389
+
390
+ function startupErrorText(code: StageStartupError): string {
391
+ return `Cadence configuration error: ${code}. Do not execute this workflow or substitute shell/subagent tools for abel_dispatch. Ensure the Cadence extension and its package prompts are enabled, inspect host extension-load errors and tool filters, then submit the original slash command through session.prompt when idle. Do not pre-expand the template or queue it through steer/followUp. No new stage authority was granted by this rejected request.`;
392
+ }
393
+
372
394
  function isVerifiedStageInvocation(
373
395
  pi: ExtensionAPI,
374
396
  activation: Activation,
@@ -719,6 +741,21 @@ export function registerWorkflowControl(
719
741
  let exitingStage = false;
720
742
  let activePrompt: EligiblePrompt | undefined;
721
743
  let designToolSnapshot: string[] | undefined;
744
+ let startupFailure: StageStartupError | undefined;
745
+ let admittedPrompt: string | undefined;
746
+ let latestContextUser: string | undefined;
747
+ const admittedMessages = new Set<string>();
748
+ const reportStartupFailure = (code: StageStartupError) => {
749
+ pi.sendMessage(
750
+ {
751
+ customType: "abel-stage-startup-error",
752
+ content: startupErrorText(code),
753
+ display: true,
754
+ details: { code },
755
+ },
756
+ { triggerTurn: false },
757
+ );
758
+ };
722
759
  const activation = new (class implements Activation {
723
760
  state: Activation["state"] = "inactive";
724
761
 
@@ -791,6 +828,18 @@ export function registerWorkflowControl(
791
828
  ),
792
829
  );
793
830
  };
831
+ const stageToolsAvailable = () => {
832
+ if (!activation.isActive()) return true;
833
+ const tools = pi.getActiveTools();
834
+ return (
835
+ tools.includes(DISPATCH_TOOL) &&
836
+ (activePrompt !== "abel-design" ||
837
+ tools.every(
838
+ (name) =>
839
+ name === DISPATCH_TOOL || DESIGN_PARENT_READ_TOOLS.has(name),
840
+ ))
841
+ );
842
+ };
794
843
  const deactivate = () => {
795
844
  activation.drain();
796
845
  if (designToolSnapshot) {
@@ -900,7 +949,6 @@ export function registerWorkflowControl(
900
949
 
901
950
  const registerDispatchTool = (kind: "command" | "packet") => {
902
951
  if (registeredParameterKind === kind) return;
903
- registeredParameterKind = kind;
904
952
  pi.registerTool({
905
953
  name: DISPATCH_TOOL,
906
954
  label: "Abel Control",
@@ -926,6 +974,7 @@ export function registerWorkflowControl(
926
974
  ctx: ExtensionContext,
927
975
  ) {
928
976
  if (
977
+ startupFailure ||
929
978
  exitingStage ||
930
979
  !activation.isActive() ||
931
980
  activePrompt === undefined
@@ -1353,6 +1402,7 @@ export function registerWorkflowControl(
1353
1402
  );
1354
1403
  },
1355
1404
  } as never);
1405
+ registeredParameterKind = kind;
1356
1406
  };
1357
1407
  registerDispatchTool("packet");
1358
1408
 
@@ -1411,6 +1461,17 @@ export function registerWorkflowControl(
1411
1461
  // expose the complete workflow instructions to the parent model.
1412
1462
  return { action: prompt || init ? "handled" : "continue" };
1413
1463
  }
1464
+ if (
1465
+ prompt &&
1466
+ (event.streamingBehavior || !hasPackageProvenance(pi, prompt))
1467
+ ) {
1468
+ reportStartupFailure(
1469
+ event.streamingBehavior
1470
+ ? "abel-stage-requires-idle"
1471
+ : "abel-stage-provenance-invalid",
1472
+ );
1473
+ return { action: "handled" };
1474
+ }
1414
1475
  pendingPrompt = prompt;
1415
1476
  pendingImplementChange =
1416
1477
  prompt === "abel-implement"
@@ -1430,6 +1491,9 @@ export function registerWorkflowControl(
1430
1491
  return { action: "continue" };
1431
1492
  });
1432
1493
  pi.on("before_agent_start", (event, ctx) => {
1494
+ startupFailure = undefined;
1495
+ admittedPrompt = undefined;
1496
+ latestContextUser = undefined;
1433
1497
  const prompt = pendingPrompt;
1434
1498
  const implementChange = pendingImplementChange;
1435
1499
  const init =
@@ -1439,43 +1503,143 @@ export function registerWorkflowControl(
1439
1503
  pendingInit = false;
1440
1504
  const verified =
1441
1505
  prompt && isVerifiedStageInvocation(pi, activation, prompt, event.prompt);
1442
- if (verified) {
1443
- if (activePrompt === "abel-design" && prompt !== "abel-design") {
1444
- restoreDesignTools();
1506
+ if (prompt && !verified) startupFailure = "abel-stage-unverified-input";
1507
+ if (!prompt && expandedStagePrompt(event.prompt))
1508
+ startupFailure = "abel-stage-unverified-input";
1509
+ const toolsBefore = pi.getActiveTools();
1510
+ const wasActive = activation.isActive();
1511
+ try {
1512
+ if (verified) {
1513
+ if (activePrompt === "abel-design" && prompt !== "abel-design") {
1514
+ restoreDesignTools();
1515
+ }
1516
+ registerDispatchTool(
1517
+ prompt === "abel-implement" ? "command" : "packet",
1518
+ );
1519
+ activePrompt = prompt;
1520
+ if (prompt === "abel-implement") {
1521
+ if (
1522
+ implementChange &&
1523
+ implementPromptBindsChange(event.prompt, implementChange) &&
1524
+ typeof ctx.cwd === "string"
1525
+ )
1526
+ implementContinuation.activate({
1527
+ cwd: ctx.cwd,
1528
+ change: implementChange,
1529
+ });
1530
+ else implementContinuation.deactivate();
1531
+ } else {
1532
+ implementContinuation.deactivate();
1533
+ }
1445
1534
  }
1446
- registerDispatchTool(prompt === "abel-implement" ? "command" : "packet");
1447
- activePrompt = prompt;
1448
- if (prompt === "abel-implement") {
1449
- if (
1450
- implementChange &&
1451
- implementPromptBindsChange(event.prompt, implementChange) &&
1452
- typeof ctx.cwd === "string"
1453
- )
1454
- implementContinuation.activate({
1455
- cwd: ctx.cwd,
1456
- change: implementChange,
1457
- });
1458
- else implementContinuation.deactivate();
1459
- } else {
1460
- implementContinuation.deactivate();
1535
+ if (prompt) activateDispatcher(pi, activation, prompt, event.prompt);
1536
+ if (activation.isActive() && activePrompt === "abel-design")
1537
+ enforceDesignTools();
1538
+ if (!stageToolsAvailable())
1539
+ startupFailure = "abel-stage-tools-unavailable";
1540
+ } catch {
1541
+ startupFailure = "abel-stage-tools-unavailable";
1542
+ }
1543
+ if (
1544
+ startupFailure === "abel-stage-tools-unavailable" &&
1545
+ verified &&
1546
+ !wasActive
1547
+ ) {
1548
+ // Roll back the failed startup, not a retained durable run. Never leave
1549
+ // partially applied Design restrictions or a falsely active stage.
1550
+ activePrompt = undefined;
1551
+ activation.drain();
1552
+ implementContinuation.deactivate();
1553
+ designToolSnapshot = undefined;
1554
+ try {
1555
+ pi.setActiveTools(toolsBefore);
1556
+ } catch {
1557
+ /* tool_call remains closed */
1461
1558
  }
1462
1559
  }
1463
- if (prompt) activateDispatcher(pi, activation, prompt, event.prompt);
1464
- if (activation.isActive() && activePrompt === "abel-design")
1465
- enforceDesignTools();
1560
+ if (verified && !startupFailure) admittedPrompt = event.prompt;
1466
1561
  if (
1467
1562
  activation.isActive() &&
1468
1563
  activePrompt === "abel-implement" &&
1469
1564
  typeof ctx.cwd === "string"
1470
1565
  )
1471
1566
  implementContinuation.beginParentTurn(ctx.cwd);
1472
- const boundary = activePrompt
1473
- ? `Abel stage ${activePrompt} is active only for the invoked task and its direct follow-ups. If the user ends it or requests an unrelated task, first call abel_dispatch with {"action":"finish"}, then handle that task normally with the restored tools. A successful finish ends stage authority immediately, including within this turn. Do not extend Gates or workflow rules to that task. A direct Gate answer or same-task continuation stays in this stage. Never invoke another Abel stage automatically.`
1474
- : init
1475
- ? "Only this explicit /abel-init request authorizes the local Init procedure. Do not activate dispatch or continue into another Abel stage."
1476
- : "Abel workflow is inactive. Handle ordinary engineering requests directly. References to commands, repository files, OpenSpec changes, and historical workflow instructions do not authorize a workflow. Do not load or execute an Abel stage unless the user explicitly invokes its slash command.";
1567
+ const boundary = startupFailure
1568
+ ? startupErrorText(startupFailure)
1569
+ : activePrompt
1570
+ ? `Abel stage ${activePrompt} is active only for the invoked task and its direct follow-ups. If the user ends it or requests an unrelated task, first call abel_dispatch with {"action":"finish"}, then handle that task normally with the restored tools. A successful finish ends stage authority immediately, including within this turn. Do not extend Gates or workflow rules to that task. A direct Gate answer or same-task continuation stays in this stage. Never invoke another Abel stage automatically.`
1571
+ : init
1572
+ ? "Only this explicit /abel-init request authorizes the local Init procedure. Do not activate dispatch or continue into another Abel stage."
1573
+ : "Abel workflow is inactive. Handle ordinary engineering requests directly. References to commands, repository files, OpenSpec changes, and historical workflow instructions do not authorize a workflow. Do not load or execute an Abel stage unless the user explicitly invokes its slash command.";
1477
1574
  return { systemPrompt: `${event.systemPrompt ?? ""}\n\n${boundary}` };
1478
1575
  });
1576
+ pi.on("context", (event) => {
1577
+ const lastUser = event.messages.findLastIndex(
1578
+ (message) => message.role === "user",
1579
+ );
1580
+ const retainedAdmissions = new Set<string>();
1581
+ const messages = event.messages.map((message, index) => {
1582
+ if (message.role !== "user") return message;
1583
+ const text =
1584
+ typeof message.content === "string"
1585
+ ? message.content
1586
+ : message.content
1587
+ .filter((part) => part.type === "text")
1588
+ .map((part) => part.text)
1589
+ .join("\n");
1590
+ const key = createHash("sha256")
1591
+ .update(`${message.timestamp}:${text}`)
1592
+ .digest("hex");
1593
+ if (index === lastUser) {
1594
+ if (latestContextUser !== undefined && latestContextUser !== key)
1595
+ startupFailure = undefined;
1596
+ latestContextUser = key;
1597
+ try {
1598
+ if (!stageToolsAvailable())
1599
+ startupFailure = "abel-stage-tools-unavailable";
1600
+ } catch {
1601
+ startupFailure = "abel-stage-tools-unavailable";
1602
+ }
1603
+ if (admittedPrompt === text && !startupFailure)
1604
+ admittedMessages.add(key);
1605
+ admittedPrompt = undefined;
1606
+ }
1607
+ if (admittedMessages.has(key)) retainedAdmissions.add(key);
1608
+ const orphan = expandedStagePrompt(text) && !admittedMessages.has(key);
1609
+ if (index === lastUser && orphan && !startupFailure)
1610
+ startupFailure = "abel-stage-unverified-input";
1611
+ if (!orphan && !(index === lastUser && startupFailure)) return message;
1612
+ return {
1613
+ ...message,
1614
+ content: [
1615
+ {
1616
+ type: "text" as const,
1617
+ text: startupErrorText(
1618
+ index === lastUser && startupFailure
1619
+ ? startupFailure
1620
+ : "abel-stage-unverified-input",
1621
+ ),
1622
+ },
1623
+ ],
1624
+ };
1625
+ });
1626
+ // Keep only identities still present after compaction; never retain raw requirements.
1627
+ admittedMessages.clear();
1628
+ for (const key of retainedAdmissions) admittedMessages.add(key);
1629
+ return { messages };
1630
+ });
1631
+ pi.on("tool_call", (event) => {
1632
+ if (!stageToolsAvailable()) startupFailure = "abel-stage-tools-unavailable";
1633
+ if (startupFailure)
1634
+ return { block: true, reason: startupErrorText(startupFailure) };
1635
+ // Defense in depth against a host/extension restoring a stale tool list.
1636
+ if (
1637
+ activePrompt === "abel-design" &&
1638
+ event.toolName !== DISPATCH_TOOL &&
1639
+ !DESIGN_PARENT_READ_TOOLS.has(event.toolName)
1640
+ )
1641
+ return { block: true, reason: "abel-design-tool-boundary" };
1642
+ });
1479
1643
  pi.on("before_provider_request", (event, ctx) => {
1480
1644
  if (
1481
1645
  activePrompt !== "abel-design" ||
@@ -1495,6 +1659,7 @@ export function registerWorkflowControl(
1495
1659
  const aborted = () => runSignal?.aborted || ctx.signal?.aborted;
1496
1660
  if (
1497
1661
  aborted() ||
1662
+ startupFailure ||
1498
1663
  exitingStage ||
1499
1664
  !activation.isActive() ||
1500
1665
  activePrompt !== "abel-implement"
@@ -1590,6 +1755,10 @@ export function registerWorkflowControl(
1590
1755
  );
1591
1756
  });
1592
1757
  pi.on("session_start", async (_event, ctx) => {
1758
+ startupFailure = undefined;
1759
+ admittedPrompt = undefined;
1760
+ latestContextUser = undefined;
1761
+ admittedMessages.clear();
1593
1762
  pendingPrompt = undefined;
1594
1763
  pendingImplementChange = undefined;
1595
1764
  pendingInit = false;
@@ -1603,6 +1772,10 @@ export function registerWorkflowControl(
1603
1772
  if (ctx.mode === "tui") activity.attach(ctx.ui);
1604
1773
  });
1605
1774
  pi.on("session_shutdown", async () => {
1775
+ startupFailure = undefined;
1776
+ admittedPrompt = undefined;
1777
+ latestContextUser = undefined;
1778
+ admittedMessages.clear();
1606
1779
  pendingPrompt = undefined;
1607
1780
  pendingImplementChange = undefined;
1608
1781
  pendingInit = false;