@agentic-sdlc-kit/contracts 0.8.0 → 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 +10 -2
- package/dist/installer/ownership-manifest.d.ts.map +1 -1
- package/dist/installer/ownership-manifest.js +4 -0
- package/dist/installer/ownership-manifest.js.map +1 -1
- 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 +5 -5
- package/dist/secret-guard/detection-rule.d.ts.map +1 -1
- package/dist/secret-guard/detection-rule.js +44 -0
- package/dist/secret-guard/detection-rule.js.map +1 -1
- package/dist/secret-guard/finding.d.ts +12 -12
- package/dist/secret-guard/finding.d.ts.map +1 -1
- package/dist/secret-guard/finding.js +2 -0
- package/dist/secret-guard/finding.js.map +1 -1
- 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/installer/ownership-manifest.ts +4 -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/secret-guard/detection-rule.ts +53 -0
- package/src/secret-guard/finding.ts +2 -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,36 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { EngineeringRuleSchema } from './rule.js';
|
|
3
|
+
|
|
4
|
+
const base = {
|
|
5
|
+
schemaVersion: 1,
|
|
6
|
+
id: 'ONB-AGENT-001',
|
|
7
|
+
title: 't',
|
|
8
|
+
statement: 's',
|
|
9
|
+
rationale: 'r',
|
|
10
|
+
scope: { paths: ['**/*'] },
|
|
11
|
+
status: 'proposed',
|
|
12
|
+
mode: 'off',
|
|
13
|
+
check: { kind: 'guidance-only' },
|
|
14
|
+
source: 'declared',
|
|
15
|
+
confidence: 1,
|
|
16
|
+
owner: 'unassigned',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe('EngineeringRule origin (provenance)', () => {
|
|
20
|
+
it('accepts an origin naming the candidate and its source', () => {
|
|
21
|
+
const res = EngineeringRuleSchema.safeParse({
|
|
22
|
+
...base,
|
|
23
|
+
origin: { candidateId: 'declared:agent-instruction:AGENTS.md#abc', path: 'AGENTS.md', line: 4 },
|
|
24
|
+
});
|
|
25
|
+
expect(res.success).toBe(true);
|
|
26
|
+
if (res.success) expect(res.data.origin?.line).toBe(4);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('origin is optional', () => {
|
|
30
|
+
expect(EngineeringRuleSchema.safeParse(base).success).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('rejects an origin without a candidate id', () => {
|
|
34
|
+
expect(EngineeringRuleSchema.safeParse({ ...base, origin: { path: 'AGENTS.md' } }).success).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { describe as describeRule, expect as expectRule, it as itRule } from 'vitest';
|
|
2
|
+
import { RuleCheckSchema, isRepoRelativePath } from './rule.js';
|
|
3
|
+
|
|
4
|
+
describeRule('rule file paths are repository-relative', () => {
|
|
5
|
+
itRule.each(['rules/no-eval.yml', 'a/b/c.yml'])('accepts %s', (p) => {
|
|
6
|
+
expectRule(isRepoRelativePath(p)).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
itRule.each(['/etc/rules.yml', '../outside.yml', 'C:/x.yml', 'a\\..\\x.yml', ''])('rejects %p', (p) => {
|
|
9
|
+
expectRule(isRepoRelativePath(p)).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
itRule('an ast-grep check with an unsafe ruleFile is rejected by the contract', () => {
|
|
12
|
+
expectRule(RuleCheckSchema.safeParse({ kind: 'ast-grep', ruleFile: '../x.yml' }).success).toBe(false);
|
|
13
|
+
expectRule(RuleCheckSchema.safeParse({ kind: 'ast-grep', ruleFile: 'rules/x.yml' }).success).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// packages/contracts/src/constitution/rule.test.ts
|
|
2
|
+
//
|
|
3
|
+
// Offline contract tests for EngineeringRule and Baseline (ADR-0023).
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
import {
|
|
7
|
+
BaselineSchema,
|
|
8
|
+
EngineeringRuleSchema,
|
|
9
|
+
isAtLeastAsStrict,
|
|
10
|
+
modeFailsGate,
|
|
11
|
+
} from './rule.js';
|
|
12
|
+
|
|
13
|
+
const SHA = 'abc1234';
|
|
14
|
+
const FP = 'a'.repeat(64);
|
|
15
|
+
|
|
16
|
+
function rule(overrides: Record<string, unknown> = {}) {
|
|
17
|
+
return {
|
|
18
|
+
schemaVersion: 1,
|
|
19
|
+
id: 'ARCH-CORE-001',
|
|
20
|
+
title: 'core imports only contracts',
|
|
21
|
+
statement: 'packages/core may import only @agentic-sdlc-kit/contracts.',
|
|
22
|
+
rationale: 'ADR-0004 runtime-independent core.',
|
|
23
|
+
scope: { paths: ['packages/core/src/**'] },
|
|
24
|
+
status: 'active',
|
|
25
|
+
mode: 'blocking',
|
|
26
|
+
check: { kind: 'import-boundary', from: 'packages/core', allow: ['@agentic-sdlc-kit/contracts'] },
|
|
27
|
+
source: 'human',
|
|
28
|
+
confidence: 1,
|
|
29
|
+
owner: 'architecture',
|
|
30
|
+
...overrides,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function baseline(overrides: Record<string, unknown> = {}) {
|
|
35
|
+
return {
|
|
36
|
+
schemaVersion: 1,
|
|
37
|
+
capturedAt: '2026-11-28T00:00:00.000Z',
|
|
38
|
+
revision: SHA,
|
|
39
|
+
entries: [{ ruleId: 'ARCH-CORE-001', path: 'a.ts', fingerprint: FP }],
|
|
40
|
+
...overrides,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('EngineeringRuleSchema', () => {
|
|
45
|
+
it('accepts a blocking import-boundary rule and applies defaults', () => {
|
|
46
|
+
const parsed = EngineeringRuleSchema.parse(rule());
|
|
47
|
+
expect(parsed.evidence).toEqual([]);
|
|
48
|
+
expect(parsed.supersedes).toEqual([]);
|
|
49
|
+
expect(parsed.scope.exclude).toEqual([]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('rejects blocking with a guidance-only check', () => {
|
|
53
|
+
const res = EngineeringRuleSchema.safeParse(rule({ check: { kind: 'guidance-only' } }));
|
|
54
|
+
expect(res.success).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('does not carry approval metadata: ratifiedIn is not part of the contract', () => {
|
|
58
|
+
const parsed = EngineeringRuleSchema.parse(rule({ ratifiedIn: 'abc1234' }));
|
|
59
|
+
expect('ratifiedIn' in parsed).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('accepts guidance-only in shadow mode', () => {
|
|
63
|
+
const res = EngineeringRuleSchema.safeParse(
|
|
64
|
+
rule({ check: { kind: 'guidance-only' }, mode: 'shadow', status: 'proposed' }),
|
|
65
|
+
);
|
|
66
|
+
expect(res.success).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('allows advisory and blocking for an active rule without any approval field', () => {
|
|
70
|
+
expect(EngineeringRuleSchema.safeParse(rule({ mode: 'advisory' })).success).toBe(true);
|
|
71
|
+
expect(EngineeringRuleSchema.safeParse(rule({ mode: 'blocking' })).success).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it.each(['advisory', 'blocking'])('rejects a proposed rule in %s mode', (mode) => {
|
|
75
|
+
expect(EngineeringRuleSchema.safeParse(rule({ status: 'proposed', mode })).success).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it.each(['deprecated', 'retired'])('rejects a %s rule in blocking mode', (status) => {
|
|
79
|
+
expect(EngineeringRuleSchema.safeParse(rule({ status })).success).toBe(false);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it.each(['deprecated', 'retired'])('accepts a %s rule only in off mode', (status) => {
|
|
83
|
+
const ok = rule({ status, mode: 'off' });
|
|
84
|
+
expect(EngineeringRuleSchema.safeParse(ok).success).toBe(true);
|
|
85
|
+
for (const mode of ['shadow', 'advisory'] as const) {
|
|
86
|
+
expect(EngineeringRuleSchema.safeParse(rule({ status, mode })).success).toBe(false);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('rejects self-supersession', () => {
|
|
91
|
+
expect(EngineeringRuleSchema.safeParse(rule({ supersedes: ['ARCH-CORE-001'] })).success).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it.each(['arch-core-001', 'ARCH-CORE', 'ARCH-CORE-1', 'ARCH--001', '001'])(
|
|
95
|
+
'rejects malformed id %s',
|
|
96
|
+
(id) => {
|
|
97
|
+
expect(EngineeringRuleSchema.safeParse(rule({ id })).success).toBe(false);
|
|
98
|
+
},
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
it.each(['RAILS-SERVICE-001', 'SEC-001', 'TS-REACT-HOOKS-012'])('accepts id %s', (id) => {
|
|
102
|
+
expect(EngineeringRuleSchema.safeParse(rule({ id })).success).toBe(true);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('rejects empty scope paths', () => {
|
|
106
|
+
expect(EngineeringRuleSchema.safeParse(rule({ scope: { paths: [] } })).success).toBe(false);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('rejects out-of-range confidence', () => {
|
|
110
|
+
expect(EngineeringRuleSchema.safeParse(rule({ confidence: 1.1 })).success).toBe(false);
|
|
111
|
+
expect(EngineeringRuleSchema.safeParse(rule({ confidence: -0.1 })).success).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('rejects a non-sha evidence revision', () => {
|
|
115
|
+
const bad = rule({ evidence: [{ path: 'a.ts', revision: 'HEAD' }] });
|
|
116
|
+
expect(EngineeringRuleSchema.safeParse(bad).success).toBe(false);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('rejects unknown check kinds and unknown modes', () => {
|
|
120
|
+
expect(EngineeringRuleSchema.safeParse(rule({ check: { kind: 'llm-review' } })).success).toBe(false);
|
|
121
|
+
expect(EngineeringRuleSchema.safeParse(rule({ mode: 'strict' })).success).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('rejects an unsupported schemaVersion', () => {
|
|
125
|
+
expect(EngineeringRuleSchema.safeParse(rule({ schemaVersion: 2 })).success).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('accepts a command check that references a registered commandId', () => {
|
|
129
|
+
const res = EngineeringRuleSchema.safeParse(rule({ check: { kind: 'command', commandId: 'rails-rspec' } }));
|
|
130
|
+
expect(res.success).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it.each(['bundle exec rspec', 'Rails_RSpec', '../bin/x', '', '/usr/bin/rm'])(
|
|
134
|
+
'rejects command check id %p (must be a kebab-case registered id)',
|
|
135
|
+
(commandId) => {
|
|
136
|
+
const res = EngineeringRuleSchema.safeParse(rule({ check: { kind: 'command', commandId } }));
|
|
137
|
+
expect(res.success).toBe(false);
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
it('strips smuggled argv from a command check, so rules cannot carry executables', () => {
|
|
142
|
+
const res = EngineeringRuleSchema.safeParse(
|
|
143
|
+
rule({ check: { kind: 'command', commandId: 'rails-rspec', argv: ['rm', '-rf', '/'] } }),
|
|
144
|
+
);
|
|
145
|
+
expect(res.success).toBe(true);
|
|
146
|
+
expect(res.success && 'argv' in res.data.check).toBe(false);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('accepts only registered linter tools', () => {
|
|
150
|
+
const ok = rule({ check: { kind: 'linter', tool: 'rubocop', ruleId: 'Style/Foo' } });
|
|
151
|
+
expect(EngineeringRuleSchema.safeParse(ok).success).toBe(true);
|
|
152
|
+
const bad = rule({ check: { kind: 'linter', tool: 'curl', ruleId: 'x' } });
|
|
153
|
+
expect(EngineeringRuleSchema.safeParse(bad).success).toBe(false);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('BaselineSchema', () => {
|
|
158
|
+
it('accepts a valid baseline', () => {
|
|
159
|
+
expect(BaselineSchema.safeParse(baseline()).success).toBe(true);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('accepts an empty baseline', () => {
|
|
163
|
+
expect(BaselineSchema.safeParse(baseline({ entries: [] })).success).toBe(true);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('rejects a non-sha256 fingerprint', () => {
|
|
167
|
+
const bad = baseline({ entries: [{ ruleId: 'ARCH-CORE-001', path: 'a.ts', fingerprint: 'abc' }] });
|
|
168
|
+
expect(BaselineSchema.safeParse(bad).success).toBe(false);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('defaults occurrence count to 1 and rejects non-positive counts', () => {
|
|
172
|
+
const parsed = BaselineSchema.parse(baseline());
|
|
173
|
+
expect(parsed.entries[0]?.count).toBe(1);
|
|
174
|
+
const zero = baseline({ entries: [{ ruleId: 'ARCH-CORE-001', path: 'a.ts', fingerprint: FP, count: 0 }] });
|
|
175
|
+
expect(BaselineSchema.safeParse(zero).success).toBe(false);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('rejects duplicate rule+fingerprint entries (use count instead)', () => {
|
|
179
|
+
const entry = { ruleId: 'ARCH-CORE-001', path: 'a.ts', fingerprint: FP };
|
|
180
|
+
expect(BaselineSchema.safeParse(baseline({ entries: [entry, entry] })).success).toBe(false);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('allows one fingerprint under different rules', () => {
|
|
184
|
+
const entries = [
|
|
185
|
+
{ ruleId: 'ARCH-CORE-001', path: 'a.ts', fingerprint: FP },
|
|
186
|
+
{ ruleId: 'ARCH-CLI-002', path: 'a.ts', fingerprint: FP },
|
|
187
|
+
];
|
|
188
|
+
expect(BaselineSchema.safeParse(baseline({ entries })).success).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('rejects a bad timestamp or revision', () => {
|
|
192
|
+
expect(BaselineSchema.safeParse(baseline({ capturedAt: 'yesterday' })).success).toBe(false);
|
|
193
|
+
expect(BaselineSchema.safeParse(baseline({ revision: 'main' })).success).toBe(false);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('mode helpers', () => {
|
|
198
|
+
it('only blocking fails the gate', () => {
|
|
199
|
+
expect(modeFailsGate('blocking')).toBe(true);
|
|
200
|
+
for (const m of ['off', 'shadow', 'advisory'] as const) expect(modeFailsGate(m)).toBe(false);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('orders modes by strictness so org rules can only be tightened', () => {
|
|
204
|
+
expect(isAtLeastAsStrict('blocking', 'advisory')).toBe(true);
|
|
205
|
+
expect(isAtLeastAsStrict('advisory', 'advisory')).toBe(true);
|
|
206
|
+
expect(isAtLeastAsStrict('shadow', 'blocking')).toBe(false);
|
|
207
|
+
expect(isAtLeastAsStrict('off', 'shadow')).toBe(false);
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// packages/contracts/src/constitution/rule.ts
|
|
2
|
+
//
|
|
3
|
+
// ADR-0023: one model for artifact-level engineering rules (what code may
|
|
4
|
+
// look like). Action-level governance (what the agent may do) stays in the
|
|
5
|
+
// runtime-guard PolicyPack; merging them would weaken ADR-0009's
|
|
6
|
+
// terminal-deny invariant.
|
|
7
|
+
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
|
|
10
|
+
export const RULE_SCHEMA_VERSION = 1 as const;
|
|
11
|
+
export const BASELINE_SCHEMA_VERSION = 1 as const;
|
|
12
|
+
|
|
13
|
+
const GIT_SHA = /^[0-9a-f]{7,40}$/;
|
|
14
|
+
|
|
15
|
+
export const EnforcementModeSchema = z.enum(['off', 'shadow', 'advisory', 'blocking']);
|
|
16
|
+
export type EnforcementMode = z.infer<typeof EnforcementModeSchema>;
|
|
17
|
+
|
|
18
|
+
export const RuleStatusSchema = z.enum(['proposed', 'active', 'deprecated', 'retired']);
|
|
19
|
+
export type RuleStatus = z.infer<typeof RuleStatusSchema>;
|
|
20
|
+
|
|
21
|
+
export const RuleSourceSchema = z.enum([
|
|
22
|
+
'declared', // harvested from linter config / AGENTS.md / ADR
|
|
23
|
+
'detected', // inferred from code statistics
|
|
24
|
+
'human',
|
|
25
|
+
'review',
|
|
26
|
+
'correction',
|
|
27
|
+
'ci',
|
|
28
|
+
'stack-default',
|
|
29
|
+
'org-baseline',
|
|
30
|
+
]);
|
|
31
|
+
export type RuleSource = z.infer<typeof RuleSourceSchema>;
|
|
32
|
+
|
|
33
|
+
// Adapter registry for linter checks. Adding a tool is a contract change,
|
|
34
|
+
// not a rule-file edit: rules must not name arbitrary executables.
|
|
35
|
+
export const LINTER_TOOLS = ['eslint', 'rubocop', 'ruff', 'golangci-lint'] as const;
|
|
36
|
+
export const LinterToolSchema = z.enum(LINTER_TOOLS);
|
|
37
|
+
export type LinterTool = z.infer<typeof LinterToolSchema>;
|
|
38
|
+
|
|
39
|
+
// A command check references an ID that the project's existing verification
|
|
40
|
+
// configuration defines (executable, args, timeout). Rules never carry argv.
|
|
41
|
+
export const COMMAND_ID_PATTERN = /^[a-z][a-z0-9-]*$/;
|
|
42
|
+
|
|
43
|
+
// Core never parses code itself; each kind maps to exactly one adapter.
|
|
44
|
+
// A repository-relative path: no absolute paths, drive letters, backslashes or traversal.
|
|
45
|
+
// Rules reference files, so a rule can never reach outside the project it belongs to.
|
|
46
|
+
export function isRepoRelativePath(p: string): boolean {
|
|
47
|
+
if (p.length === 0 || p.startsWith('/') || /^[A-Za-z]:/.test(p) || p.includes('\\')) return false;
|
|
48
|
+
return !p.split('/').some((segment) => segment === '..');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const RuleCheckSchema = z.discriminatedUnion('kind', [
|
|
52
|
+
z.object({
|
|
53
|
+
kind: z.literal('import-boundary'),
|
|
54
|
+
from: z.string().min(1),
|
|
55
|
+
allow: z.array(z.string()),
|
|
56
|
+
deny: z.array(z.string()).default([]),
|
|
57
|
+
}),
|
|
58
|
+
z.object({
|
|
59
|
+
kind: z.literal('ast-grep'),
|
|
60
|
+
ruleFile: z.string().min(1).refine(isRepoRelativePath, 'ruleFile must be repository-relative, without traversal'),
|
|
61
|
+
}),
|
|
62
|
+
z.object({ kind: z.literal('linter'), tool: LinterToolSchema, ruleId: z.string().min(1) }),
|
|
63
|
+
z.object({
|
|
64
|
+
kind: z.literal('command'),
|
|
65
|
+
commandId: z.string().regex(COMMAND_ID_PATTERN, 'commandId must be kebab-case'),
|
|
66
|
+
}),
|
|
67
|
+
z.object({ kind: z.literal('guidance-only') }),
|
|
68
|
+
]);
|
|
69
|
+
export type RuleCheck = z.infer<typeof RuleCheckSchema>;
|
|
70
|
+
|
|
71
|
+
export const EvidenceRefSchema = z.object({
|
|
72
|
+
path: z.string().min(1),
|
|
73
|
+
line: z.number().int().positive().optional(),
|
|
74
|
+
revision: z.string().regex(GIT_SHA, 'revision must be a git sha'),
|
|
75
|
+
note: z.string().optional(),
|
|
76
|
+
});
|
|
77
|
+
export type EvidenceRef = z.infer<typeof EvidenceRefSchema>;
|
|
78
|
+
|
|
79
|
+
export const RuleScopeSchema = z.object({
|
|
80
|
+
stacks: z.array(z.string()).default([]),
|
|
81
|
+
paths: z.array(z.string().min(1)).min(1),
|
|
82
|
+
exclude: z.array(z.string()).default([]),
|
|
83
|
+
});
|
|
84
|
+
export type RuleScope = z.infer<typeof RuleScopeSchema>;
|
|
85
|
+
|
|
86
|
+
export const RULE_ID_PATTERN = /^[A-Z][A-Z0-9]*(-[A-Z0-9]+)*-\d{3}$/;
|
|
87
|
+
|
|
88
|
+
export const EngineeringRuleSchema = z
|
|
89
|
+
.object({
|
|
90
|
+
schemaVersion: z.literal(RULE_SCHEMA_VERSION),
|
|
91
|
+
id: z.string().regex(RULE_ID_PATTERN, 'rule id must look like RAILS-SERVICE-001'),
|
|
92
|
+
title: z.string().min(1).max(120),
|
|
93
|
+
statement: z.string().min(1),
|
|
94
|
+
rationale: z.string().min(1),
|
|
95
|
+
scope: RuleScopeSchema,
|
|
96
|
+
status: RuleStatusSchema,
|
|
97
|
+
mode: EnforcementModeSchema,
|
|
98
|
+
check: RuleCheckSchema,
|
|
99
|
+
source: RuleSourceSchema,
|
|
100
|
+
confidence: z.number().min(0).max(1),
|
|
101
|
+
evidence: z.array(EvidenceRefSchema).default([]),
|
|
102
|
+
owner: z.string().min(1),
|
|
103
|
+
patternId: z.string().optional(),
|
|
104
|
+
supersedes: z.array(z.string()).default([]),
|
|
105
|
+
// Cross-repository sharing (ADR-0027). Off by default: a rule leaves its repository only when
|
|
106
|
+
// it says so explicitly. Only rules move; patterns, decisions and memory do not.
|
|
107
|
+
shareable: z.boolean().default(false),
|
|
108
|
+
// Provenance for rules proposed by `kit onboard`: which candidate produced
|
|
109
|
+
// the rule. Lets a re-run reuse the rule id instead of minting a duplicate.
|
|
110
|
+
origin: z
|
|
111
|
+
.object({
|
|
112
|
+
candidateId: z.string().min(1),
|
|
113
|
+
path: z.string().min(1),
|
|
114
|
+
line: z.number().int().positive().optional(),
|
|
115
|
+
})
|
|
116
|
+
.optional(),
|
|
117
|
+
})
|
|
118
|
+
.superRefine((rule, ctx) => {
|
|
119
|
+
const fail = (message: string, path: string[]): void =>
|
|
120
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, message, path });
|
|
121
|
+
if (rule.mode === 'blocking' && rule.check.kind === 'guidance-only') {
|
|
122
|
+
fail('blocking requires a deterministic check', ['check']);
|
|
123
|
+
}
|
|
124
|
+
if (rule.status === 'proposed' && rule.mode !== 'off' && rule.mode !== 'shadow') {
|
|
125
|
+
fail('proposed rules may only run in off or shadow mode', ['mode']);
|
|
126
|
+
}
|
|
127
|
+
if (rule.mode === 'blocking' && rule.status !== 'active') {
|
|
128
|
+
fail('only active rules may block', ['status']);
|
|
129
|
+
}
|
|
130
|
+
if ((rule.status === 'deprecated' || rule.status === 'retired') && rule.mode !== 'off') {
|
|
131
|
+
fail(`${rule.status} rules must be off`, ['mode']);
|
|
132
|
+
}
|
|
133
|
+
if (rule.supersedes.includes(rule.id)) {
|
|
134
|
+
fail('a rule cannot supersede itself', ['supersedes']);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
export type EngineeringRule = z.infer<typeof EngineeringRuleSchema>;
|
|
138
|
+
|
|
139
|
+
export const BaselineEntrySchema = z.object({
|
|
140
|
+
ruleId: z.string().regex(RULE_ID_PATTERN),
|
|
141
|
+
path: z.string().min(1),
|
|
142
|
+
// sha256(ruleId + path + normalized matched snippet): stable across
|
|
143
|
+
// unrelated edits, unlike a line number.
|
|
144
|
+
fingerprint: z.string().regex(/^[0-9a-f]{64}$/, 'fingerprint must be sha256 hex'),
|
|
145
|
+
// Identical violations share a fingerprint; the ratchet compares occurrence
|
|
146
|
+
// counts so a new copy in the same file is not treated as accepted.
|
|
147
|
+
count: z.number().int().positive().default(1),
|
|
148
|
+
});
|
|
149
|
+
export type BaselineEntry = z.infer<typeof BaselineEntrySchema>;
|
|
150
|
+
|
|
151
|
+
export const BaselineSchema = z
|
|
152
|
+
.object({
|
|
153
|
+
schemaVersion: z.literal(BASELINE_SCHEMA_VERSION),
|
|
154
|
+
capturedAt: z.string().datetime(),
|
|
155
|
+
revision: z.string().regex(GIT_SHA, 'revision must be a git sha'),
|
|
156
|
+
entries: z.array(BaselineEntrySchema),
|
|
157
|
+
})
|
|
158
|
+
.superRefine((baseline, ctx) => {
|
|
159
|
+
const seen = new Set<string>();
|
|
160
|
+
baseline.entries.forEach((e, i) => {
|
|
161
|
+
const key = `${e.ruleId}:${e.fingerprint}`;
|
|
162
|
+
if (seen.has(key)) {
|
|
163
|
+
ctx.addIssue({
|
|
164
|
+
code: z.ZodIssueCode.custom,
|
|
165
|
+
message: `duplicate baseline entry ${key}`,
|
|
166
|
+
path: ['entries', i],
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
seen.add(key);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
export type Baseline = z.infer<typeof BaselineSchema>;
|
|
173
|
+
|
|
174
|
+
const MODE_STRICTNESS: Readonly<Record<EnforcementMode, number>> = {
|
|
175
|
+
off: 0,
|
|
176
|
+
shadow: 1,
|
|
177
|
+
advisory: 2,
|
|
178
|
+
blocking: 3,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Organization rules may only be tightened by lower scopes (ADR-0023).
|
|
183
|
+
* True when `override` is at least as strict as `base`.
|
|
184
|
+
*/
|
|
185
|
+
export function isAtLeastAsStrict(override: EnforcementMode, base: EnforcementMode): boolean {
|
|
186
|
+
return MODE_STRICTNESS[override] >= MODE_STRICTNESS[base];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Returns true when a violation in this mode must fail the verification gate. */
|
|
190
|
+
export function modeFailsGate(mode: EnforcementMode): boolean {
|
|
191
|
+
return mode === 'blocking';
|
|
192
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './project-context.js';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// packages/contracts/src/context/project-context.ts
|
|
2
|
+
//
|
|
3
|
+
// Task-scoped project context (platform roadmap Phase 3). Returned by
|
|
4
|
+
// `kit context --json`, `kit_project_context` over MCP, and consumed by the
|
|
5
|
+
// agentic-mods kit-bridge. It carries only what a task needs: applicable rules
|
|
6
|
+
// for the given files, patterns, decision titles and the last verification.
|
|
7
|
+
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { EnforcementModeSchema, RuleStatusSchema } from '../constitution/rule.js';
|
|
10
|
+
import { GateStatusSchema } from '../constitution/result.js';
|
|
11
|
+
|
|
12
|
+
export const PROJECT_CONTEXT_SCHEMA_VERSION = 1 as const;
|
|
13
|
+
|
|
14
|
+
export const ContextRuleSchema = z.object({
|
|
15
|
+
id: z.string().min(1),
|
|
16
|
+
title: z.string().min(1),
|
|
17
|
+
statement: z.string().min(1),
|
|
18
|
+
status: RuleStatusSchema,
|
|
19
|
+
mode: EnforcementModeSchema,
|
|
20
|
+
matchedFiles: z.array(z.string()),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const ContextPatternSchema = z.object({
|
|
24
|
+
id: z.string().min(1),
|
|
25
|
+
name: z.string().min(1),
|
|
26
|
+
problem: z.string().min(1),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const ContextDecisionSchema = z.object({
|
|
30
|
+
id: z.string().min(1),
|
|
31
|
+
title: z.string().min(1),
|
|
32
|
+
path: z.string().min(1),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const ContextVerificationSchema = z.object({
|
|
36
|
+
runId: z.string().min(1),
|
|
37
|
+
status: z.enum(['passed', 'failed', 'blocked']),
|
|
38
|
+
recordedAt: z.string().min(1),
|
|
39
|
+
checks: z.array(z.object({ id: z.string().min(1), status: z.string().min(1) })),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export const ProjectContextSchema = z.object({
|
|
43
|
+
schemaVersion: z.literal(PROJECT_CONTEXT_SCHEMA_VERSION),
|
|
44
|
+
project: z.object({ name: z.string().min(1), stacks: z.array(z.string()) }),
|
|
45
|
+
constitution: z.object({
|
|
46
|
+
present: z.boolean(),
|
|
47
|
+
// Mirrors constitution.required in project.yml. When true, an unavailable or
|
|
48
|
+
// failing constitution must never be reported as passing.
|
|
49
|
+
required: z.boolean(),
|
|
50
|
+
ruleCount: z.number().int().nonnegative(),
|
|
51
|
+
// Null when no files were given, or no constitution exists: the gate was not evaluated.
|
|
52
|
+
gate: GateStatusSchema.nullable(),
|
|
53
|
+
}),
|
|
54
|
+
// The files this context was computed for. Empty means no task-scoped rules.
|
|
55
|
+
files: z.array(z.string()),
|
|
56
|
+
rules: z.array(ContextRuleSchema),
|
|
57
|
+
patterns: z.array(ContextPatternSchema),
|
|
58
|
+
decisions: z.array(ContextDecisionSchema),
|
|
59
|
+
// Null when no verification has been recorded in this checkout.
|
|
60
|
+
verification: ContextVerificationSchema.nullable(),
|
|
61
|
+
notes: z.array(z.string()),
|
|
62
|
+
});
|
|
63
|
+
export type ProjectContext = z.infer<typeof ProjectContextSchema>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// packages/contracts/src/execution/execution-profile.ts
|
|
2
|
+
//
|
|
3
|
+
// Where verification and evidence commands run (roadmap Phase 8, issue #49). `host` is the existing
|
|
4
|
+
// behaviour. `container` is opt-in and must fail closed: a profile that requires isolation never
|
|
5
|
+
// runs on the host when the runtime is unavailable.
|
|
6
|
+
//
|
|
7
|
+
// Containers reduce risk. They are not a complete kernel or security sandbox, and nothing here
|
|
8
|
+
// claims otherwise.
|
|
9
|
+
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
|
|
12
|
+
export const EXECUTION_PROFILE_SCHEMA_VERSION = 1 as const;
|
|
13
|
+
|
|
14
|
+
const imageRef = z
|
|
15
|
+
.string()
|
|
16
|
+
.regex(/^[a-z0-9][a-z0-9._/-]*(:[A-Za-z0-9._-]+)?@sha256:[a-f0-9]{64}$/, 'image must be pinned by digest (@sha256:...)');
|
|
17
|
+
|
|
18
|
+
export const ContainerIsolationSchema = z
|
|
19
|
+
.object({
|
|
20
|
+
runtime: z.enum(['docker', 'podman']),
|
|
21
|
+
image: imageRef,
|
|
22
|
+
// Deny by default. An allowlist entry is a hostname; no wildcards.
|
|
23
|
+
network: z.enum(['none', 'allowlist']),
|
|
24
|
+
allowedHosts: z.array(z.string().regex(/^[a-z0-9.-]+$/, 'exact hostname only')).max(20),
|
|
25
|
+
cpus: z.number().positive().max(64),
|
|
26
|
+
memoryMb: z.number().int().positive().max(131072),
|
|
27
|
+
// Seconds before the container is killed. The kit never waits forever.
|
|
28
|
+
timeoutSeconds: z.number().int().positive().max(3600),
|
|
29
|
+
})
|
|
30
|
+
.strict()
|
|
31
|
+
.refine((c) => c.network === 'allowlist' || c.allowedHosts.length === 0, {
|
|
32
|
+
message: 'allowedHosts is only meaningful with network: allowlist',
|
|
33
|
+
path: ['allowedHosts'],
|
|
34
|
+
});
|
|
35
|
+
export type ContainerIsolation = z.infer<typeof ContainerIsolationSchema>;
|
|
36
|
+
|
|
37
|
+
export const ExecutionProfileSchema = z.discriminatedUnion('kind', [
|
|
38
|
+
z.object({
|
|
39
|
+
schemaVersion: z.literal(EXECUTION_PROFILE_SCHEMA_VERSION),
|
|
40
|
+
kind: z.literal('host'),
|
|
41
|
+
requireIsolation: z.literal(false),
|
|
42
|
+
}).strict(),
|
|
43
|
+
z.object({
|
|
44
|
+
schemaVersion: z.literal(EXECUTION_PROFILE_SCHEMA_VERSION),
|
|
45
|
+
kind: z.literal('container'),
|
|
46
|
+
requireIsolation: z.boolean(),
|
|
47
|
+
container: ContainerIsolationSchema,
|
|
48
|
+
}).strict(),
|
|
49
|
+
]);
|
|
50
|
+
export type ExecutionProfile = z.infer<typeof ExecutionProfileSchema>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './execution-profile.js';
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
export * from './common/index.js';
|
|
12
12
|
export * from './project/index.js';
|
|
13
13
|
export * from './workflow/index.js';
|
|
14
|
+
export * from './agent-tools/index.js';
|
|
14
15
|
export * from './specification/index.js';
|
|
15
16
|
export * from './planning/index.js';
|
|
16
17
|
export * from './verification/index.js';
|
|
@@ -51,3 +52,18 @@ export * from './evolution/index.js';
|
|
|
51
52
|
|
|
52
53
|
// M36 agent execution surface (ADR-0019, ADR-0020):
|
|
53
54
|
export * from './agent/index.js';
|
|
55
|
+
|
|
56
|
+
// ADR-0023 engineering constitution surface:
|
|
57
|
+
export * from './constitution/index.js';
|
|
58
|
+
|
|
59
|
+
// ADR-0023 §7 onboarding surface (kit onboard --dry-run):
|
|
60
|
+
export * from './onboard/index.js';
|
|
61
|
+
|
|
62
|
+
// Task-scoped project context (roadmap Phase 3):
|
|
63
|
+
export * from './context/index.js';
|
|
64
|
+
|
|
65
|
+
// Agent regression benchmark (roadmap Phase 5, #46):
|
|
66
|
+
export * from './benchmark/index.js';
|
|
67
|
+
|
|
68
|
+
// Per-run execution isolation (roadmap Phase 8, #49):
|
|
69
|
+
export * from './execution/index.js';
|
|
@@ -20,6 +20,10 @@ export const OwnershipEntrySchema = z.object({
|
|
|
20
20
|
installedAt: z.string(),
|
|
21
21
|
// Whether the file was preserved (not overwritten) on upgrade.
|
|
22
22
|
preserved: z.boolean().default(false),
|
|
23
|
+
// For symlink entries: the absolute path the link pointed to when the kit
|
|
24
|
+
// created or verified it. Uninstall removes the link only while it still
|
|
25
|
+
// points here. Absent on manifests written before this field existed.
|
|
26
|
+
target: z.string().optional(),
|
|
23
27
|
});
|
|
24
28
|
|
|
25
29
|
export const OwnershipManifestSchema = z.object({
|
|
@@ -44,6 +44,8 @@ export const EngineeringMemoryEntrySchema = z.object({
|
|
|
44
44
|
expiresAt: z.string().optional(),
|
|
45
45
|
// Tags for retrieval.
|
|
46
46
|
tags: z.array(z.string()).default([]),
|
|
47
|
+
// Use counts (ADR-0025): carried over from the legacy MemoryEntry, additive and optional.
|
|
48
|
+
usage: z.object({ appliedCount: z.number().int().nonnegative(), successCount: z.number().int().nonnegative() }).optional(),
|
|
47
49
|
});
|
|
48
50
|
|
|
49
51
|
export type MemoryLevel = z.infer<typeof MemoryLevelSchema>;
|
package/src/learning/index.ts
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// packages/contracts/src/learning/learning-event.ts
|
|
2
|
+
//
|
|
3
|
+
// One privacy-safe outcome of a workflow run (platform roadmap Phase 6). The schema is strict and
|
|
4
|
+
// carries no free text: only enumerations, identifiers, repository-relative paths and counts. A
|
|
5
|
+
// prompt, a model reply, a source excerpt or a log line cannot be represented, so it cannot be
|
|
6
|
+
// stored by accident.
|
|
7
|
+
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
import { isRepoRelativePath } from '../constitution/rule.js';
|
|
10
|
+
|
|
11
|
+
export const LEARNING_EVENT_SCHEMA_VERSION = 1 as const;
|
|
12
|
+
|
|
13
|
+
const KEBAB = /^[a-z][a-z0-9-]*$/;
|
|
14
|
+
const RULE_ID = /^[A-Z][A-Z0-9]*(-[A-Z0-9]+)*-\d{3}$/;
|
|
15
|
+
const RUN_ID = /^[A-Za-z0-9][A-Za-z0-9_.-]{0,95}$/;
|
|
16
|
+
const repoPath = z.string().min(1).max(512).refine(isRepoRelativePath, 'path must be repository-relative');
|
|
17
|
+
|
|
18
|
+
export const LearningTaskTypeSchema = z.enum(['feature', 'fix', 'refactor', 'review', 'verify']);
|
|
19
|
+
export const LearningOutcomeSchema = z.enum(['passed', 'failed', 'blocked', 'cancelled']);
|
|
20
|
+
|
|
21
|
+
export const LearningEventSchema = z
|
|
22
|
+
.object({
|
|
23
|
+
schemaVersion: z.literal(LEARNING_EVENT_SCHEMA_VERSION),
|
|
24
|
+
id: z.string().regex(RUN_ID),
|
|
25
|
+
occurredAt: z.string().datetime(),
|
|
26
|
+
runId: z.string().regex(RUN_ID),
|
|
27
|
+
taskType: LearningTaskTypeSchema,
|
|
28
|
+
outcome: LearningOutcomeSchema,
|
|
29
|
+
stacks: z.array(z.string().regex(KEBAB)).max(10),
|
|
30
|
+
affectedFiles: z.array(repoPath).max(200),
|
|
31
|
+
ruleViolations: z.array(z.object({ ruleId: z.string().regex(RULE_ID), path: repoPath }).strict()).max(200),
|
|
32
|
+
verification: z
|
|
33
|
+
.object({
|
|
34
|
+
passed: z.number().int().nonnegative(),
|
|
35
|
+
failed: z.number().int().nonnegative(),
|
|
36
|
+
skipped: z.number().int().nonnegative(),
|
|
37
|
+
})
|
|
38
|
+
.strict(),
|
|
39
|
+
durationMs: z.number().int().nonnegative(),
|
|
40
|
+
})
|
|
41
|
+
.strict();
|
|
42
|
+
export type LearningEvent = z.infer<typeof LearningEventSchema>;
|