@hiroshi.inoue/agent-spectrum-kernel 1.0.0 → 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.
- package/README.ja.md +160 -0
- package/README.md +11 -154
- package/dist/AGENTS.md +1 -1
- package/dist/CUSTOM_INSTRUCTIONS.md +3 -2
- package/dist/README.md +11 -154
- package/dist/adapters/claude-code/plugin/skills/handoff/SKILL.md +1 -1
- package/dist/adapters/claude-code/plugin/skills/implement/SKILL.md +1 -1
- package/dist/adapters/claude-code/plugin/skills/investigate/SKILL.md +1 -1
- package/dist/adapters/claude-code/plugin/skills/review-pr/SKILL.md +1 -1
- package/dist/adapters/claude-code/plugin/skills/verify/SKILL.md +1 -1
- package/dist/docs/README.md +1 -0
- package/dist/docs/architecture/README.md +54 -0
- package/dist/docs/architecture/model.json +318 -0
- package/dist/docs/architecture/views/skill-assets.md +109 -0
- package/dist/docs/fixtures/adapter-runtime-bundle.json +85 -69
- package/dist/docs/fixtures/adapter-runtime-evidence.json +4 -4
- package/dist/docs/fixtures/adapter-runtime-profiles.json +97 -61
- package/dist/docs/fixtures/verification-proof-policy-cases.json +1 -1
- package/dist/docs/npm-distribution-ja.md +8 -6
- package/dist/docs/npm-distribution.md +6 -7
- package/dist/docs/routing-model.md +15 -0
- package/dist/docs/skill-matrix.md +4 -0
- package/dist/docs/validation-report.md +36 -30
- package/dist/manifest.json +36 -1
- package/dist/npm-runtime-inventory.json +214 -119
- package/dist/package.json +2 -2
- package/dist/schemas/adoption-plan.schema.json +5 -1
- package/dist/schemas/architecture-model.schema.json +619 -0
- package/dist/scripts/ask-primary-runtime-lineage.mjs +2 -1
- package/dist/scripts/ask-setup-apply-state.mjs +2 -2
- package/dist/scripts/ask-setup-apply.mjs +3 -3
- package/dist/scripts/ask-setup.mjs +37 -18
- package/dist/scripts/codex-exec-runner.mjs +7 -2
- package/dist/scripts/install-claude-adapter.mjs +14 -1
- package/dist/scripts/install-codex-adapter.mjs +17 -1
- package/dist/scripts/install-kernel.mjs +8 -4
- package/dist/scripts/installer-lifecycle.mjs +41 -0
- package/dist/scripts/kernel-principles.mjs +4 -2
- package/dist/skills/adr-review/SKILL.md +1 -0
- package/dist/skills/application-boundary-architecture/SKILL.md +1 -0
- package/dist/skills/architecture-decision-memory/SKILL.md +1 -0
- package/dist/skills/architecture-modeling/SKILL.md +22 -0
- package/dist/skills/architecture-modeling/references/architecture-model.mjs +441 -0
- package/dist/skills/architecture-modeling/references/last-seat.json +37 -0
- package/dist/skills/architecture-modeling/references/model.md +42 -0
- package/dist/skills/architecture-modeling/references/views.md +18 -0
- package/dist/skills/architecture-modeling/references/views.mjs +370 -0
- package/dist/skills/code-visualization/SKILL.md +8 -4
- package/dist/skills/code-visualization/references/design-preview.mjs +74 -0
- package/dist/skills/code-visualization/references/examples/last-seat.json +42 -0
- package/dist/skills/code-visualization/references/guide-input.md +30 -0
- package/dist/skills/code-visualization/references/render-guide.mjs +53 -11
- package/dist/skills/code-visualization/references/structure-index.mjs +41 -0
- package/dist/skills/code-visualization/references/visual-player.js +34 -3
- package/dist/skills/code-visualization/references/visual-surface.css +3 -0
- package/dist/skills/controlled-implementation/SKILL.md +4 -0
- package/dist/skills/documentation-knowledge-compiler/SKILL.md +2 -1
- package/dist/skills/doubt-driven-development/SKILL.md +2 -0
- package/dist/skills/engineering-documentation-generation/SKILL.md +27 -0
- package/dist/skills/engineering-documentation-generation/references/diagram-selection.md +25 -0
- package/dist/skills/engineering-documentation-generation/references/document-types.md +16 -0
- package/dist/skills/engineering-documentation-generation/references/reservation.md +61 -0
- package/dist/skills/engineering-documentation-generation/references/update-and-check.md +24 -0
- package/dist/skills/grill-design/SKILL.md +6 -2
- package/dist/skills/grill-with-docs/SKILL.md +4 -2
- package/dist/skills/handoff-generation/SKILL.md +1 -0
- package/dist/skills/implementation-context-generation/SKILL.md +1 -0
- package/dist/skills/mr-readme-generation/SKILL.md +2 -0
- package/dist/skills/operating-mode-router/SKILL.md +1 -0
- package/dist/skills/project-adoption-pack-generation/SKILL.md +1 -0
- package/dist/skills/refactor-implementation/SKILL.md +1 -0
- package/dist/skills/repository-orientation/SKILL.md +2 -0
- package/dist/skills/requirement-grill/SKILL.md +2 -0
- package/dist/skills/review-architecture-impact/SKILL.md +2 -0
- package/dist/skills/review-context-generation/SKILL.md +1 -0
- package/dist/skills/review-domain-impact/SKILL.md +2 -0
- package/dist/skills/skill-router/SKILL.md +5 -1
- package/dist/skills/spec-driven-development/SKILL.md +4 -0
- package/dist/skills/spec-driven-development/references/examples/javascript/candidate-preview.mjs +44 -0
- package/dist/skills/spec-driven-development/references/examples/javascript/scenario-review.mjs +10 -1
- package/dist/skills/spec-driven-development/references/scenario-visual-review.md +16 -0
- package/dist/skills/spec-driven-development/references/spec-index.md +8 -0
- package/dist/skills/test-first-verification/SKILL.md +2 -0
- package/dist/skills/work-package-compiler/SKILL.md +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
// A bounded derived index. Never execute application code or change files while inspecting it.
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
5
|
+
import { basename, dirname, resolve, relative } from 'node:path';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
+
import { parseArgs } from 'node:util';
|
|
8
|
+
import { markdown, projectGuide, differences, deploymentEnvironments } from './views.mjs';
|
|
9
|
+
|
|
10
|
+
export { markdown, projectGuide, differences };
|
|
11
|
+
const self = fileURLToPath(import.meta.url);
|
|
12
|
+
const skillsRoot = resolve(dirname(self), '../..');
|
|
13
|
+
const parent = dirname(skillsRoot);
|
|
14
|
+
const core = ['.agents', '.claude'].includes(basename(parent)) ? dirname(parent) : parent;
|
|
15
|
+
const { validateJsonSchema } = await import(pathToFileURL(resolve(core, 'scripts/json-schema-validation.mjs')));
|
|
16
|
+
const schemaPath = resolve(core, 'schemas/architecture-model.schema.json');
|
|
17
|
+
const hash = (bytes) => createHash('sha256').update(bytes).digest('hex');
|
|
18
|
+
const canonical = (x) =>
|
|
19
|
+
JSON.stringify(x, (_, v) =>
|
|
20
|
+
v && typeof v === 'object' && !Array.isArray(v)
|
|
21
|
+
? Object.fromEntries(
|
|
22
|
+
Object.keys(v)
|
|
23
|
+
.sort()
|
|
24
|
+
.map((k) => [k, v[k]])
|
|
25
|
+
)
|
|
26
|
+
: v
|
|
27
|
+
);
|
|
28
|
+
const same = (a, b) => canonical(a) === canonical(b);
|
|
29
|
+
const ordered = (rows) => [...rows].sort((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
30
|
+
const generator =
|
|
31
|
+
'ask.architecture-model/1@' +
|
|
32
|
+
hash(
|
|
33
|
+
[self, resolve(dirname(self), 'views.mjs'), schemaPath, resolve(core, 'scripts/json-schema-validation.mjs')]
|
|
34
|
+
.map((path) => hash(readFileSync(path)))
|
|
35
|
+
.join(':')
|
|
36
|
+
);
|
|
37
|
+
const tables = ['scopes', 'claims', 'elements', 'relationships', 'scenarios', 'comparisons'];
|
|
38
|
+
const insist = (ok, message) => {
|
|
39
|
+
if (!ok) throw new Error(message);
|
|
40
|
+
};
|
|
41
|
+
const inside = (path, base) => path === base || path.startsWith(base + '/');
|
|
42
|
+
const covers = (s, path) =>
|
|
43
|
+
s.include.some((p) => inside(path, p)) && !s.exclude.some((e) => inside(path, e.path));
|
|
44
|
+
|
|
45
|
+
function safePath(path, { exclude = false } = {}) {
|
|
46
|
+
insist(
|
|
47
|
+
!/[\\:\x00-\x1f\x7f]/u.test(path) &&
|
|
48
|
+
path.split('/').every((part) => part && !['.', '..', '.git'].includes(part.toLowerCase())),
|
|
49
|
+
'Invalid repository-relative path'
|
|
50
|
+
);
|
|
51
|
+
if (!exclude)
|
|
52
|
+
insist(
|
|
53
|
+
!/(^|\/)(\.env(\..*)?|id_(rsa|ed25519)|\.npmrc|credentials|[^/]+\.(pem|key|p12))$/iu.test(path),
|
|
54
|
+
'Exclude sensitive inputs from this scope'
|
|
55
|
+
);
|
|
56
|
+
return path;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function validate(model) {
|
|
60
|
+
const errors = validateJsonSchema(model, { schemaPath });
|
|
61
|
+
insist(!errors.length, errors.slice(0, 3).join('\n'));
|
|
62
|
+
const maps = {};
|
|
63
|
+
for (const key of tables) {
|
|
64
|
+
maps[key] = new Map(model[key].map((row) => [row.id, row]));
|
|
65
|
+
insist(maps[key].size === model[key].length, 'Conflicting IDs in ' + key);
|
|
66
|
+
}
|
|
67
|
+
const get = (key, id) => {
|
|
68
|
+
insist(maps[key].has(id), 'Unresolved ' + key + ' reference: ' + id);
|
|
69
|
+
return maps[key].get(id);
|
|
70
|
+
};
|
|
71
|
+
for (const s of model.scopes) {
|
|
72
|
+
for (const path of s.include) safePath(path);
|
|
73
|
+
for (const e of s.exclude) safePath(e.path, { exclude: true });
|
|
74
|
+
}
|
|
75
|
+
const roles = {
|
|
76
|
+
intended: ['requirement', 'spec', 'adr', 'contract'],
|
|
77
|
+
actual: ['code', 'config', 'contract'],
|
|
78
|
+
'observed-execution': ['execution'],
|
|
79
|
+
};
|
|
80
|
+
for (const c of model.claims) {
|
|
81
|
+
const scope = get('scopes', c.scope);
|
|
82
|
+
if (c.kind === 'proposed') {
|
|
83
|
+
insist(['Hypothesis', 'Unknown'].includes(c.status), 'Proposals are unapproved');
|
|
84
|
+
insist(!c.sources.some((r) => r.role === 'execution'), 'Proposals cannot supply execution evidence');
|
|
85
|
+
} else if (c.status !== 'Unknown') {
|
|
86
|
+
insist(
|
|
87
|
+
c.sources.some((r) => roles[c.kind].includes(r.role)),
|
|
88
|
+
'Missing primary source for ' + c.id
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
for (const r of c.sources) {
|
|
92
|
+
insist(covers(scope, safePath(r.path)), 'Out-of-scope reference in ' + c.id);
|
|
93
|
+
insist(!r.end || r.end >= r.line, 'Invalid line range in ' + c.id);
|
|
94
|
+
if (r.spec_ref) insist(r.role === 'spec', 'Only a spec can bind a spec_ref');
|
|
95
|
+
if (r.role === 'execution')
|
|
96
|
+
insist(c.kind === 'observed-execution', 'Keep run evidence in a separate observation');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (const e of model.elements) {
|
|
100
|
+
const claim = get('claims', e.claim);
|
|
101
|
+
const expected = { container: 'system', component: 'container' }[e.type];
|
|
102
|
+
insist(
|
|
103
|
+
expected ? e.parent && get('elements', e.parent).type === expected : !e.parent,
|
|
104
|
+
'Invalid parent of ' + e.id
|
|
105
|
+
);
|
|
106
|
+
if (e.parent && get('claims', get('elements', e.parent).claim).kind === 'proposed')
|
|
107
|
+
insist(claim.kind === 'proposed', 'Current structure cannot have a proposed parent');
|
|
108
|
+
}
|
|
109
|
+
deploymentEnvironments(model);
|
|
110
|
+
for (const r of model.relationships) {
|
|
111
|
+
const endpointClaims = [r.from, r.to].map((id) => get('claims', get('elements', id).claim));
|
|
112
|
+
const fact = get('claims', r.claim);
|
|
113
|
+
if (endpointClaims.some((c) => c.kind === 'proposed'))
|
|
114
|
+
insist(fact.kind === 'proposed', 'Current relationship cannot depend on proposed structure');
|
|
115
|
+
if (r.kind === 'deployment' && fact.kind === 'actual' && fact.status !== 'Unknown')
|
|
116
|
+
insist(fact.sources.some((source) => source.role === 'config'), 'Missing deployment evidence for ' + r.id);
|
|
117
|
+
}
|
|
118
|
+
for (const s of model.scenarios) {
|
|
119
|
+
const claim = get('claims', s.claim);
|
|
120
|
+
let previous;
|
|
121
|
+
for (const id of s.path) {
|
|
122
|
+
const edge = get('relationships', id);
|
|
123
|
+
insist(!previous || previous.to === edge.from, 'Disconnected scenario ' + s.id);
|
|
124
|
+
if (get('claims', edge.claim).kind === 'proposed')
|
|
125
|
+
insist(claim.kind === 'proposed', 'Proposed step in current path');
|
|
126
|
+
previous = edge;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (const c of model.comparisons) {
|
|
130
|
+
get('scenarios', c.scenario);
|
|
131
|
+
for (const [name, kind] of [
|
|
132
|
+
['intended', 'intended'],
|
|
133
|
+
['actual', 'actual'],
|
|
134
|
+
['execution', 'observed-execution'],
|
|
135
|
+
]) {
|
|
136
|
+
if (c[name]) insist(get('claims', c[name]).kind === kind, 'Wrong authority for ' + name);
|
|
137
|
+
}
|
|
138
|
+
for (const id of c.proposed ?? []) insist(get('claims', id).kind === 'proposed', 'Expected proposal');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function git(root, ...args) {
|
|
143
|
+
return execFileSync('git', ['--no-replace-objects', '--literal-pathspecs', '-C', root, ...args], {
|
|
144
|
+
env: { ...process.env, GIT_NO_LAZY_FETCH: '1' },
|
|
145
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
146
|
+
maxBuffer: 32 * 1024 * 1024,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const line = (root, ...args) =>
|
|
150
|
+
git(root, ...args)
|
|
151
|
+
.toString()
|
|
152
|
+
.trim();
|
|
153
|
+
function identity(root) {
|
|
154
|
+
insist(
|
|
155
|
+
realpathSync(line(root, 'rev-parse', '--show-toplevel')) === realpathSync(root),
|
|
156
|
+
'Expected repository root'
|
|
157
|
+
);
|
|
158
|
+
let origin;
|
|
159
|
+
try {
|
|
160
|
+
origin = line(root, 'remote', 'get-url', 'origin');
|
|
161
|
+
} catch {
|
|
162
|
+
/* local only */
|
|
163
|
+
}
|
|
164
|
+
const github = origin?.match(
|
|
165
|
+
/^(?:https:\/\/github\.com\/|git@github\.com:|ssh:\/\/git@github\.com\/)([\w.-]+\/[\w.-]+?)(?:\.git)?$/iu
|
|
166
|
+
);
|
|
167
|
+
if (github) return 'github.com/' + github[1].toLowerCase();
|
|
168
|
+
// Keep other remote addresses and local paths out of persistent views.
|
|
169
|
+
return 'local:' + hash(realpathSync(root));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function collect(root, scope, commit) {
|
|
173
|
+
const listing = commit
|
|
174
|
+
? git(root, 'ls-tree', '-rz', commit, '--', ...scope.include)
|
|
175
|
+
: git(root, 'ls-files', '-z', '--cached', '--others', '--exclude-standard', '--', ...scope.include);
|
|
176
|
+
const files = new Map();
|
|
177
|
+
for (const entry of new TextDecoder('utf-8', { fatal: true }).decode(listing).split('\0').filter(Boolean)) {
|
|
178
|
+
const sep = commit ? entry.indexOf('\t') : -1;
|
|
179
|
+
const path = entry.slice(sep + 1);
|
|
180
|
+
if (!covers(scope, path)) continue;
|
|
181
|
+
safePath(path);
|
|
182
|
+
if (commit) {
|
|
183
|
+
const [mode, type, oid] = entry.slice(0, sep).split(' ');
|
|
184
|
+
insist(type === 'blob' && /^100(644|755)$/.test(mode), 'Expected regular Git file');
|
|
185
|
+
files.set(path, git(root, 'cat-file', 'blob', oid));
|
|
186
|
+
} else {
|
|
187
|
+
let file = root;
|
|
188
|
+
for (const part of path.split('/')) {
|
|
189
|
+
file = resolve(file, part);
|
|
190
|
+
const stat = lstatSync(file, { throwIfNoEntry: false });
|
|
191
|
+
if (!stat) break;
|
|
192
|
+
insist(!stat.isSymbolicLink(), 'Cannot follow symlink');
|
|
193
|
+
if (file === resolve(root, path)) {
|
|
194
|
+
insist(stat.isFile(), 'Expected regular source file');
|
|
195
|
+
files.set(path, readFileSync(file));
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return files;
|
|
201
|
+
}
|
|
202
|
+
const inventory = (files) => [...files.keys()].sort().map((path) => ({ path, sha256: hash(files.get(path)) }));
|
|
203
|
+
|
|
204
|
+
function isJsonSpec(path, text) {
|
|
205
|
+
if (/\.json$/iu.test(path)) return true;
|
|
206
|
+
// Extensionless specs may be JSON or ordinary prose with markup such as {attribute}.
|
|
207
|
+
try {
|
|
208
|
+
const value = JSON.parse(text);
|
|
209
|
+
return value !== null && typeof value === 'object';
|
|
210
|
+
} catch {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function verifyLocations(model, scope, files) {
|
|
216
|
+
for (const claim of model.claims.filter((c) => c.scope === scope.id))
|
|
217
|
+
for (const r of claim.sources) {
|
|
218
|
+
insist(files.has(r.path), 'Missing source of ' + claim.id);
|
|
219
|
+
const text = new TextDecoder('utf-8', { fatal: true }).decode(files.get(r.path));
|
|
220
|
+
const lines = text.replace(/\r?\n$/u, '').split(/\r?\n/u);
|
|
221
|
+
insist(text.length && (r.end ?? r.line) <= lines.length, 'Missing lines for ' + claim.id);
|
|
222
|
+
if (r.anchor)
|
|
223
|
+
insist(
|
|
224
|
+
lines
|
|
225
|
+
.slice(r.line - 1, r.end ?? r.line)
|
|
226
|
+
.join('\n')
|
|
227
|
+
.includes(r.anchor),
|
|
228
|
+
'Missing anchor for ' + claim.id
|
|
229
|
+
);
|
|
230
|
+
if (r.role === 'spec' && !r.spec_ref)
|
|
231
|
+
insist(!isJsonSpec(r.path, text), 'JSON spec requires a spec_ref for ' + claim.id);
|
|
232
|
+
if (r.spec_ref) {
|
|
233
|
+
const doc = JSON.parse(text);
|
|
234
|
+
const ref = r.spec_ref;
|
|
235
|
+
const matches = doc.items?.filter(
|
|
236
|
+
(item) =>
|
|
237
|
+
(item.spec_ref?.artifact_id ?? doc.artifact_id) === ref.artifact_id &&
|
|
238
|
+
(item.spec_ref?.item_id ?? item.item_id) === ref.item_id
|
|
239
|
+
);
|
|
240
|
+
insist(matches?.length === 1, 'Missing or conflicting spec item for ' + claim.id);
|
|
241
|
+
const item = matches[0];
|
|
242
|
+
insist(
|
|
243
|
+
(item.spec_ref ? same(item.spec_ref, ref) : doc.revision === ref.observed_revision) &&
|
|
244
|
+
(item.item_id === undefined || item.item_id === ref.item_id) &&
|
|
245
|
+
(doc.artifact_id === undefined || doc.artifact_id === ref.artifact_id) &&
|
|
246
|
+
(doc.revision === undefined || doc.revision === ref.observed_revision),
|
|
247
|
+
'Different spec revision for ' + claim.id
|
|
248
|
+
);
|
|
249
|
+
if (claim.kind === 'intended' && ['Verified', 'Supported'].includes(claim.status)) {
|
|
250
|
+
const statuses = [item.status, doc.status].filter((v) => v !== undefined);
|
|
251
|
+
insist(
|
|
252
|
+
(!item.spec_ref || item.status === 'accepted') &&
|
|
253
|
+
statuses.length &&
|
|
254
|
+
statuses.every((s) => s === 'accepted'),
|
|
255
|
+
'Unconfirmed spec for ' + claim.id
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function fingerprint(model, scope, snapshot) {
|
|
263
|
+
const { id, include, exclude, boundary } = scope;
|
|
264
|
+
const { commit, tree, mode, files } = snapshot;
|
|
265
|
+
return hash(
|
|
266
|
+
canonical({
|
|
267
|
+
repository: model.repository,
|
|
268
|
+
project: model.project,
|
|
269
|
+
profile: model.profile,
|
|
270
|
+
generator,
|
|
271
|
+
id,
|
|
272
|
+
include,
|
|
273
|
+
exclude,
|
|
274
|
+
boundary,
|
|
275
|
+
commit,
|
|
276
|
+
tree,
|
|
277
|
+
mode,
|
|
278
|
+
files,
|
|
279
|
+
})
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function checkScope(model, root, s) {
|
|
284
|
+
try {
|
|
285
|
+
const b = s.snapshot;
|
|
286
|
+
if (!b) return { id: s.id, state: 'unknown', reason: 'unbound' };
|
|
287
|
+
insist(
|
|
288
|
+
b.generator === generator && fingerprint(model, s, b) === b.fingerprint,
|
|
289
|
+
'Scope or fingerprint changed'
|
|
290
|
+
);
|
|
291
|
+
insist(line(root, 'rev-parse', b.commit + '^{tree}') === b.tree, 'Tree mismatch');
|
|
292
|
+
const files = collect(root, s);
|
|
293
|
+
const current = inventory(files);
|
|
294
|
+
if (!same(current, b.files)) {
|
|
295
|
+
const before = new Map(b.files.map((f) => [f.path, f.sha256]));
|
|
296
|
+
const after = new Map(current.map((f) => [f.path, f.sha256]));
|
|
297
|
+
const paths = [...new Set([...before.keys(), ...after.keys()])]
|
|
298
|
+
.filter((p) => before.get(p) !== after.get(p))
|
|
299
|
+
.sort();
|
|
300
|
+
return { id: s.id, state: 'stale', paths };
|
|
301
|
+
}
|
|
302
|
+
insist(line(root, 'cat-file', '-t', b.commit) === 'commit', 'Invalid commit object');
|
|
303
|
+
if (b.mode === 'commit')
|
|
304
|
+
insist(same(inventory(collect(root, s, b.commit)), current), 'Commit binding mismatch');
|
|
305
|
+
verifyLocations(model, s, files);
|
|
306
|
+
return { id: s.id, state: 'current' };
|
|
307
|
+
} catch (error) {
|
|
308
|
+
return { id: s.id, state: 'stale', reason: error.code ? 'Cannot confirm source' : error.message };
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export function inspect(model, root, { path } = {}) {
|
|
313
|
+
validate(model);
|
|
314
|
+
insist(identity(root) === model.repository, 'Different repository or unbound model');
|
|
315
|
+
if (path) safePath(path);
|
|
316
|
+
const scopes = ordered(model.scopes).filter((s) => !path || covers(s, path));
|
|
317
|
+
if (!scopes.length) return [{ state: 'out-of-scope' }];
|
|
318
|
+
return scopes.map((s) => {
|
|
319
|
+
const result = checkScope(model, root, s);
|
|
320
|
+
if (path && result.state === 'current' && !s.snapshot.files.some((f) => inside(f.path, path))) {
|
|
321
|
+
return { id: s.id, state: 'out-of-scope' };
|
|
322
|
+
}
|
|
323
|
+
return result;
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export function bind(input, root) {
|
|
328
|
+
validate(input);
|
|
329
|
+
const model = structuredClone(input);
|
|
330
|
+
const repository = identity(root);
|
|
331
|
+
insist(!model.repository || model.repository === repository, 'Different repository');
|
|
332
|
+
model.repository = repository;
|
|
333
|
+
const commit = line(root, 'rev-parse', 'HEAD');
|
|
334
|
+
const tree = line(root, 'rev-parse', commit + '^{tree}');
|
|
335
|
+
for (const s of model.scopes) {
|
|
336
|
+
if (s.snapshot) {
|
|
337
|
+
insist(
|
|
338
|
+
checkScope(model, root, s).state === 'current',
|
|
339
|
+
'Review stale scope before removing its snapshot: ' + s.id
|
|
340
|
+
);
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
const files = collect(root, s);
|
|
344
|
+
insist(files.size, 'Empty scope: ' + s.id);
|
|
345
|
+
verifyLocations(model, s, files);
|
|
346
|
+
const rows = inventory(files);
|
|
347
|
+
const mode = same(rows, inventory(collect(root, s, commit))) ? 'commit' : 'worktree';
|
|
348
|
+
s.snapshot = { commit, tree, mode, generator, generated_at: new Date().toISOString(), files: rows };
|
|
349
|
+
s.snapshot.fingerprint = fingerprint(model, s, s.snapshot);
|
|
350
|
+
}
|
|
351
|
+
validate(model);
|
|
352
|
+
return model;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export function compare(a, b) {
|
|
356
|
+
validate(a);
|
|
357
|
+
validate(b);
|
|
358
|
+
insist(a.project === b.project && a.repository === b.repository, 'Different project or repository');
|
|
359
|
+
const metadata = ['title', 'purpose', 'profile', 'language', 'unknowns'].filter(
|
|
360
|
+
(key) => !same(a[key], b[key])
|
|
361
|
+
);
|
|
362
|
+
// Reading order is visible in the generated views. Ignore insertions and deletions here.
|
|
363
|
+
for (const key of tables) {
|
|
364
|
+
const before = new Set(a[key].map((row) => row.id));
|
|
365
|
+
const after = new Set(b[key].map((row) => row.id));
|
|
366
|
+
if (!same([...before].filter((id) => after.has(id)), [...after].filter((id) => before.has(id))))
|
|
367
|
+
metadata.push(key + '.order');
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
metadata,
|
|
371
|
+
...Object.fromEntries(
|
|
372
|
+
tables.map((key) => {
|
|
373
|
+
const rows = (m) =>
|
|
374
|
+
new Map(
|
|
375
|
+
m[key].map((row) => {
|
|
376
|
+
const copy = structuredClone(row);
|
|
377
|
+
if (copy.snapshot) delete copy.snapshot.generated_at;
|
|
378
|
+
return [row.id, copy];
|
|
379
|
+
})
|
|
380
|
+
);
|
|
381
|
+
const before = rows(a),
|
|
382
|
+
after = rows(b);
|
|
383
|
+
return [
|
|
384
|
+
key,
|
|
385
|
+
{
|
|
386
|
+
added: [...after.keys()].filter((k) => !before.has(k)).sort(),
|
|
387
|
+
removed: [...before.keys()].filter((k) => !after.has(k)).sort(),
|
|
388
|
+
changed: [...after.keys()]
|
|
389
|
+
.filter((k) => before.has(k) && !same(before.get(k), after.get(k)))
|
|
390
|
+
.sort(),
|
|
391
|
+
},
|
|
392
|
+
];
|
|
393
|
+
})
|
|
394
|
+
),
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function main() {
|
|
399
|
+
const {
|
|
400
|
+
values,
|
|
401
|
+
positionals: [command, input, other, ...extra],
|
|
402
|
+
} = parseArgs({
|
|
403
|
+
allowPositionals: true,
|
|
404
|
+
options: { repo: { type: 'string', default: process.cwd() }, path: { type: 'string' } },
|
|
405
|
+
});
|
|
406
|
+
const pair = ['diff', 'guide'].includes(command);
|
|
407
|
+
insist(
|
|
408
|
+
['check', 'bind', 'render', 'diff', 'guide'].includes(command) &&
|
|
409
|
+
input &&
|
|
410
|
+
!!other === pair &&
|
|
411
|
+
!extra.length &&
|
|
412
|
+
(!values.path || command === 'check'),
|
|
413
|
+
'Usage: architecture-model.mjs bind|check|render|diff|guide MODEL [OTHER] [--repo ROOT] [check --path PATH]'
|
|
414
|
+
);
|
|
415
|
+
const read = (file) => JSON.parse(readFileSync(file, 'utf8'));
|
|
416
|
+
const model = read(input),
|
|
417
|
+
root = realpathSync(values.repo);
|
|
418
|
+
validate(model);
|
|
419
|
+
const selfPath = relative(root, realpathSync(input));
|
|
420
|
+
insist(!model.scopes.some((s) => covers(s, selfPath)), 'Exclude the model itself from source inputs');
|
|
421
|
+
if (command === 'bind') return bind(model, root);
|
|
422
|
+
if (command === 'diff') return compare(model, read(other));
|
|
423
|
+
const state = inspect(model, root, { path: values.path });
|
|
424
|
+
if (state.some((s) => s.state !== 'current')) process.exitCode = 1;
|
|
425
|
+
if (command === 'check') return state;
|
|
426
|
+
if (command === 'render') return markdown(model, state);
|
|
427
|
+
insist(!process.exitCode, 'Guide needs current sources');
|
|
428
|
+
return projectGuide(model, read(other));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (process.argv[1] && realpathSync(process.argv[1]) === self) {
|
|
432
|
+
try {
|
|
433
|
+
const result = main();
|
|
434
|
+
process.stdout.write(typeof result === 'string' ? result : JSON.stringify(result, null, 2) + '\n');
|
|
435
|
+
} catch (error) {
|
|
436
|
+
console.error(
|
|
437
|
+
error.code || error instanceof SyntaxError ? 'Could not read model or repository inputs.' : error.message
|
|
438
|
+
);
|
|
439
|
+
process.exitCode = 1;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"contract": "ask.architecture-model@1.0.0",
|
|
3
|
+
"project": "booking",
|
|
4
|
+
"title": "Who owns the last seat?",
|
|
5
|
+
"language": "en",
|
|
6
|
+
"purpose": "Two people request the last seat. Follow the promise and the competing writes.",
|
|
7
|
+
"profile": "reservation-example/1",
|
|
8
|
+
"scopes": [
|
|
9
|
+
{"id":"rules","include":["requirements","spec.json"],"exclude":[],"boundary":"The booking promise and its acceptance item."},
|
|
10
|
+
{"id":"runtime","include":["src"],"exclude":[],"boundary":"Local pseudocode only. No live service or database."}
|
|
11
|
+
],
|
|
12
|
+
"claims": [
|
|
13
|
+
{"id":"promise","scope":"rules","kind":"intended","status":"Verified","authority":"Booking policy owner","summary":"Do not overbook. Accept at most one request.","outcome":"one","sources":[{"role":"spec","path":"spec.json","line":1,"spec_ref":{"artifact_id":"SEAT","item_id":"LAST","observed_revision":2}},{"role":"requirement","path":"requirements","line":1}]},
|
|
14
|
+
{"id":"implementation","scope":"runtime","kind":"actual","status":"Supported","authority":"Reservation code","summary":"Each tab checks its own remaining count. Both may accept.","outcome":"two","sources":[{"role":"code","path":"src/action","line":1}]},
|
|
15
|
+
{"id":"server","scope":"rules","kind":"proposed","status":"Hypothesis","authority":"Design discussion","summary":"A service could atomically reserve one seat and reject the later request.","outcome":"one","sources":[{"role":"requirement","path":"requirements","line":1}]}
|
|
16
|
+
],
|
|
17
|
+
"elements": [
|
|
18
|
+
{"id":"customer","type":"person","name":"Customer","responsibility":"Request the last seat.","claim":"promise"},
|
|
19
|
+
{"id":"booking","type":"system","name":"Booking","responsibility":"Decide which requests to accept.","claim":"promise"},
|
|
20
|
+
{"id":"web","parent":"booking","type":"container","name":"Browser","responsibility":"Show availability.","claim":"implementation"},
|
|
21
|
+
{"id":"counter","parent":"web","type":"component","name":"Local counter","responsibility":"Check one tab's copy.","state":"Tab-local availability","claim":"implementation"},
|
|
22
|
+
{"id":"service","parent":"booking","type":"container","name":"Reservation service","responsibility":"Serialize claims on the same seat.","claim":"server"}
|
|
23
|
+
],
|
|
24
|
+
"relationships": [
|
|
25
|
+
{"id":"request","from":"customer","to":"web","kind":"uses","meaning":"Requests a seat","claim":"implementation"},
|
|
26
|
+
{"id":"check","from":"web","to":"counter","kind":"call","meaning":"Decrements the local count","claim":"implementation"},
|
|
27
|
+
{"id":"reserve","from":"web","to":"service","kind":"call","meaning":"Asks for an atomic reservation","claim":"server"}
|
|
28
|
+
],
|
|
29
|
+
"scenarios": [
|
|
30
|
+
{"id":"race","title":"Two simultaneous requests","input":"Two tabs, one seat","path":["request","check"],"result":"Both tabs can return success.","claim":"implementation"},
|
|
31
|
+
{"id":"alternative","title":"Server ownership","input":"Two tabs, one seat","path":["request","reserve"],"result":"One success and one refusal are expected.","claim":"server"}
|
|
32
|
+
],
|
|
33
|
+
"comparisons": [
|
|
34
|
+
{"id":"overbooking","scenario":"race","intended":"promise","actual":"implementation","proposed":["server"],"owner":"Reservation team","next":"Verify atomicity with two clients against the same store."}
|
|
35
|
+
],
|
|
36
|
+
"unknowns":["Concurrent execution and persistent state have not been observed."]
|
|
37
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# A local architecture model
|
|
2
|
+
|
|
3
|
+
The file is a derived index for a particular question. Start with the [small reservation example](last-seat.json). Its sources are deliberately fictional. Use real repository paths and review every claim before binding an actual model. A brief explanation or a code-free design can stay in the conversation. Use a design preview for proposals without a Git repository.
|
|
4
|
+
|
|
5
|
+
## Write only the needed slice
|
|
6
|
+
|
|
7
|
+
Use the existing project convention. If an adopted project has none, keep the model at `docs/architecture/model.json`, the authored guide in the sibling README and generated Markdown in `views/`. Exclude model and generated views from the inputs. Store no document bodies, prompts, personal data, credentials, private addresses or execution logs in the index.
|
|
8
|
+
|
|
9
|
+
| Part | How to author it |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| Identity | Set `contract` to `ask.architecture-model@1.0.0`. Set project, title, purpose, language (ja or en) and a versioned profile. Bump the profile for a change in discovery conventions. |
|
|
12
|
+
| Scopes | Use stable IDs, literal repository-relative file or directory names in `include`, exclusions with a reason, and a sentence in `boundary` describing coverage and external limits. Include relevant contracts, build settings, test definitions and decision records. A shared input can belong to several scopes. Never scan an entire checkout by default. |
|
|
13
|
+
| Claims | Choose the kind and authority by the claim being made. Give each claim a scope and the existing evidence status. Each source identifies a role, a path, a one-based line and optional inclusive end and text anchor. A test definition is distinct from an execution record. |
|
|
14
|
+
| Structure | Define people, systems, containers and selected components. A container belongs to a system and a component to a container. A system-only view can describe a client library without inventing processes. Give each edge a direction, kind and verb. Reuse IDs across moves only if responsibility is unchanged. |
|
|
15
|
+
| Scenarios | List connected relationship IDs in traversal order and record the input, condition and result. Keep different outcomes in separate scenarios. Every deployment edge must occur in a scenario. Name the environment in each such scenario. Use separate edges and claims for different environments. A placement or run cited in a scenario result or comparison must belong to that same environment. Cite configuration for static placement and an execution record for observed placement. Keep unsupported placement Unknown. |
|
|
16
|
+
| Comparisons | Link one scenario to applicable claim IDs, a responsible owner and the next check. Compare the same input and boundary. Use matching controlled `outcome` labels only when the source meanings are directly comparable. Optional `gap` records independently established discrepancies. Report remaining uncertainties in `unknowns`. |
|
|
17
|
+
|
|
18
|
+
An intended claim needs a requirement, spec, ADR or contract. Actual claims need code, configuration or a static contract. Proposals remain Hypothesis or Unknown, even when based on a verified constraint. An observed execution needs a real execution source. Check the matching run, revision, environment, input and reached assertions directly. Unknown is allowed when an authority or source is missing. Do not turn a missing link into evidence of absence.
|
|
19
|
+
|
|
20
|
+
For a JSON spec or index, attach `spec_ref` with the existing `artifact_id`, `item_id` and positive `observed_revision`. Resolve one item by artifact and item ID before checking the revision. An index item needs its own `status: accepted` for established intent. A direct spec may declare that status on the document or item, with no conflicting status. Keep unresolved intent `Unknown`. A checked reference does not independently establish the agreement or the freshness of the index itself. For other sources use a line and anchor and resolve the authoritative reference directly. Do not create spec IDs just for this map.
|
|
21
|
+
|
|
22
|
+
## Check and update
|
|
23
|
+
|
|
24
|
+
Use Node.js 24 and local Git. Run from the source checkout or use the selected adapter's sibling `references` directory. The CLI resolves its trusted schema engine from its own installation. It never imports application code from `--repo`.
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
tool=skills/architecture-modeling/references/architecture-model.mjs
|
|
28
|
+
out=$(mktemp -d)
|
|
29
|
+
node "$tool" bind draft.json --repo . > "$out/model.json"
|
|
30
|
+
node "$tool" check "$out/model.json" --repo .
|
|
31
|
+
node "$tool" check "$out/model.json" --repo . --path src/action
|
|
32
|
+
node "$tool" render "$out/model.json" --repo . > "$out/view.md"
|
|
33
|
+
node "$tool" diff docs/architecture/model.json "$out/model.json"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Use paths that exist in the selected project. Never redirect output over the input or hand-edited notes. Compare the draft against the original, then replace only the authorized model and generated sections. The CLI writes to stdout. A nonzero exit invalidates the corresponding currentness claim. A stale render is diagnostic only. A scope check covers the requested file's scopes, not arbitrary consumers.
|
|
37
|
+
|
|
38
|
+
- Binding records the repository identity, HEAD and tree, content hashes, the profile, a digest of the generator, views, schema and validator, and time for each scope. A GitHub origin identifies a shared repository. Without one, the tool uses a hash of the local root and a moved checkout needs fresh review. Tracked and non-ignored untracked files count. Directly inspect ignored, dynamic or external inputs beyond that boundary.
|
|
39
|
+
- An unchanged input set can survive an unrelated commit. Worktree sources use a content fingerprint and never receive commit links. Review moves, deletions, additions, changed contracts, source ranges and affected relationships. Remove only the reviewed scope's `snapshot` from the draft, revise its claims and links, and bind again. Other snapshots are checked and retained. A changed generation profile requires rechecking all affected scopes. Time does not affect the comparison.
|
|
40
|
+
- For `guide MODEL GUIDE`, supply a committed structure at the exact guide revision. Optional element `links` contain a zero-based flow index and target node ID. Pipe the projected JSON through the existing local guide renderer to validate all original source references. Do not map an uncommitted change or proposal to a committed node.
|
|
41
|
+
- Unknown, stale, partial, missing or contradictory references call for direct inspection. The CLI checks structural consistency and reports explicit comparable differences. It cannot infer business intent, semantic equivalence, completeness or execution success. Stop using an outdated view without deleting authored sources or changing release gates.
|
|
42
|
+
- The diff lists changes to the relative reading order of existing IDs in metadata, for example `scenarios.order`. Additions and removals are reported separately.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# A reading path for one decision
|
|
2
|
+
|
|
3
|
+
Ask who needs to decide what. Begin with the outcome the person experiences, then identify the boundary that can change it. A context view answers who interacts with the system. A container view answers which application or store runs the work. Show a component only when the reader needs its responsibility, state, public contract or dependency. End at an exact source location. The [C4 diagram checklist](https://c4model.com/diagrams/checklist) covers titles, scope, abstraction and labeled directions.
|
|
4
|
+
|
|
5
|
+
For a change, fix both revisions and hold the input constant. Show the normal path and a consequential alternative. Explain what stays unchanged. Separate static dependencies, calls, data flow and actual deployment. A missing edge in a partial view is no basis for rejecting a dependency. Inspect both consumers and providers before recommending a change.
|
|
6
|
+
|
|
7
|
+
For the last seat, two tabs can each see one remaining place. Local checks may both accept. A proposed service can serialize requests only if the shared store supports atomic reservation. The diagram cannot establish that guarantee. The booking owner decides the promise. The service owner must demonstrate the result and absence of duplicate side effects with two clients. The included example records those limits.
|
|
8
|
+
|
|
9
|
+
| Finding | Where the decision belongs |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| missing-implementation | Confirm the intended item and inspect the absent path, then send the missing behavior and check to the implementation owner. |
|
|
12
|
+
| unexpected-behavior | Show the same input, expected and actual outcome and practical effect. Confirm whether code or the agreed requirement needs revision. |
|
|
13
|
+
| outdated-model-or-doc | Check whether only a derived description has drifted. Correct its source and regenerate the affected part. |
|
|
14
|
+
| missing-verification | Identify the unobserved assertion, revision or boundary and the test or observation needed. |
|
|
15
|
+
| unresolved-authority | Ask the requirement or design owner for the governing decision. Proposed material cannot decide it. |
|
|
16
|
+
| unknown | Name the missing source or coverage. Continue work independent of that claim. |
|
|
17
|
+
|
|
18
|
+
Use a sequence, state table, decision table or a few sentences when static structure alone cannot explain the behavior. Use the selected documentation capability for a lasting guide. Use a lightweight in-conversation comparison if optional rendering is unavailable. Reuse existing review findings and proof records. Treat timestamps, playback and diagram validation as presentation information.
|