@agentic-sdlc-kit/contracts 0.9.1 → 1.1.0

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 (186) hide show
  1. package/dist/agent/events.d.ts +18 -18
  2. package/dist/agent/execution.d.ts +22 -22
  3. package/dist/agent-tools/index.d.ts +85 -0
  4. package/dist/agent-tools/index.d.ts.map +1 -0
  5. package/dist/agent-tools/index.js +60 -0
  6. package/dist/agent-tools/index.js.map +1 -0
  7. package/dist/application/application-context.d.ts +194 -60
  8. package/dist/application/application-context.d.ts.map +1 -1
  9. package/dist/application/application-persistence.d.ts +276 -114
  10. package/dist/application/application-persistence.d.ts.map +1 -1
  11. package/dist/application/application-state.d.ts +18 -18
  12. package/dist/architecture/api-contract.d.ts +18 -18
  13. package/dist/architecture/architecture-options.d.ts +6 -6
  14. package/dist/architecture/component-map.d.ts +6 -6
  15. package/dist/architecture/data-model.d.ts +6 -6
  16. package/dist/architecture/operational-design.d.ts +6 -6
  17. package/dist/benchmark/bench.d.ts +330 -0
  18. package/dist/benchmark/bench.d.ts.map +1 -0
  19. package/dist/benchmark/bench.js +69 -0
  20. package/dist/benchmark/bench.js.map +1 -0
  21. package/dist/benchmark/index.d.ts +2 -0
  22. package/dist/benchmark/index.d.ts.map +1 -0
  23. package/dist/benchmark/index.js +2 -0
  24. package/dist/benchmark/index.js.map +1 -0
  25. package/dist/constitution/cli-output.d.ts +706 -0
  26. package/dist/constitution/cli-output.d.ts.map +1 -0
  27. package/dist/constitution/cli-output.js +37 -0
  28. package/dist/constitution/cli-output.js.map +1 -0
  29. package/dist/constitution/index.d.ts +4 -0
  30. package/dist/constitution/index.d.ts.map +1 -0
  31. package/dist/constitution/index.js +4 -0
  32. package/dist/constitution/index.js.map +1 -0
  33. package/dist/constitution/result.d.ts +112 -0
  34. package/dist/constitution/result.d.ts.map +1 -0
  35. package/dist/constitution/result.js +67 -0
  36. package/dist/constitution/result.js.map +1 -0
  37. package/dist/constitution/rule.d.ts +488 -0
  38. package/dist/constitution/rule.d.ts.map +1 -0
  39. package/dist/constitution/rule.js +164 -0
  40. package/dist/constitution/rule.js.map +1 -0
  41. package/dist/context/index.d.ts +2 -0
  42. package/dist/context/index.d.ts.map +1 -0
  43. package/dist/context/index.js +2 -0
  44. package/dist/context/index.js.map +1 -0
  45. package/dist/context/project-context.d.ts +275 -0
  46. package/dist/context/project-context.d.ts.map +1 -0
  47. package/dist/context/project-context.js +56 -0
  48. package/dist/context/project-context.js.map +1 -0
  49. package/dist/evaluation/benchmark.d.ts +12 -12
  50. package/dist/evaluation/metrics.d.ts +4 -4
  51. package/dist/evolution/improvement-hypothesis.d.ts +10 -10
  52. package/dist/execution/execution-profile.d.ts +130 -0
  53. package/dist/execution/execution-profile.d.ts.map +1 -0
  54. package/dist/execution/execution-profile.js +44 -0
  55. package/dist/execution/execution-profile.js.map +1 -0
  56. package/dist/execution/index.d.ts +2 -0
  57. package/dist/execution/index.d.ts.map +1 -0
  58. package/dist/execution/index.js +2 -0
  59. package/dist/execution/index.js.map +1 -0
  60. package/dist/index.d.ts +6 -0
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +11 -0
  63. package/dist/index.js.map +1 -1
  64. package/dist/installer/install-plan.d.ts +16 -16
  65. package/dist/installer/ownership-manifest.d.ts +2 -2
  66. package/dist/installer/package-manifest.d.ts +6 -6
  67. package/dist/learning/engineering-lesson.d.ts +14 -14
  68. package/dist/learning/engineering-memory.d.ts +20 -2
  69. package/dist/learning/engineering-memory.d.ts.map +1 -1
  70. package/dist/learning/engineering-memory.js +2 -0
  71. package/dist/learning/engineering-memory.js.map +1 -1
  72. package/dist/learning/experience-episode.d.ts +14 -14
  73. package/dist/learning/experience.d.ts +8 -8
  74. package/dist/learning/index.d.ts +1 -0
  75. package/dist/learning/index.d.ts.map +1 -1
  76. package/dist/learning/index.js +1 -0
  77. package/dist/learning/index.js.map +1 -1
  78. package/dist/learning/learning-event.d.ts +78 -0
  79. package/dist/learning/learning-event.d.ts.map +1 -0
  80. package/dist/learning/learning-event.js +37 -0
  81. package/dist/learning/learning-event.js.map +1 -0
  82. package/dist/learning/memory.d.ts +2 -2
  83. package/dist/maintenance/bug-fix-workflow.d.ts +4 -4
  84. package/dist/maintenance/bug-report.d.ts +6 -6
  85. package/dist/maintenance/refactor-contract.d.ts +8 -8
  86. package/dist/maintenance/refactor-workflow.d.ts +4 -4
  87. package/dist/observer/event-schema.d.ts +6 -6
  88. package/dist/observer/journal.d.ts +10 -10
  89. package/dist/observer/journal.d.ts.map +1 -1
  90. package/dist/observer/journal.js +7 -0
  91. package/dist/observer/journal.js.map +1 -1
  92. package/dist/observer/run-summary.d.ts +12 -12
  93. package/dist/onboard/index.d.ts +2 -0
  94. package/dist/onboard/index.d.ts.map +1 -0
  95. package/dist/onboard/index.js +2 -0
  96. package/dist/onboard/index.js.map +1 -0
  97. package/dist/onboard/onboard-report.d.ts +349 -0
  98. package/dist/onboard/onboard-report.d.ts.map +1 -0
  99. package/dist/onboard/onboard-report.js +96 -0
  100. package/dist/onboard/onboard-report.js.map +1 -0
  101. package/dist/patterns/pattern.d.ts +2 -2
  102. package/dist/planning/task.d.ts +36 -36
  103. package/dist/policy/policy.d.ts +8 -8
  104. package/dist/product/product-brief.d.ts +6 -6
  105. package/dist/product/requirements.d.ts +48 -48
  106. package/dist/project/project-profile.d.ts +113 -2
  107. package/dist/project/project-profile.d.ts.map +1 -1
  108. package/dist/project/project-profile.js +17 -2
  109. package/dist/project/project-profile.js.map +1 -1
  110. package/dist/routing/index.d.ts +1 -0
  111. package/dist/routing/index.d.ts.map +1 -1
  112. package/dist/routing/index.js +1 -0
  113. package/dist/routing/index.js.map +1 -1
  114. package/dist/routing/measured-routing.d.ts +41 -0
  115. package/dist/routing/measured-routing.d.ts.map +1 -0
  116. package/dist/routing/measured-routing.js +24 -0
  117. package/dist/routing/measured-routing.js.map +1 -0
  118. package/dist/routing/routing-policy.d.ts +20 -20
  119. package/dist/routing/routing-request.d.ts +2 -2
  120. package/dist/runtime-guard/action-classification.d.ts +2 -2
  121. package/dist/runtime-guard/audit-event.d.ts +8 -8
  122. package/dist/runtime-guard/policy-schema.d.ts +4 -4
  123. package/dist/scaffolding/scaffold-contract.d.ts +59 -59
  124. package/dist/scaffolding/template-manifest.d.ts +15 -15
  125. package/dist/secret-guard/detection-rule.d.ts +4 -4
  126. package/dist/secret-guard/finding.d.ts +10 -10
  127. package/dist/secret-guard/scanner-failure.d.ts +4 -4
  128. package/dist/specification/specification.d.ts +8 -8
  129. package/dist/stack-pack/manifest.d.ts +33 -4
  130. package/dist/stack-pack/manifest.d.ts.map +1 -1
  131. package/dist/stack-pack/manifest.js +22 -2
  132. package/dist/stack-pack/manifest.js.map +1 -1
  133. package/dist/verification/index.d.ts +1 -0
  134. package/dist/verification/index.d.ts.map +1 -1
  135. package/dist/verification/index.js +1 -0
  136. package/dist/verification/index.js.map +1 -1
  137. package/dist/verification/report.d.ts +118 -12
  138. package/dist/verification/report.d.ts.map +1 -1
  139. package/dist/verification/report.js +4 -0
  140. package/dist/verification/report.js.map +1 -1
  141. package/dist/verification/strength.d.ts +270 -0
  142. package/dist/verification/strength.d.ts.map +1 -0
  143. package/dist/verification/strength.js +168 -0
  144. package/dist/verification/strength.js.map +1 -0
  145. package/dist/workflow/next-action.d.ts +67 -6
  146. package/dist/workflow/next-action.d.ts.map +1 -1
  147. package/dist/workflow/next-action.js +23 -0
  148. package/dist/workflow/next-action.js.map +1 -1
  149. package/dist/workflow/workflow.d.ts +9 -8
  150. package/dist/workflow/workflow.d.ts.map +1 -1
  151. package/package.json +6 -1
  152. package/src/agent-tools/index.ts +81 -0
  153. package/src/benchmark/bench.ts +83 -0
  154. package/src/benchmark/index.ts +1 -0
  155. package/src/constitution/cli-output.ts +44 -0
  156. package/src/constitution/index.ts +3 -0
  157. package/src/constitution/result.test.ts +69 -0
  158. package/src/constitution/result.ts +74 -0
  159. package/src/constitution/rule-origin.test.ts +36 -0
  160. package/src/constitution/rule-path.test.ts +15 -0
  161. package/src/constitution/rule.test.ts +209 -0
  162. package/src/constitution/rule.ts +192 -0
  163. package/src/context/index.ts +1 -0
  164. package/src/context/project-context.ts +63 -0
  165. package/src/execution/execution-profile.ts +50 -0
  166. package/src/execution/index.ts +1 -0
  167. package/src/index.ts +16 -0
  168. package/src/learning/engineering-memory.ts +2 -0
  169. package/src/learning/index.ts +1 -0
  170. package/src/learning/learning-event.ts +42 -0
  171. package/src/observer/journal.ts +7 -0
  172. package/src/onboard/index.ts +1 -0
  173. package/src/onboard/onboard-report.test.ts +92 -0
  174. package/src/onboard/onboard-report.ts +115 -0
  175. package/src/project/project-profile.ts +19 -2
  176. package/src/routing/index.ts +1 -0
  177. package/src/routing/measured-routing.ts +27 -0
  178. package/src/stack-pack/manifest.test.ts +45 -0
  179. package/src/stack-pack/manifest.ts +24 -2
  180. package/src/verification/index.ts +1 -0
  181. package/src/verification/report.ts +4 -0
  182. package/src/verification/strength.test.ts +160 -0
  183. package/src/verification/strength.ts +189 -0
  184. package/src/workflow/next-action.test.ts +25 -0
  185. package/src/workflow/next-action.ts +25 -0
  186. package/src/workflow/workflow.ts +1 -0
@@ -0,0 +1,189 @@
1
+ // packages/contracts/src/verification/strength.ts
2
+ //
3
+ // Test-strength evidence contract (ADR-0022). Passing evidence proves
4
+ // the agent wrote a test that failed and then passed; it does NOT prove
5
+ // the test would catch a regression. Strength evidence measures the
6
+ // suite's ability to detect regressions via mutation testing and records
7
+ // the score as a versioned, auditable artifact.
8
+ //
9
+ // Honest limits (documented in ADR-0022, repeated here because a
10
+ // contract must not overclaim):
11
+ // - The mutation score is a PROXY, not proof. It measures how many
12
+ // generated mutants the suite killed on THIS run with THIS tool.
13
+ // - `incomplete` status means the run exceeded its budget (or the
14
+ // tool was unavailable): the score is UNKNOWN, never silently 0
15
+ // and never silently passed.
16
+ // - `scope: diff` mutates only the files named in the scope: a
17
+ // cross-file escape (a mutant in file A caught only by a test of
18
+ // file B) can be missed when B is outside the diff.
19
+ //
20
+ // See docs/contracts/CONTRACTS.md §6.3.
21
+
22
+ import { z } from 'zod';
23
+
24
+ export const STRENGTH_EVIDENCE_SCHEMA_VERSION = 1 as const;
25
+
26
+ /**
27
+ * The mutation tool that produced the evidence. Stack adapters map
28
+ * stacks onto tools (core/tdd/strength.ts); the contract only records
29
+ * which tool ran so the score is interpretable later.
30
+ */
31
+ export const MutationToolSchema = z.enum([
32
+ 'stryker', // node-typescript, react-typescript (StrykerJS)
33
+ 'mutmut', // python
34
+ 'mutant', // ruby, ruby-rails
35
+ 'go-mutesting', // go (gremlins shares the runner, recorded distinctly)
36
+ 'gremlins', // go
37
+ 'cargo-mutants', // rust
38
+ 'stryker-net', // dotnet (Stryker.NET)
39
+ ]);
40
+ export type MutationTool = z.infer<typeof MutationToolSchema>;
41
+
42
+ /**
43
+ * Status of a strength run. Exhaustive by construction:
44
+ * - passed: tool ran to completion and score >= threshold.
45
+ * - failed: tool ran to completion and score < threshold.
46
+ * - incomplete: the run did NOT complete (budget exceeded, tool
47
+ * missing, tool crashed). The score is unknown —
48
+ * an incomplete run NEVER counts as passed and never
49
+ * fabricates a score.
50
+ */
51
+ export const StrengthStatusSchema = z.enum(['passed', 'failed', 'incomplete']);
52
+ export type StrengthStatus = z.infer<typeof StrengthStatusSchema>;
53
+
54
+ /** How the score reacts to the threshold: warn logs, enforce blocks. */
55
+ export const StrengthGateModeSchema = z.enum(['warn', 'enforce']);
56
+ export type StrengthGateMode = z.infer<typeof StrengthGateModeSchema>;
57
+
58
+ /** `diff` = only the scoped files; `suite` = the full target set. */
59
+ export const StrengthScopeSchema = z.enum(['diff', 'suite']);
60
+ export type StrengthScope = z.infer<typeof StrengthScopeSchema>;
61
+
62
+ /**
63
+ * Configuration surface on the project profile (`.ai-kit/project.yml`):
64
+ *
65
+ * verification:
66
+ * strength:
67
+ * enabled: true # default false in v1 (opt-in)
68
+ * threshold: 60 # mutation score percentage
69
+ * budgetMs: 300000 # hard cap on the mutation run
70
+ * scope: diff # 'diff' | 'suite'
71
+ * gateMode: warn # 'warn' | 'enforce'
72
+ */
73
+ export const StrengthSettingsSchema = z
74
+ .object({
75
+ enabled: z.boolean(),
76
+ threshold: z.number().int().min(0).max(100),
77
+ budgetMs: z.number().int().positive(),
78
+ scope: StrengthScopeSchema,
79
+ gateMode: StrengthGateModeSchema,
80
+ })
81
+ .strict();
82
+ export type StrengthSettings = z.infer<typeof StrengthSettingsSchema>;
83
+
84
+ export const DEFAULT_STRENGTH_SETTINGS: StrengthSettings = {
85
+ enabled: false,
86
+ threshold: 60,
87
+ budgetMs: 300_000,
88
+ scope: 'diff',
89
+ gateMode: 'warn',
90
+ };
91
+
92
+ export const VerificationSettingsSchema = z
93
+ .object({
94
+ strength: StrengthSettingsSchema.optional(),
95
+ })
96
+ .strict();
97
+ export type VerificationSettings = z.infer<typeof VerificationSettingsSchema>;
98
+
99
+ export const StrengthEvidenceSchema = z
100
+ .object({
101
+ schemaVersion: z.literal(STRENGTH_EVIDENCE_SCHEMA_VERSION),
102
+ taskId: z.string().min(1).optional(),
103
+ tool: MutationToolSchema,
104
+ toolVersion: z.string().min(1).optional(),
105
+ status: StrengthStatusSchema,
106
+ /** Mutation score percentage 0–100. Undefined iff status is `incomplete`. */
107
+ score: z.number().min(0).max(100).optional(),
108
+ mutantsGenerated: z.number().int().nonnegative(),
109
+ mutantsKilled: z.number().int().nonnegative(),
110
+ mutantsSurvived: z.number().int().nonnegative(),
111
+ threshold: z.number().int().min(0).max(100),
112
+ scope: StrengthScopeSchema,
113
+ /** Files mutated; empty when the tool did not report a file list. */
114
+ scopeFiles: z.array(z.string()).default([]),
115
+ durationMs: z.number().int().nonnegative(),
116
+ budgetMs: z.number().int().positive(),
117
+ /** Bounded, redacted human-readable derivation (never full output). */
118
+ summary: z.string().max(300),
119
+ })
120
+ .strict()
121
+ .refine((e) => e.status === 'incomplete' || e.score !== undefined, {
122
+ message: 'score is required unless status is incomplete',
123
+ path: ['score'],
124
+ })
125
+ .refine((e) => e.status !== 'incomplete' || e.score === undefined, {
126
+ message: 'an incomplete run must not carry a score',
127
+ path: ['score'],
128
+ })
129
+ .refine((e) => e.mutantsKilled + e.mutantsSurvived <= e.mutantsGenerated, {
130
+ message: 'killed + survived cannot exceed generated mutants',
131
+ path: ['mutantsKilled'],
132
+ });
133
+ export type StrengthEvidence = z.infer<typeof StrengthEvidenceSchema>;
134
+
135
+ /**
136
+ * Deterministic mutation score: round(100 * killed / generated).
137
+ * Returns null when no mutants were generated — a suite with nothing
138
+ * to kill has no measurable strength, and reporting 0 would claim a
139
+ * measurement that was not made.
140
+ */
141
+ export function computeMutationScore(killed: number, generated: number): number | null {
142
+ if (generated <= 0) return null;
143
+ return Math.round((100 * killed) / generated);
144
+ }
145
+
146
+ /**
147
+ * Resolve the status of a completed strength run against the threshold.
148
+ * An unknown score (no mutants generated) is `incomplete`: the run
149
+ * measured nothing and must not pass a gate by default.
150
+ */
151
+ export function resolveStrengthStatus(score: number | null, threshold: number): StrengthStatus {
152
+ if (score === null) return 'incomplete';
153
+ return score >= threshold ? 'passed' : 'failed';
154
+ }
155
+
156
+ /**
157
+ * Gate decision. `enforce` refuses completion below threshold (the
158
+ * caller turns a `block` decision into a failed verify); `warn` never
159
+ * blocks — it is observability only. An `incomplete` run in `enforce`
160
+ * mode blocks: an unknown score must not certify strength (fail
161
+ * closed).
162
+ */
163
+ export function evaluateStrengthGate(
164
+ evidence: Pick<StrengthEvidence, 'status' | 'score'>,
165
+ gateMode: StrengthGateMode,
166
+ ): { block: boolean; reason: string } {
167
+ if (gateMode === 'warn') {
168
+ return {
169
+ block: false,
170
+ reason:
171
+ evidence.status === 'incomplete'
172
+ ? 'strength run incomplete (warn mode: logged, not blocked)'
173
+ : `mutation score ${evidence.score ?? 'n/a'}% (warn mode: logged, not blocked)`,
174
+ };
175
+ }
176
+ if (evidence.status === 'incomplete') {
177
+ return {
178
+ block: true,
179
+ reason: 'strength run incomplete: score unknown, refusing to certify (enforce mode)',
180
+ };
181
+ }
182
+ if (evidence.status === 'failed') {
183
+ return {
184
+ block: true,
185
+ reason: `mutation score ${evidence.score}% is below the threshold (enforce mode)`,
186
+ };
187
+ }
188
+ return { block: false, reason: `mutation score ${evidence.score}% meets the threshold` };
189
+ }
@@ -7,6 +7,7 @@ import {
7
7
  NEXT_ACTION_SCHEMA_VERSION,
8
8
  NextActionSchema,
9
9
  NextRequiredActionSchema,
10
+ RecoveryHintSchema,
10
11
  } from './next-action.js';
11
12
  import { WorkflowStatusSchema } from './workflow.js';
12
13
 
@@ -99,3 +100,27 @@ describe('NextActionSchema', () => {
99
100
  expect(NextActionSchema.safeParse({ ...base, status: 'exploding' }).success).toBe(false);
100
101
  });
101
102
  });
103
+
104
+ describe('RecoveryHintSchema', () => {
105
+ const hint = {
106
+ classification: 'compilation',
107
+ action: 'feedback',
108
+ reason: 'Fix the compile error; do not change the assertion.',
109
+ attempt: 1,
110
+ maxAttempts: 3,
111
+ };
112
+
113
+ it('accepts a feedback hint for a known classification', () => {
114
+ expect(RecoveryHintSchema.safeParse(hint).success).toBe(true);
115
+ });
116
+
117
+ it('rejects an unknown classification, a non-feedback action and a zero attempt', () => {
118
+ expect(RecoveryHintSchema.safeParse({ ...hint, classification: 'bogus' }).success).toBe(false);
119
+ expect(RecoveryHintSchema.safeParse({ ...hint, action: 'stop' }).success).toBe(false);
120
+ expect(RecoveryHintSchema.safeParse({ ...hint, attempt: 0 }).success).toBe(false);
121
+ });
122
+
123
+ it('is an optional field on the NextAction payload', () => {
124
+ expect('recoveryHint' in NextActionSchema.shape).toBe(true);
125
+ });
126
+ });
@@ -74,6 +74,29 @@ export const NextActionConstraintsSchema = z.object({
74
74
  });
75
75
  export type NextActionConstraints = z.infer<typeof NextActionConstraintsSchema>;
76
76
 
77
+ /**
78
+ * Feedback for an attempt the evidence gate rejected. Its text is fixed
79
+ * guidance chosen by the kit, never stored or captured output, so it is
80
+ * safe to place in an agent's instructions.
81
+ */
82
+ export const RecoveryHintSchema = z.object({
83
+ classification: z.enum([
84
+ 'assertion',
85
+ 'compilation',
86
+ 'dependency',
87
+ 'discovery',
88
+ 'environment',
89
+ 'timeout',
90
+ 'unclassified',
91
+ ]),
92
+ action: z.literal('feedback'),
93
+ reason: z.string().min(1),
94
+ /** The failed attempt this hint reports, counted within the current phase (1-based). */
95
+ attempt: z.number().int().positive(),
96
+ maxAttempts: z.number().int().positive(),
97
+ });
98
+ export type RecoveryHint = z.infer<typeof RecoveryHintSchema>;
99
+
77
100
  export const NextActionSchema = z.object({
78
101
  schemaVersion: z.literal(NEXT_ACTION_SCHEMA_VERSION),
79
102
  /** The feature run this action belongs to (one run per feature id). */
@@ -96,6 +119,8 @@ export const NextActionSchema = z.object({
96
119
  blockingQuestions: z.array(z.string()),
97
120
  /** Advisory lessons (ADVISORY ONLY — never authority; ADR-0021 §4). */
98
121
  advisoryLessons: z.array(LessonRefSchema),
122
+ /** Present only when the last attempt was rejected and feedback is still offered. */
123
+ recoveryHint: RecoveryHintSchema.optional(),
99
124
  constraints: NextActionConstraintsSchema,
100
125
  });
101
126
  export type NextAction = z.infer<typeof NextActionSchema>;
@@ -43,6 +43,7 @@ export const WorkflowStateSchema = z.object({
43
43
  });
44
44
 
45
45
  export type WorkflowState = z.infer<typeof WorkflowStateSchema>;
46
+ export type WorkflowRun = WorkflowState;
46
47
  export type TaskHistoryEntry = z.infer<typeof TaskHistoryEntrySchema>;
47
48
 
48
49
  // Re-export for ergonomic imports.