@abelxiaoxing/cadence 1.3.0 → 1.4.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 (76) hide show
  1. package/README.md +172 -13
  2. package/agents/design-explorer.md +17 -11
  3. package/agents/diagnosis-worker.md +9 -1
  4. package/agents/implementation-worker.md +3 -1
  5. package/config/plan-draft.example.json +122 -0
  6. package/config/plan-draft.multiple-tasks.example.json +345 -0
  7. package/package.json +9 -5
  8. package/prompts/abel-design.md +141 -38
  9. package/prompts/abel-diagnose.md +10 -1
  10. package/prompts/abel-implement.md +118 -20
  11. package/prompts/abel-init.md +9 -2
  12. package/src/activity-contracts.ts +82 -0
  13. package/src/apply-transaction.ts +16 -14
  14. package/src/artifact-store.ts +17 -0
  15. package/src/candidate-artifact.ts +143 -0
  16. package/src/candidate-patch.ts +33 -12
  17. package/src/candidate-workspace.ts +74 -0
  18. package/src/canonical.ts +16 -0
  19. package/src/change-contract-schema.ts +191 -0
  20. package/src/change-contract.ts +273 -0
  21. package/src/change-verification.ts +896 -0
  22. package/src/child-model.ts +129 -0
  23. package/src/child-session.ts +296 -328
  24. package/src/contracts.ts +325 -109
  25. package/src/control-contracts.ts +51 -1
  26. package/src/delivery-compiler.ts +241 -141
  27. package/src/delivery-revision.ts +42 -0
  28. package/src/design-control.ts +182 -15
  29. package/src/design-diagnostics.ts +150 -0
  30. package/src/design-journal.ts +216 -72
  31. package/src/durable-contracts.ts +210 -0
  32. package/src/durable-workflow.ts +963 -0
  33. package/src/evidence-draft.ts +122 -0
  34. package/src/implement-graph.ts +14 -16
  35. package/src/implement-plan.ts +70 -0
  36. package/src/index.ts +341 -1405
  37. package/src/isolation-backend.ts +84 -23
  38. package/src/model-source.ts +22 -0
  39. package/src/package-candidate.ts +224 -0
  40. package/src/package-delivery.ts +486 -0
  41. package/src/package-verification.ts +509 -0
  42. package/src/package-workflow.ts +253 -0
  43. package/src/packet-runtime.ts +27 -48
  44. package/src/parent-provider.ts +86 -198
  45. package/src/phase-execution.ts +2248 -0
  46. package/src/pi-adapter.ts +19 -0
  47. package/src/plan-draft-summary.ts +146 -0
  48. package/src/plan-draft.ts +493 -0
  49. package/src/route-policy.ts +1 -11
  50. package/src/run-state.ts +4 -16
  51. package/src/run-store.ts +5 -144
  52. package/src/scoped-grep-worker.mjs +23 -0
  53. package/src/scoped-tools.ts +312 -116
  54. package/src/sqlite-schema.ts +171 -0
  55. package/src/storage-schema.ts +352 -0
  56. package/src/subagent-activity.ts +46 -67
  57. package/src/submit-tool.ts +40 -61
  58. package/src/task-ledger.ts +14 -55
  59. package/src/transport-budget.ts +32 -0
  60. package/src/verification-capability.ts +298 -102
  61. package/src/verification-environment.ts +213 -0
  62. package/src/verification-identity.ts +77 -0
  63. package/src/worker-broker.ts +134 -91
  64. package/src/workflow-engine.ts +28 -8285
  65. package/src/workflow-policy.ts +1388 -0
  66. package/src/workflow-recovery-policy.ts +95 -0
  67. package/src/workflow-scheduling.ts +105 -0
  68. package/src/workflow-state-machine.ts +4086 -0
  69. package/src/workflow-status.ts +384 -0
  70. package/src/workspace-io-entry.mjs +58 -0
  71. package/src/workspace-io-worker.mjs +991 -0
  72. package/src/workspace-io.ts +84 -0
  73. package/src/workspace-store.ts +125 -19
  74. package/skills/abel-workflow/SKILL.md +0 -205
  75. package/src/empty-resource-loader.ts +0 -38
  76. package/src/parent-payload-bridge.ts +0 -523
@@ -0,0 +1,122 @@
1
+ import { StringEnum } from "@earendil-works/pi-ai";
2
+ import { Type } from "typebox";
3
+ import { AGENTS_IMPACTS, RELATIVE_PATH_PATTERN } from "./contracts.ts";
4
+
5
+ // The authoring boundary is smaller than the sealed EvidenceResult. Only
6
+ // code-owned identity and explicitly advisory fields may be omitted.
7
+ const advisoryStrings = () => Type.Optional(Type.Array(Type.String()));
8
+ const relativePath = () =>
9
+ Type.String({
10
+ pattern: RELATIVE_PATH_PATTERN,
11
+ minLength: 1,
12
+ maxLength: 512,
13
+ description:
14
+ "Canonical workspace-relative path or module slug; no absolute paths, ./, .., backslashes, or trailing slash.",
15
+ });
16
+ const pathSet = (minItems = 0) =>
17
+ Type.Array(relativePath(), { uniqueItems: true, minItems });
18
+
19
+ export function evidenceDraftSchema(requestId: string, role: string) {
20
+ const identity = {
21
+ id: Type.Optional(
22
+ Type.Literal(requestId, {
23
+ description:
24
+ "Omit: bound by the submit tool. If supplied, must match this request.",
25
+ }),
26
+ ),
27
+ role: Type.Optional(Type.Literal(role)),
28
+ kind: Type.Optional(Type.Literal("evidence")),
29
+ };
30
+ return role === "design-explorer"
31
+ ? Type.Object(
32
+ {
33
+ ...identity,
34
+ packet_id: Type.Optional(Type.Literal(requestId)),
35
+ module_name: relativePath(),
36
+ scope: pathSet(1),
37
+ files_read: pathSet(),
38
+ evidence: Type.Array(
39
+ Type.Object(
40
+ {
41
+ claim: Type.String({ minLength: 1 }),
42
+ path: relativePath(),
43
+ line_start: Type.Integer({ minimum: 1 }),
44
+ line_end: Type.Integer({
45
+ minimum: 1,
46
+ description:
47
+ "Inclusive end line, greater than or equal to line_start.",
48
+ }),
49
+ },
50
+ { additionalProperties: false },
51
+ ),
52
+ ),
53
+ existing_structures: advisoryStrings(),
54
+ existing_conventions: advisoryStrings(),
55
+ constraints_discovered: Type.Array(Type.String()),
56
+ open_questions: Type.Array(Type.String()),
57
+ dependencies: advisoryStrings(),
58
+ write_set_hints: Type.Optional(pathSet()),
59
+ validation_hints: advisoryStrings(),
60
+ agents_impact_hints: advisoryStrings(),
61
+ risks: Type.Array(Type.String()),
62
+ success_criteria_hints: advisoryStrings(),
63
+ },
64
+ { additionalProperties: false },
65
+ )
66
+ : Type.Object(
67
+ {
68
+ ...identity,
69
+ conclusions: Type.Array(Type.String()),
70
+ citations: Type.Array(
71
+ Type.Object(
72
+ { path: relativePath(), lines: Type.String() },
73
+ { additionalProperties: false },
74
+ ),
75
+ ),
76
+ constraints: Type.Array(Type.String()),
77
+ dependencies: advisoryStrings(),
78
+ risks: Type.Array(Type.String()),
79
+ blockingQuestions: Type.Array(Type.String()),
80
+ hints: Type.Optional(
81
+ Type.Object(
82
+ {
83
+ writeSet: pathSet(),
84
+ verification: Type.String(),
85
+ agentsImpact: StringEnum(AGENTS_IMPACTS),
86
+ },
87
+ { additionalProperties: false },
88
+ ),
89
+ ),
90
+ },
91
+ { additionalProperties: false },
92
+ );
93
+ }
94
+
95
+ export function completeEvidenceDraft(
96
+ value: unknown,
97
+ requestId: string,
98
+ role: string,
99
+ ): unknown {
100
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
101
+ const draft = value as Record<string, unknown>;
102
+ const defaults: Record<string, unknown> = {
103
+ id: requestId,
104
+ role,
105
+ kind: "evidence",
106
+ dependencies: [],
107
+ ...(role === "design-explorer"
108
+ ? {
109
+ packet_id: requestId,
110
+ existing_structures: [],
111
+ existing_conventions: [],
112
+ write_set_hints: [],
113
+ validation_hints: [],
114
+ agents_impact_hints: [],
115
+ success_criteria_hints: [],
116
+ }
117
+ : { hints: { writeSet: [], verification: "", agentsImpact: "none" } }),
118
+ };
119
+ // Defaults mean "no advisory information supplied", never verified facts or
120
+ // authority. Explicit wrong values (including null/undefined) survive validation.
121
+ return { ...defaults, ...draft };
122
+ }
@@ -1,4 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
+ import { canonicalJson } from "./canonical.ts";
2
3
  import {
3
4
  type ImplementationPhase,
4
5
  type ImplementGraphBoundary,
@@ -16,21 +17,6 @@ import {
16
17
  validateVerificationAdapterCapability,
17
18
  } from "./verification-capability.ts";
18
19
 
19
- export function canonicalJson(value: unknown): string {
20
- if (Array.isArray(value)) {
21
- return `[${value.map(canonicalJson).join(",")}]`;
22
- }
23
- if (value && typeof value === "object") {
24
- const entries = Object.entries(value as Record<string, unknown>)
25
- .filter(([, entry]) => entry !== undefined)
26
- .sort(([left], [right]) => left.localeCompare(right));
27
- return `{${entries
28
- .map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`)
29
- .join(",")}}`;
30
- }
31
- return JSON.stringify(value) ?? "null";
32
- }
33
-
34
20
  export function hashCanonicalValue(value: unknown): string {
35
21
  return createHash("sha256").update(canonicalJson(value)).digest("hex");
36
22
  }
@@ -92,7 +78,14 @@ function taskPhases(
92
78
  task: ImplementTaskBoundary,
93
79
  ): Array<[ImplementationPhase, ImplementTaskBoundary["phases"]["red"]]> {
94
80
  return [
95
- ["red", task.phases.red],
81
+ ...(!task.verificationMode || task.verificationMode === "behavior"
82
+ ? [
83
+ ["red", task.phases.red] as [
84
+ ImplementationPhase,
85
+ ImplementTaskBoundary["phases"]["red"],
86
+ ],
87
+ ]
88
+ : []),
96
89
  ["green", task.phases.green],
97
90
  ...(task.phases.refactor
98
91
  ? ([["refactor", task.phases.refactor]] as Array<
@@ -355,6 +348,9 @@ export function assessImplementGraphReadiness(
355
348
  taskId: task.taskId,
356
349
  phase,
357
350
  verificationId,
351
+ field: `phases.${phase}.verificationInputs`,
352
+ expectedPaths: [...requiredPaths].sort(),
353
+ actualPaths: [...boundPaths].sort(),
358
354
  }),
359
355
  );
360
356
  }
@@ -576,3 +572,5 @@ export function assessImplementGraphReadiness(
576
572
 
577
573
  return { closure, phases, outputs: outputReadiness };
578
574
  }
575
+
576
+ export { canonicalJson } from "./canonical.ts";
@@ -0,0 +1,70 @@
1
+ import type { ChangeContract } from "./change-contract.ts";
2
+ import type {
3
+ AgentsImpact,
4
+ ImplementGraphOutput,
5
+ ImplementTaskBoundary,
6
+ PhaseBoundary,
7
+ StructuredVerificationContract,
8
+ } from "./contracts.ts";
9
+
10
+ /** Complete execution contracts. No authoring references or defaults cross this boundary. */
11
+ export interface PlanTaskDraft extends Omit<ImplementTaskBoundary, "phases"> {
12
+ phases: {
13
+ red: PhaseBoundary;
14
+ green: PhaseBoundary;
15
+ refactor?: PhaseBoundary;
16
+ };
17
+ affectedVerification: StructuredVerificationContract;
18
+ repairVerification: StructuredVerificationContract;
19
+ }
20
+
21
+ export interface PlanVerification {
22
+ baseline: {
23
+ target: "task-red-contracts";
24
+ affected: "task-affected-contracts";
25
+ fullSuite: StructuredVerificationContract;
26
+ failureIdentity: "normalized";
27
+ };
28
+ change: {
29
+ affected: "task-affected-contracts";
30
+ fullSuite: StructuredVerificationContract;
31
+ postApply: StructuredVerificationContract;
32
+ };
33
+ artifactCorrection: {
34
+ maxAttempts: number;
35
+ };
36
+ repair: {
37
+ maxAttempts: number;
38
+ inBoundaryOnly: true;
39
+ approvalOnBoundaryExpansion: true;
40
+ attribution: ["pre-existing", "introduced", "unresolved", "environment"];
41
+ };
42
+ agentsCheckpoint: {
43
+ required: boolean;
44
+ verification: StructuredVerificationContract | null;
45
+ operations: PlanAgentsCheckpointOperation[];
46
+ };
47
+ }
48
+
49
+ export interface PlanAgentsCheckpointOperation {
50
+ target: string;
51
+ impact: Exclude<AgentsImpact, "none">;
52
+ taskIds: string[];
53
+ managedBlock: string | null;
54
+ }
55
+
56
+ export interface PlanTracking {
57
+ path: "tasks.md";
58
+ format: "markdown-checkbox";
59
+ taskIds: string[];
60
+ completionOwner: "parent";
61
+ }
62
+
63
+ export interface ImplementPlan {
64
+ changeContract?: ChangeContract;
65
+ changeId: string;
66
+ tasks: PlanTaskDraft[];
67
+ outputs: ImplementGraphOutput[];
68
+ verification: PlanVerification;
69
+ tracking: PlanTracking;
70
+ }