@agentic-sdlc-kit/contracts 0.9.1 → 1.0.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/dist/agent/events.d.ts +18 -18
- package/dist/agent/execution.d.ts +22 -22
- package/dist/agent-tools/index.d.ts +85 -0
- package/dist/agent-tools/index.d.ts.map +1 -0
- package/dist/agent-tools/index.js +60 -0
- package/dist/agent-tools/index.js.map +1 -0
- package/dist/application/application-context.d.ts +194 -60
- package/dist/application/application-context.d.ts.map +1 -1
- package/dist/application/application-persistence.d.ts +276 -114
- package/dist/application/application-persistence.d.ts.map +1 -1
- package/dist/application/application-state.d.ts +18 -18
- package/dist/architecture/api-contract.d.ts +18 -18
- package/dist/architecture/architecture-options.d.ts +6 -6
- package/dist/architecture/component-map.d.ts +6 -6
- package/dist/architecture/data-model.d.ts +6 -6
- package/dist/architecture/operational-design.d.ts +6 -6
- package/dist/benchmark/bench.d.ts +330 -0
- package/dist/benchmark/bench.d.ts.map +1 -0
- package/dist/benchmark/bench.js +69 -0
- package/dist/benchmark/bench.js.map +1 -0
- package/dist/benchmark/index.d.ts +2 -0
- package/dist/benchmark/index.d.ts.map +1 -0
- package/dist/benchmark/index.js +2 -0
- package/dist/benchmark/index.js.map +1 -0
- package/dist/constitution/cli-output.d.ts +706 -0
- package/dist/constitution/cli-output.d.ts.map +1 -0
- package/dist/constitution/cli-output.js +37 -0
- package/dist/constitution/cli-output.js.map +1 -0
- package/dist/constitution/index.d.ts +4 -0
- package/dist/constitution/index.d.ts.map +1 -0
- package/dist/constitution/index.js +4 -0
- package/dist/constitution/index.js.map +1 -0
- package/dist/constitution/result.d.ts +112 -0
- package/dist/constitution/result.d.ts.map +1 -0
- package/dist/constitution/result.js +67 -0
- package/dist/constitution/result.js.map +1 -0
- package/dist/constitution/rule.d.ts +488 -0
- package/dist/constitution/rule.d.ts.map +1 -0
- package/dist/constitution/rule.js +164 -0
- package/dist/constitution/rule.js.map +1 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +2 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/project-context.d.ts +275 -0
- package/dist/context/project-context.d.ts.map +1 -0
- package/dist/context/project-context.js +56 -0
- package/dist/context/project-context.js.map +1 -0
- package/dist/evaluation/benchmark.d.ts +12 -12
- package/dist/evaluation/metrics.d.ts +4 -4
- package/dist/evolution/improvement-hypothesis.d.ts +10 -10
- package/dist/execution/execution-profile.d.ts +130 -0
- package/dist/execution/execution-profile.d.ts.map +1 -0
- package/dist/execution/execution-profile.js +44 -0
- package/dist/execution/execution-profile.js.map +1 -0
- package/dist/execution/index.d.ts +2 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +2 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/installer/install-plan.d.ts +16 -16
- package/dist/installer/ownership-manifest.d.ts +2 -2
- package/dist/installer/package-manifest.d.ts +6 -6
- package/dist/learning/engineering-lesson.d.ts +14 -14
- package/dist/learning/engineering-memory.d.ts +20 -2
- package/dist/learning/engineering-memory.d.ts.map +1 -1
- package/dist/learning/engineering-memory.js +2 -0
- package/dist/learning/engineering-memory.js.map +1 -1
- package/dist/learning/experience-episode.d.ts +14 -14
- package/dist/learning/experience.d.ts +8 -8
- package/dist/learning/index.d.ts +1 -0
- package/dist/learning/index.d.ts.map +1 -1
- package/dist/learning/index.js +1 -0
- package/dist/learning/index.js.map +1 -1
- package/dist/learning/learning-event.d.ts +78 -0
- package/dist/learning/learning-event.d.ts.map +1 -0
- package/dist/learning/learning-event.js +37 -0
- package/dist/learning/learning-event.js.map +1 -0
- package/dist/learning/memory.d.ts +2 -2
- package/dist/maintenance/bug-fix-workflow.d.ts +4 -4
- package/dist/maintenance/bug-report.d.ts +6 -6
- package/dist/maintenance/refactor-contract.d.ts +8 -8
- package/dist/maintenance/refactor-workflow.d.ts +4 -4
- package/dist/observer/event-schema.d.ts +6 -6
- package/dist/observer/journal.d.ts +10 -10
- package/dist/observer/journal.d.ts.map +1 -1
- package/dist/observer/journal.js +7 -0
- package/dist/observer/journal.js.map +1 -1
- package/dist/observer/run-summary.d.ts +12 -12
- package/dist/onboard/index.d.ts +2 -0
- package/dist/onboard/index.d.ts.map +1 -0
- package/dist/onboard/index.js +2 -0
- package/dist/onboard/index.js.map +1 -0
- package/dist/onboard/onboard-report.d.ts +349 -0
- package/dist/onboard/onboard-report.d.ts.map +1 -0
- package/dist/onboard/onboard-report.js +96 -0
- package/dist/onboard/onboard-report.js.map +1 -0
- package/dist/patterns/pattern.d.ts +2 -2
- package/dist/planning/task.d.ts +36 -36
- package/dist/policy/policy.d.ts +8 -8
- package/dist/product/product-brief.d.ts +6 -6
- package/dist/product/requirements.d.ts +48 -48
- package/dist/project/project-profile.d.ts +113 -2
- package/dist/project/project-profile.d.ts.map +1 -1
- package/dist/project/project-profile.js +17 -2
- package/dist/project/project-profile.js.map +1 -1
- package/dist/routing/index.d.ts +1 -0
- package/dist/routing/index.d.ts.map +1 -1
- package/dist/routing/index.js +1 -0
- package/dist/routing/index.js.map +1 -1
- package/dist/routing/measured-routing.d.ts +41 -0
- package/dist/routing/measured-routing.d.ts.map +1 -0
- package/dist/routing/measured-routing.js +24 -0
- package/dist/routing/measured-routing.js.map +1 -0
- package/dist/routing/routing-policy.d.ts +20 -20
- package/dist/routing/routing-request.d.ts +2 -2
- package/dist/runtime-guard/action-classification.d.ts +2 -2
- package/dist/runtime-guard/audit-event.d.ts +8 -8
- package/dist/runtime-guard/policy-schema.d.ts +4 -4
- package/dist/scaffolding/scaffold-contract.d.ts +59 -59
- package/dist/scaffolding/template-manifest.d.ts +15 -15
- package/dist/secret-guard/detection-rule.d.ts +4 -4
- package/dist/secret-guard/finding.d.ts +10 -10
- package/dist/secret-guard/scanner-failure.d.ts +4 -4
- package/dist/specification/specification.d.ts +8 -8
- package/dist/stack-pack/manifest.d.ts +33 -4
- package/dist/stack-pack/manifest.d.ts.map +1 -1
- package/dist/stack-pack/manifest.js +22 -2
- package/dist/stack-pack/manifest.js.map +1 -1
- package/dist/verification/index.d.ts +1 -0
- package/dist/verification/index.d.ts.map +1 -1
- package/dist/verification/index.js +1 -0
- package/dist/verification/index.js.map +1 -1
- package/dist/verification/report.d.ts +118 -12
- package/dist/verification/report.d.ts.map +1 -1
- package/dist/verification/report.js +4 -0
- package/dist/verification/report.js.map +1 -1
- package/dist/verification/strength.d.ts +270 -0
- package/dist/verification/strength.d.ts.map +1 -0
- package/dist/verification/strength.js +168 -0
- package/dist/verification/strength.js.map +1 -0
- package/dist/workflow/next-action.d.ts +67 -6
- package/dist/workflow/next-action.d.ts.map +1 -1
- package/dist/workflow/next-action.js +23 -0
- package/dist/workflow/next-action.js.map +1 -1
- package/dist/workflow/workflow.d.ts +9 -8
- package/dist/workflow/workflow.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/agent-tools/index.ts +81 -0
- package/src/benchmark/bench.ts +83 -0
- package/src/benchmark/index.ts +1 -0
- package/src/constitution/cli-output.ts +44 -0
- package/src/constitution/index.ts +3 -0
- package/src/constitution/result.test.ts +69 -0
- package/src/constitution/result.ts +74 -0
- package/src/constitution/rule-origin.test.ts +36 -0
- package/src/constitution/rule-path.test.ts +15 -0
- package/src/constitution/rule.test.ts +209 -0
- package/src/constitution/rule.ts +192 -0
- package/src/context/index.ts +1 -0
- package/src/context/project-context.ts +63 -0
- package/src/execution/execution-profile.ts +50 -0
- package/src/execution/index.ts +1 -0
- package/src/index.ts +16 -0
- package/src/learning/engineering-memory.ts +2 -0
- package/src/learning/index.ts +1 -0
- package/src/learning/learning-event.ts +42 -0
- package/src/observer/journal.ts +7 -0
- package/src/onboard/index.ts +1 -0
- package/src/onboard/onboard-report.test.ts +92 -0
- package/src/onboard/onboard-report.ts +115 -0
- package/src/project/project-profile.ts +19 -2
- package/src/routing/index.ts +1 -0
- package/src/routing/measured-routing.ts +27 -0
- package/src/stack-pack/manifest.test.ts +45 -0
- package/src/stack-pack/manifest.ts +24 -2
- package/src/verification/index.ts +1 -0
- package/src/verification/report.ts +4 -0
- package/src/verification/strength.test.ts +160 -0
- package/src/verification/strength.ts +189 -0
- package/src/workflow/next-action.test.ts +25 -0
- package/src/workflow/next-action.ts +25 -0
- package/src/workflow/workflow.ts +1 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { OnboardReportSchema, OnboardWriteResultSchema } from './onboard-report.js';
|
|
3
|
+
|
|
4
|
+
const base = {
|
|
5
|
+
schemaVersion: 1,
|
|
6
|
+
mode: 'dry-run',
|
|
7
|
+
filesWritten: 0,
|
|
8
|
+
revision: null,
|
|
9
|
+
stacks: [],
|
|
10
|
+
packageManagers: [],
|
|
11
|
+
testFrameworks: [],
|
|
12
|
+
hasCi: false,
|
|
13
|
+
sources: [],
|
|
14
|
+
candidates: [],
|
|
15
|
+
decisions: [],
|
|
16
|
+
notes: [],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe('OnboardReportSchema', () => {
|
|
20
|
+
it('accepts an empty dry-run report', () => {
|
|
21
|
+
expect(OnboardReportSchema.safeParse(base).success).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('rejects any non-zero filesWritten: a dry run cannot record a write', () => {
|
|
25
|
+
expect(OnboardReportSchema.safeParse({ ...base, filesWritten: 1 }).success).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('rejects a non-dry-run mode', () => {
|
|
29
|
+
expect(OnboardReportSchema.safeParse({ ...base, mode: 'apply' }).success).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('rejects a candidate that is not proposed', () => {
|
|
33
|
+
const candidate = {
|
|
34
|
+
id: 'declared:agent-instruction:AGENTS.md#abc',
|
|
35
|
+
kind: 'agent-instruction',
|
|
36
|
+
statement: 'Never commit secrets.',
|
|
37
|
+
source: { path: 'AGENTS.md', line: 4 },
|
|
38
|
+
status: 'active',
|
|
39
|
+
};
|
|
40
|
+
expect(OnboardReportSchema.safeParse({ ...base, candidates: [candidate] }).success).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('rejects a malformed revision', () => {
|
|
44
|
+
expect(OnboardReportSchema.safeParse({ ...base, revision: 'main' }).success).toBe(false);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('OnboardWriteResultSchema', () => {
|
|
49
|
+
const write = {
|
|
50
|
+
schemaVersion: 1,
|
|
51
|
+
mode: 'write',
|
|
52
|
+
revision: 'a'.repeat(40),
|
|
53
|
+
rulesWritten: ['ONB-AGENT-001'],
|
|
54
|
+
rulesAlreadyProposed: [],
|
|
55
|
+
staleProposals: [],
|
|
56
|
+
baseline: { status: 'written', entries: 0 },
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
it('accepts a write result pinned to a full revision', () => {
|
|
60
|
+
expect(OnboardWriteResultSchema.safeParse(write).success).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('rejects a short revision: the adoption point must be exact', () => {
|
|
64
|
+
expect(OnboardWriteResultSchema.safeParse({ ...write, revision: 'abc1234' }).success).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('rejects a dry-run mode in a write result', () => {
|
|
68
|
+
expect(OnboardWriteResultSchema.safeParse({ ...write, mode: 'dry-run' }).success).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('OnboardReportSchema defaults for conflicts and missing tools', () => {
|
|
73
|
+
it('accepts a report written before these fields existed', () => {
|
|
74
|
+
const res = OnboardReportSchema.safeParse({
|
|
75
|
+
schemaVersion: 1,
|
|
76
|
+
mode: 'dry-run',
|
|
77
|
+
filesWritten: 0,
|
|
78
|
+
revision: null,
|
|
79
|
+
stacks: [],
|
|
80
|
+
packageManagers: [],
|
|
81
|
+
testFrameworks: [],
|
|
82
|
+
hasCi: false,
|
|
83
|
+
sources: [],
|
|
84
|
+
candidates: [],
|
|
85
|
+
decisions: [],
|
|
86
|
+
notes: [],
|
|
87
|
+
});
|
|
88
|
+
expect(res.success && res.data.conflicts).toEqual([]);
|
|
89
|
+
expect(res.success && res.data.missingTools).toEqual([]);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// packages/contracts/src/onboard/onboard-report.ts
|
|
2
|
+
//
|
|
3
|
+
// Output of `kit onboard --dry-run` (ADR-0023 §7). The report lists what the
|
|
4
|
+
// repository already declares: lint and formatter settings, type options,
|
|
5
|
+
// agent instructions, ownership, and decision records. Every candidate is a
|
|
6
|
+
// proposal with a source reference. None becomes a rule without review.
|
|
7
|
+
//
|
|
8
|
+
// `filesWritten` is the literal 0. A dry run cannot record a write.
|
|
9
|
+
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
|
|
12
|
+
export const ONBOARD_REPORT_SCHEMA_VERSION = 1 as const;
|
|
13
|
+
|
|
14
|
+
export const DeclaredSourceKindSchema = z.enum([
|
|
15
|
+
'agent-instruction',
|
|
16
|
+
'lint-config',
|
|
17
|
+
'formatter-config',
|
|
18
|
+
'type-config',
|
|
19
|
+
'ownership',
|
|
20
|
+
'tooling-config',
|
|
21
|
+
]);
|
|
22
|
+
export type DeclaredSourceKind = z.infer<typeof DeclaredSourceKindSchema>;
|
|
23
|
+
|
|
24
|
+
export const DeclaredSourceSchema = z.object({
|
|
25
|
+
kind: DeclaredSourceKindSchema,
|
|
26
|
+
path: z.string().min(1),
|
|
27
|
+
// false: the file exists but its rules were not extracted (e.g. code-based
|
|
28
|
+
// configs, which are never executed). The note says why.
|
|
29
|
+
parsed: z.boolean(),
|
|
30
|
+
note: z.string().optional(),
|
|
31
|
+
});
|
|
32
|
+
export type DeclaredSource = z.infer<typeof DeclaredSourceSchema>;
|
|
33
|
+
|
|
34
|
+
export const CandidateStandardSchema = z.object({
|
|
35
|
+
// Stable across runs: derived from the source path and the statement.
|
|
36
|
+
id: z.string().min(1),
|
|
37
|
+
kind: DeclaredSourceKindSchema,
|
|
38
|
+
statement: z.string().min(1),
|
|
39
|
+
source: z.object({
|
|
40
|
+
path: z.string().min(1),
|
|
41
|
+
line: z.number().int().positive().optional(),
|
|
42
|
+
}),
|
|
43
|
+
status: z.literal('proposed'),
|
|
44
|
+
});
|
|
45
|
+
export type CandidateStandard = z.infer<typeof CandidateStandardSchema>;
|
|
46
|
+
|
|
47
|
+
export const DecisionRecordSchema = z.object({
|
|
48
|
+
id: z.string().min(1),
|
|
49
|
+
title: z.string().min(1),
|
|
50
|
+
path: z.string().min(1),
|
|
51
|
+
});
|
|
52
|
+
export type DecisionRecord = z.infer<typeof DecisionRecordSchema>;
|
|
53
|
+
|
|
54
|
+
export const DeclarationConflictSchema = z.object({
|
|
55
|
+
kind: z.enum(['multiple-config-files', 'duplicate-statement']),
|
|
56
|
+
// The tool whose configuration conflicts, or 'declared-standards' for prose.
|
|
57
|
+
subject: z.string().min(1),
|
|
58
|
+
paths: z.array(z.string().min(1)).min(1),
|
|
59
|
+
detail: z.string().min(1),
|
|
60
|
+
});
|
|
61
|
+
export type DeclarationConflict = z.infer<typeof DeclarationConflictSchema>;
|
|
62
|
+
|
|
63
|
+
export const MissingToolSchema = z.object({
|
|
64
|
+
tool: z.string().min(1),
|
|
65
|
+
// The configuration file that names the tool.
|
|
66
|
+
declaredIn: z.string().min(1),
|
|
67
|
+
});
|
|
68
|
+
export type MissingTool = z.infer<typeof MissingToolSchema>;
|
|
69
|
+
|
|
70
|
+
export const OnboardNoteSchema = z.object({
|
|
71
|
+
severity: z.enum(['info', 'warning']),
|
|
72
|
+
message: z.string().min(1),
|
|
73
|
+
});
|
|
74
|
+
export type OnboardNote = z.infer<typeof OnboardNoteSchema>;
|
|
75
|
+
|
|
76
|
+
export const OnboardReportSchema = z.object({
|
|
77
|
+
schemaVersion: z.literal(ONBOARD_REPORT_SCHEMA_VERSION),
|
|
78
|
+
mode: z.literal('dry-run'),
|
|
79
|
+
filesWritten: z.literal(0),
|
|
80
|
+
// HEAD commit at the time of the scan, or null outside a git repository.
|
|
81
|
+
revision: z.string().regex(/^([0-9a-f]{40})?$/).nullable(),
|
|
82
|
+
stacks: z.array(z.string()),
|
|
83
|
+
packageManagers: z.array(z.string()),
|
|
84
|
+
testFrameworks: z.array(z.string()),
|
|
85
|
+
hasCi: z.boolean(),
|
|
86
|
+
sources: z.array(DeclaredSourceSchema),
|
|
87
|
+
candidates: z.array(CandidateStandardSchema),
|
|
88
|
+
decisions: z.array(DecisionRecordSchema),
|
|
89
|
+
notes: z.array(OnboardNoteSchema),
|
|
90
|
+
// Defaults keep reports written before these fields existed valid.
|
|
91
|
+
conflicts: z.array(DeclarationConflictSchema).default([]),
|
|
92
|
+
// Tools that the configuration names but that are not installed. Depends on
|
|
93
|
+
// the machine running the dry run, and the report says so.
|
|
94
|
+
missingTools: z.array(MissingToolSchema).default([]),
|
|
95
|
+
});
|
|
96
|
+
export type OnboardReport = z.infer<typeof OnboardReportSchema>;
|
|
97
|
+
|
|
98
|
+
// Result of `kit onboard` (write mode). A write is pinned to a git revision so
|
|
99
|
+
// the adoption point is auditable. Rules are only added, never overwritten.
|
|
100
|
+
export const OnboardWriteResultSchema = z.object({
|
|
101
|
+
schemaVersion: z.literal(ONBOARD_REPORT_SCHEMA_VERSION),
|
|
102
|
+
mode: z.literal('write'),
|
|
103
|
+
revision: z.string().regex(/^[0-9a-f]{40}$/),
|
|
104
|
+
rulesWritten: z.array(z.string().min(1)),
|
|
105
|
+
// Candidates that already have a proposed rule from an earlier run.
|
|
106
|
+
rulesAlreadyProposed: z.array(z.string().min(1)),
|
|
107
|
+
// Proposed rules whose candidate no longer appears in the sources. They are
|
|
108
|
+
// left in place for a human to retire.
|
|
109
|
+
staleProposals: z.array(z.string().min(1)),
|
|
110
|
+
baseline: z.object({
|
|
111
|
+
status: z.enum(['written', 'kept-existing']),
|
|
112
|
+
entries: z.number().int().nonnegative(),
|
|
113
|
+
}),
|
|
114
|
+
});
|
|
115
|
+
export type OnboardWriteResult = z.infer<typeof OnboardWriteResultSchema>;
|
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
// See docs/contracts/CONTRACTS.md §2 and ADR-0008.
|
|
9
9
|
|
|
10
10
|
import { z } from 'zod';
|
|
11
|
+
import { StrengthSettingsSchema } from '../verification/strength.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Schema version for the ProjectProfile contract. Bumped on breaking
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
* changes; requires an ADR and a migration function in
|
|
16
|
+
* core/artifacts/migrations/.
|
|
16
17
|
*/
|
|
17
18
|
export const PROJECT_PROFILE_SCHEMA_VERSION = 1 as const;
|
|
18
19
|
|
|
@@ -33,6 +34,18 @@ export const CommandsMapSchema = z
|
|
|
33
34
|
})
|
|
34
35
|
.strict();
|
|
35
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Verification settings overlay (ADR-0022). Optional, absent by
|
|
39
|
+
* default: a profile without a `verification` section keeps the exact
|
|
40
|
+
* pre-ADR-0022 behavior — strength evidence is opt-in.
|
|
41
|
+
*/
|
|
42
|
+
export const VerificationSettingsSectionSchema = z
|
|
43
|
+
.object({
|
|
44
|
+
strength: StrengthSettingsSchema.optional(),
|
|
45
|
+
})
|
|
46
|
+
.strict();
|
|
47
|
+
export type VerificationSettingsSection = z.infer<typeof VerificationSettingsSectionSchema>;
|
|
48
|
+
|
|
36
49
|
export const ProjectProfileSchema = z
|
|
37
50
|
.object({
|
|
38
51
|
schemaVersion: z.literal(PROJECT_PROFILE_SCHEMA_VERSION),
|
|
@@ -47,6 +60,10 @@ export const ProjectProfileSchema = z
|
|
|
47
60
|
)
|
|
48
61
|
.min(1, 'stack must contain at least one entry'),
|
|
49
62
|
commands: CommandsMapSchema,
|
|
63
|
+
verification: VerificationSettingsSectionSchema.optional(),
|
|
64
|
+
// Engineering constitution policy (ADR-0023). required: true means a failed
|
|
65
|
+
// or unavailable constitution must never be reported as passing.
|
|
66
|
+
constitution: z.object({ required: z.boolean() }).strict().optional(),
|
|
50
67
|
})
|
|
51
68
|
.strict();
|
|
52
69
|
|
package/src/routing/index.ts
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// packages/contracts/src/routing/measured-routing.ts
|
|
2
|
+
//
|
|
3
|
+
// Empirical routing (roadmap Phase 7, issue #48). One observed run, with no free text: a prompt, a
|
|
4
|
+
// model reply or a source excerpt cannot be represented. Measured evidence can only refine the
|
|
5
|
+
// static M12 policy, never replace an explicit user model.
|
|
6
|
+
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { LearningTaskTypeSchema } from '../learning/learning-event.js';
|
|
9
|
+
|
|
10
|
+
export const ROUTING_OBSERVATION_SCHEMA_VERSION = 1 as const;
|
|
11
|
+
|
|
12
|
+
export const MeasuredRoutingObservationSchema = z
|
|
13
|
+
.object({
|
|
14
|
+
schemaVersion: z.literal(ROUTING_OBSERVATION_SCHEMA_VERSION),
|
|
15
|
+
id: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.-]{0,95}$/),
|
|
16
|
+
occurredAt: z.string().datetime(),
|
|
17
|
+
taskType: LearningTaskTypeSchema,
|
|
18
|
+
model: z.string().regex(/^[A-Za-z0-9][A-Za-z0-9._:/-]{0,79}$/, 'model must be an identifier'),
|
|
19
|
+
effort: z.enum(['low', 'medium', 'high']),
|
|
20
|
+
verdict: z.enum(['passed', 'failed', 'blocked']),
|
|
21
|
+
tokensIn: z.number().int().nonnegative(),
|
|
22
|
+
tokensOut: z.number().int().nonnegative(),
|
|
23
|
+
costUnits: z.number().nonnegative(),
|
|
24
|
+
latencyMs: z.number().int().nonnegative(),
|
|
25
|
+
})
|
|
26
|
+
.strict();
|
|
27
|
+
export type MeasuredRoutingObservation = z.infer<typeof MeasuredRoutingObservationSchema>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { StackPackManifestSchema } from './manifest.js';
|
|
3
|
+
|
|
4
|
+
const base = {
|
|
5
|
+
schemaVersion: 1,
|
|
6
|
+
id: 'node-typescript',
|
|
7
|
+
name: 'Node TypeScript',
|
|
8
|
+
description: 'd',
|
|
9
|
+
version: '1.0.0',
|
|
10
|
+
stacks: ['node-typescript'],
|
|
11
|
+
kitCompatibility: '>=0.9.0',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
describe('StackPackManifestSchema ruleSets', () => {
|
|
15
|
+
it('accepts typed rule set references inside the pack', () => {
|
|
16
|
+
const res = StackPackManifestSchema.safeParse({
|
|
17
|
+
...base,
|
|
18
|
+
ruleSets: [{ id: 'node-core', path: 'rules/node-core.yml' }],
|
|
19
|
+
});
|
|
20
|
+
expect(res.success).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it.each(['../outside.yml', '/abs/rules.yml', 'C:/rules.yml', 'rules\\..\\x.yml'])(
|
|
24
|
+
'rejects an unsafe rule set path %p',
|
|
25
|
+
(path) => {
|
|
26
|
+
expect(StackPackManifestSchema.safeParse({ ...base, ruleSets: [{ id: 'x', path }] }).success).toBe(false);
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
it('rejects a non-kebab rule set id', () => {
|
|
31
|
+
expect(
|
|
32
|
+
StackPackManifestSchema.safeParse({ ...base, ruleSets: [{ id: 'Node_Core', path: 'r.yml' }] }).success,
|
|
33
|
+
).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('accepts an empty legacy policies field', () => {
|
|
37
|
+
expect(StackPackManifestSchema.safeParse({ ...base, policies: [] }).success).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('rejects a non-empty legacy policies field with a migration message', () => {
|
|
41
|
+
const res = StackPackManifestSchema.safeParse({ ...base, policies: ['always use services'] });
|
|
42
|
+
expect(res.success).toBe(false);
|
|
43
|
+
if (!res.success) expect(res.error.issues[0]?.message).toMatch(/replaced by ruleSets/);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -8,6 +8,21 @@ import { z } from 'zod';
|
|
|
8
8
|
|
|
9
9
|
export const STACK_PACK_MANIFEST_SCHEMA_VERSION = 1 as const;
|
|
10
10
|
|
|
11
|
+
function isSafeRelativePath(p: string): boolean {
|
|
12
|
+
if (p.startsWith('/') || /^[A-Za-z]:/.test(p) || p.includes('\\')) return false;
|
|
13
|
+
return !p.split('/').some((segment) => segment === '..');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const RuleSetRefSchema = z.object({
|
|
17
|
+
id: z.string().regex(/^[a-z][a-z0-9-]*$/, 'rule set id must be kebab-case'),
|
|
18
|
+
// Relative to the pack root: a YAML rule file, or a directory of them.
|
|
19
|
+
path: z
|
|
20
|
+
.string()
|
|
21
|
+
.min(1)
|
|
22
|
+
.refine(isSafeRelativePath, 'path must be relative to the pack root, without traversal'),
|
|
23
|
+
});
|
|
24
|
+
export type RuleSetRef = z.infer<typeof RuleSetRefSchema>;
|
|
25
|
+
|
|
11
26
|
export const StackPackManifestSchema = z.object({
|
|
12
27
|
schemaVersion: z.literal(STACK_PACK_MANIFEST_SCHEMA_VERSION),
|
|
13
28
|
id: z.string().regex(/^[a-z][a-z0-9-]*$/, 'stack id must be kebab-case'),
|
|
@@ -34,8 +49,15 @@ export const StackPackManifestSchema = z.object({
|
|
|
34
49
|
}),
|
|
35
50
|
)
|
|
36
51
|
.default([]),
|
|
37
|
-
//
|
|
38
|
-
policies
|
|
52
|
+
// Typed EngineeringRule sets shipped with the pack (ADR-0023). Replaces the
|
|
53
|
+
// opaque `policies` strings, which nothing ever read.
|
|
54
|
+
ruleSets: z.array(RuleSetRefSchema).default([]),
|
|
55
|
+
// Removed field. Accepted only when empty, so an old manifest that declares
|
|
56
|
+
// entries fails loudly instead of losing them.
|
|
57
|
+
policies: z
|
|
58
|
+
.array(z.string())
|
|
59
|
+
.max(0, 'policies was replaced by ruleSets (ADR-0023): move each entry to ruleSets')
|
|
60
|
+
.optional(),
|
|
39
61
|
// Whether this pack depends on another pack.
|
|
40
62
|
dependsOn: z.array(z.string()).default([]),
|
|
41
63
|
});
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// See docs/security/SECURITY.md §1 (no false assurance).
|
|
14
14
|
|
|
15
15
|
import { z } from 'zod';
|
|
16
|
+
import { RuleResultSchema } from '../constitution/result.js';
|
|
16
17
|
|
|
17
18
|
export const CheckStatusSchema = z.enum(['passed', 'failed', 'skipped', 'blocked']);
|
|
18
19
|
export type CheckStatus = z.infer<typeof CheckStatusSchema>;
|
|
@@ -37,6 +38,9 @@ export const VerificationReportSchema = z.object({
|
|
|
37
38
|
.optional(),
|
|
38
39
|
status: z.enum(['passed', 'failed', 'blocked']),
|
|
39
40
|
checks: z.array(CheckSchema),
|
|
41
|
+
// Per-rule detail for the engineering constitution (ADR-0023). Absent when
|
|
42
|
+
// the project has no constitution.
|
|
43
|
+
rules: z.array(RuleResultSchema).optional(),
|
|
40
44
|
});
|
|
41
45
|
|
|
42
46
|
export type Check = z.infer<typeof CheckSchema>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// packages/contracts/src/verification/strength.test.ts
|
|
2
|
+
//
|
|
3
|
+
// Offline contract tests for StrengthEvidence: schema invariants,
|
|
4
|
+
// score computation, and gate evaluation (ADR-0022).
|
|
5
|
+
|
|
6
|
+
import { describe, expect, it } from 'vitest';
|
|
7
|
+
import {
|
|
8
|
+
computeMutationScore,
|
|
9
|
+
evaluateStrengthGate,
|
|
10
|
+
MutationToolSchema,
|
|
11
|
+
resolveStrengthStatus,
|
|
12
|
+
StrengthEvidenceSchema,
|
|
13
|
+
StrengthSettingsSchema,
|
|
14
|
+
} from './strength.js';
|
|
15
|
+
|
|
16
|
+
function validEvidence(overrides: Record<string, unknown> = {}) {
|
|
17
|
+
return {
|
|
18
|
+
schemaVersion: 1,
|
|
19
|
+
tool: 'stryker',
|
|
20
|
+
status: 'passed',
|
|
21
|
+
score: 72,
|
|
22
|
+
mutantsGenerated: 50,
|
|
23
|
+
mutantsKilled: 36,
|
|
24
|
+
mutantsSurvived: 14,
|
|
25
|
+
threshold: 60,
|
|
26
|
+
scope: 'diff',
|
|
27
|
+
scopeFiles: ['src/index.ts'],
|
|
28
|
+
durationMs: 12_000,
|
|
29
|
+
budgetMs: 300_000,
|
|
30
|
+
summary: '36/50 mutants killed (72% >= 60%)',
|
|
31
|
+
...overrides,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('StrengthEvidenceSchema', () => {
|
|
36
|
+
it('accepts a valid completed run', () => {
|
|
37
|
+
const parsed = StrengthEvidenceSchema.safeParse(validEvidence());
|
|
38
|
+
expect(parsed.success).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('accepts an incomplete run without a score', () => {
|
|
42
|
+
const parsed = StrengthEvidenceSchema.safeParse(
|
|
43
|
+
validEvidence({
|
|
44
|
+
status: 'incomplete',
|
|
45
|
+
mutantsGenerated: 0,
|
|
46
|
+
mutantsKilled: 0,
|
|
47
|
+
mutantsSurvived: 0,
|
|
48
|
+
score: undefined,
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
expect(parsed.success).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('rejects a completed run without a score', () => {
|
|
55
|
+
const parsed = StrengthEvidenceSchema.safeParse(validEvidence({ score: undefined }));
|
|
56
|
+
expect(parsed.success).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('rejects an incomplete run that fabricates a score', () => {
|
|
60
|
+
const parsed = StrengthEvidenceSchema.safeParse(validEvidence({ status: 'incomplete' }));
|
|
61
|
+
expect(parsed.success).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('rejects killed + survived exceeding generated mutants', () => {
|
|
65
|
+
const parsed = StrengthEvidenceSchema.safeParse(
|
|
66
|
+
validEvidence({ mutantsKilled: 40, mutantsSurvived: 20 }),
|
|
67
|
+
);
|
|
68
|
+
expect(parsed.success).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('rejects an unknown mutation tool', () => {
|
|
72
|
+
const parsed = StrengthEvidenceSchema.safeParse(validEvidence({ tool: 'cosmic-ray' }));
|
|
73
|
+
expect(parsed.success).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('rejects unknown extra fields (strict shape)', () => {
|
|
77
|
+
const parsed = StrengthEvidenceSchema.safeParse(validEvidence({ extra: 'no' }));
|
|
78
|
+
expect(parsed.success).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('MutationToolSchema', () => {
|
|
83
|
+
it('accepts every documented adapter tool', () => {
|
|
84
|
+
for (const tool of [
|
|
85
|
+
'stryker',
|
|
86
|
+
'mutmut',
|
|
87
|
+
'mutant',
|
|
88
|
+
'go-mutesting',
|
|
89
|
+
'gremlins',
|
|
90
|
+
'cargo-mutants',
|
|
91
|
+
'stryker-net',
|
|
92
|
+
]) {
|
|
93
|
+
expect(MutationToolSchema.safeParse(tool).success).toBe(true);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('StrengthSettingsSchema', () => {
|
|
99
|
+
it('accepts the documented settings surface', () => {
|
|
100
|
+
const parsed = StrengthSettingsSchema.safeParse({
|
|
101
|
+
enabled: true,
|
|
102
|
+
threshold: 60,
|
|
103
|
+
budgetMs: 300_000,
|
|
104
|
+
scope: 'diff',
|
|
105
|
+
gateMode: 'enforce',
|
|
106
|
+
});
|
|
107
|
+
expect(parsed.success).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('rejects an out-of-range threshold', () => {
|
|
111
|
+
expect(StrengthSettingsSchema.safeParse({ threshold: 101 }).success).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('computeMutationScore', () => {
|
|
116
|
+
it('computes a rounded percentage', () => {
|
|
117
|
+
expect(computeMutationScore(36, 50)).toBe(72);
|
|
118
|
+
expect(computeMutationScore(1, 3)).toBe(33);
|
|
119
|
+
expect(computeMutationScore(0, 10)).toBe(0);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('returns null when no mutants were generated', () => {
|
|
123
|
+
expect(computeMutationScore(0, 0)).toBeNull();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('resolveStrengthStatus', () => {
|
|
128
|
+
it('passes at threshold, fails below it', () => {
|
|
129
|
+
expect(resolveStrengthStatus(60, 60)).toBe('passed');
|
|
130
|
+
expect(resolveStrengthStatus(59.6, 60)).toBe('failed');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('treats an unmeasurable suite as incomplete', () => {
|
|
134
|
+
expect(resolveStrengthStatus(null, 60)).toBe('incomplete');
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('evaluateStrengthGate', () => {
|
|
139
|
+
it('warn mode never blocks, including on failure and incomplete', () => {
|
|
140
|
+
expect(evaluateStrengthGate({ status: 'failed', score: 40 }, 'warn').block).toBe(false);
|
|
141
|
+
expect(evaluateStrengthGate({ status: 'incomplete' }, 'warn').block).toBe(false);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('enforce mode blocks below threshold', () => {
|
|
145
|
+
const gate = evaluateStrengthGate({ status: 'failed', score: 40 }, 'enforce');
|
|
146
|
+
expect(gate.block).toBe(true);
|
|
147
|
+
expect(gate.reason).toContain('below the threshold');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('enforce mode fail-closes on an incomplete run', () => {
|
|
151
|
+
const gate = evaluateStrengthGate({ status: 'incomplete' }, 'enforce');
|
|
152
|
+
expect(gate.block).toBe(true);
|
|
153
|
+
expect(gate.reason).toContain('incomplete');
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('enforce mode passes a meeting score', () => {
|
|
157
|
+
const gate = evaluateStrengthGate({ status: 'passed', score: 60 }, 'enforce');
|
|
158
|
+
expect(gate.block).toBe(false);
|
|
159
|
+
});
|
|
160
|
+
});
|