@akjamie/agentic-sdlc 1.4.0 → 1.6.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.md +57 -29
- package/assets/commands/asdlc-approve.md +2 -2
- package/assets/config/config.yaml +1 -1
- package/assets/policy/policy.yaml +6 -0
- package/assets/schema/risk-assessment.schema.json +2 -1
- package/assets/schema/schema.yaml +168 -168
- package/assets/skills/asdlc-apply/SKILL.md +1 -1
- package/assets/skills/asdlc-approve/SKILL.md +2 -2
- package/assets/skills/asdlc-archive/SKILL.md +17 -13
- package/assets/skills/asdlc-doctor/SKILL.md +8 -8
- package/assets/skills/asdlc-impl-review/SKILL.md +15 -25
- package/assets/skills/asdlc-init/SKILL.md +11 -18
- package/assets/skills/asdlc-new/SKILL.md +5 -2
- package/assets/skills/asdlc-pr/SKILL.md +13 -8
- package/assets/skills/asdlc-review/SKILL.md +7 -7
- package/assets/skills/asdlc-spec-review/SKILL.md +10 -20
- package/package.json +2 -1
- package/src/assess/ai_judge.js +106 -36
- package/src/assess/decide.js +8 -6
- package/src/assess/index.js +13 -3
- package/src/assess/rules/builtin.js +7 -2
- package/src/assess/schema.js +6 -1
- package/src/assess/vectors/v1_intent.js +53 -8
- package/src/assess/vectors/v2_security.js +24 -1
- package/src/assess/vectors/v3_topology.js +125 -13
- package/src/commands/apply.js +33 -4
- package/src/commands/approve.js +2 -3
- package/src/commands/archive.js +116 -64
- package/src/commands/doctor.js +22 -19
- package/src/commands/init.js +24 -50
- package/src/commands/lint.js +32 -2
- package/src/commands/new.js +23 -22
- package/src/commands/pr.js +106 -25
- package/src/commands/status.js +1 -1
- package/src/commands/test.js +101 -5
- package/src/commands/update.js +1 -11
- package/src/commands/verify.js +141 -34
- package/src/lib/agents.js +2 -2
- package/src/lib/cliutil.js +57 -7
- package/src/lib/git.js +10 -4
- package/src/lib/graphify.js +89 -14
- package/src/lib/level.js +63 -9
- package/src/lib/openspec.js +61 -31
- package/src/lib/paths.js +0 -2
- package/src/lib/policy.js +4 -0
- package/src/lib/schema.js +32 -11
- package/src/lib/speclint.js +5 -3
- package/src/lib/tdd.js +35 -11
- package/assets/ci/asdlc-ai-review.yml +0 -65
- package/assets/githooks/post-merge +0 -22
- package/assets/githooks/pre-push +0 -17
package/src/commands/init.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { exists, ensureDir, copyTree, readText, writeText
|
|
3
|
-
import { openspecDir, configAssetFile,
|
|
2
|
+
import { exists, ensureDir, copyTree, readText, writeText } from '../lib/fs.js';
|
|
3
|
+
import { openspecDir, configAssetFile, schemaAssetDir, SCHEMA_NAME } from '../lib/paths.js';
|
|
4
4
|
import { installSchema, builtinSchemaVersion, localOverride } from '../lib/schema.js';
|
|
5
5
|
import { log } from '../lib/log.js';
|
|
6
6
|
import { runOpenspec, openspecVersion, ensureOpenspec } from '../lib/openspec.js';
|
|
7
|
-
import { git } from '../lib/git.js';
|
|
8
7
|
import { ensureGraphify, buildGraph, ensureGitignore } from '../lib/graphify.js';
|
|
9
8
|
import { refreshAgents } from '../lib/agents.js';
|
|
10
9
|
import { ensureRemoteLabels } from './pr.js';
|
|
@@ -16,16 +15,14 @@ export function initRepo(opts = {}) {
|
|
|
16
15
|
const repoRoot = path.resolve(opts.repoRoot ?? process.cwd());
|
|
17
16
|
const osDir = openspecDir(repoRoot);
|
|
18
17
|
|
|
19
|
-
// 1)
|
|
20
|
-
//
|
|
21
|
-
// is idempotent and never resets our governance config.
|
|
18
|
+
// 1) Resolve bundled OpenSpec engine (zero package.json / node_modules pollution in target repo),
|
|
19
|
+
// then initialize OpenSpec project structure & wire agent tooling idempotently.
|
|
22
20
|
const osInstall = opts.openspec === false
|
|
23
21
|
? { installed: openspecVersion(repoRoot) != null, action: 'skipped' }
|
|
24
22
|
: ensureOpenspec(repoRoot);
|
|
25
23
|
if (!osInstall.installed) {
|
|
26
|
-
log.warn('openspec CLI unavailable
|
|
24
|
+
log.warn('openspec CLI unavailable');
|
|
27
25
|
} else {
|
|
28
|
-
if (osInstall.action === 'npm-install') log.ok(`installed openspec@${'1.13.2'} (devDependency)`);
|
|
29
26
|
const tools = opts.tools ?? (detectTools(repoRoot).join(',') || 'none');
|
|
30
27
|
const res = runOpenspec(['init', '--tools', tools, '--no-animation'], repoRoot);
|
|
31
28
|
if (res.status === 0) log.ok(`openspec init --tools ${tools}`);
|
|
@@ -34,20 +31,22 @@ export function initRepo(opts = {}) {
|
|
|
34
31
|
ensureDir(path.join(osDir, 'changes'));
|
|
35
32
|
ensureDir(path.join(osDir, 'specs'));
|
|
36
33
|
|
|
37
|
-
// 1.5)
|
|
38
|
-
// copied into the repo. This IS the OpenSpec customization layer - the
|
|
39
|
-
// enterprise change flow (proposal -> specs -> review -> tasks).
|
|
34
|
+
// 1.5) Managed OpenSpec schema: bundled statelessly with asdlc and optionally cached in user data dir.
|
|
40
35
|
const override = localOverride(repoRoot);
|
|
41
36
|
if (override.tracked) {
|
|
42
37
|
log.warn(`committed local schema copy found: ${override.path}`);
|
|
43
|
-
log.warn('
|
|
38
|
+
log.warn('per-repo committed schema overrides are disallowed; remove it to use the bundled schema');
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const schemaDest = installSchema();
|
|
42
|
+
log.ok(`synced managed schema v${builtinSchemaVersion()} -> ${path.relative(repoRoot, schemaDest) || schemaDest}`);
|
|
43
|
+
} catch {
|
|
44
|
+
log.info(`using stateless bundled schema v${builtinSchemaVersion()}`);
|
|
44
45
|
}
|
|
45
|
-
const schemaDest = installSchema();
|
|
46
|
-
log.ok(`installed managed schema v${builtinSchemaVersion()} -> ${path.relative(repoRoot, schemaDest) || schemaDest}`);
|
|
47
46
|
if (opts.vendor) {
|
|
48
47
|
const vendored = path.join(osDir, 'schemas', SCHEMA_NAME);
|
|
49
48
|
copyTree(schemaAssetDir, vendored);
|
|
50
|
-
log.ok(`vendored schema -> openspec/schemas/${SCHEMA_NAME} (
|
|
49
|
+
log.ok(`vendored schema -> openspec/schemas/${SCHEMA_NAME} (do not commit)`);
|
|
51
50
|
}
|
|
52
51
|
|
|
53
52
|
// 2) Governance overlay: schema name + context + rules + lint + verify policy.
|
|
@@ -65,26 +64,17 @@ export function initRepo(opts = {}) {
|
|
|
65
64
|
log.ok('wrote governance config (openspec/config.yaml)');
|
|
66
65
|
}
|
|
67
66
|
|
|
68
|
-
// 3)
|
|
69
|
-
if (opts.ci === 'jenkins') {
|
|
70
|
-
const dest = path.join(repoRoot, 'Jenkinsfile');
|
|
71
|
-
if (exists(dest) && !opts.force) log.step('Jenkinsfile exists (use --force)');
|
|
72
|
-
else { writeText(dest, readText(path.join(ciAssetDir, 'Jenkinsfile'))); log.ok('wrote Jenkinsfile'); }
|
|
73
|
-
}
|
|
74
|
-
if (opts.hooks !== false) installHooks(repoRoot);
|
|
75
|
-
|
|
76
|
-
// 3.6) Pre-provision remote governance labels if git remote & gh are available
|
|
67
|
+
// 3) Pre-provision remote governance labels if git remote & gh are available
|
|
77
68
|
try {
|
|
78
69
|
ensureRemoteLabels(repoRoot);
|
|
79
70
|
} catch { /* ignore */ }
|
|
80
71
|
|
|
81
|
-
// 4) graphify
|
|
82
|
-
// Deterministic code-only AST (no LLM key), bound to HEAD, derived cache.
|
|
72
|
+
// 4) graphify: deterministic code-only AST navigation & topology graph (no LLM key), bound to HEAD.
|
|
83
73
|
if (opts.graph !== false) {
|
|
84
74
|
const g = ensureGraphify();
|
|
85
75
|
if (!g.installed) {
|
|
86
|
-
log.warn('graphify not installed and could not be installed');
|
|
87
|
-
log.info(' install
|
|
76
|
+
log.warn('graphify not installed and could not be auto-installed');
|
|
77
|
+
log.info(' install via internal mirror: pip install -i <mirror-url> graphifyy (or uv tool install graphifyy)');
|
|
88
78
|
} else {
|
|
89
79
|
if (g.action !== 'present') log.ok(`installed graphify (${g.action})`);
|
|
90
80
|
const b = buildGraph(repoRoot);
|
|
@@ -94,15 +84,13 @@ export function initRepo(opts = {}) {
|
|
|
94
84
|
}
|
|
95
85
|
}
|
|
96
86
|
|
|
97
|
-
// 4.5) Bundled Agent Skills & Slash Commands
|
|
98
|
-
// slash command parity into detected agent tools (.claude, .opencode, .pi, .agents, .github, etc.)
|
|
87
|
+
// 4.5) Bundled Agent Skills & Slash Commands
|
|
99
88
|
const explicitTools = opts.tools ? opts.tools.split(',').map((s) => s.trim().toLowerCase()) : [];
|
|
100
89
|
const allTools = [...new Set([...detectTools(repoRoot), ...explicitTools])];
|
|
101
90
|
installSkills(repoRoot, allTools);
|
|
102
91
|
installCommands(repoRoot, allTools);
|
|
103
92
|
|
|
104
|
-
// 5) AGENTS.md: the routing layer the agentic IDE reads
|
|
105
|
-
// status derived from the graph). Written after the graph so status has nodes.
|
|
93
|
+
// 5) AGENTS.md: the routing layer the agentic IDE reads
|
|
106
94
|
refreshAgents(repoRoot);
|
|
107
95
|
log.ok('refreshed AGENTS.md (asdlc workflow + system status)');
|
|
108
96
|
|
|
@@ -110,33 +98,19 @@ export function initRepo(opts = {}) {
|
|
|
110
98
|
log.info('Next:');
|
|
111
99
|
log.info(' 1. start a spec: asdlc new "<requirement>"');
|
|
112
100
|
log.info(' 2. check the spec: asdlc lint <CHANGE-ID>');
|
|
113
|
-
log.info(' 3.
|
|
114
|
-
log.info(' 4.
|
|
101
|
+
log.info(' 3. open Spec PR: asdlc pr <CHANGE-ID> <targetBranch>');
|
|
102
|
+
log.info(' 4. verify & Impl PR: asdlc verify <CHANGE-ID>');
|
|
115
103
|
return repoRoot;
|
|
116
104
|
}
|
|
117
105
|
|
|
118
|
-
export function installHooks(repoRoot) {
|
|
119
|
-
if (!exists(githooksAssetDir)) return;
|
|
120
|
-
const dest = path.join(repoRoot, '.githooks');
|
|
121
|
-
copyTree(githooksAssetDir, dest);
|
|
122
|
-
try {
|
|
123
|
-
git(['config', 'core.hooksPath', '.githooks'], repoRoot);
|
|
124
|
-
log.ok('installed .githooks (pre-push, post-merge) + core.hooksPath');
|
|
125
|
-
} catch {
|
|
126
|
-
log.warn('could not set core.hooksPath (not a git repo?)');
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
106
|
export function register(program) {
|
|
131
107
|
program
|
|
132
108
|
.command('init')
|
|
133
|
-
.description('set up a repo:
|
|
109
|
+
.description('set up a repo: OpenSpec project + governance overlay + Graphify AST + agent skills')
|
|
134
110
|
.option('--repo-root <path>', 'repository root (default: cwd)')
|
|
135
111
|
.option('--tools <list>', 'OpenSpec agent tools (default: auto-detect)')
|
|
136
|
-
.option('--ci <name>', 'scaffold a CI pipeline (supported: jenkins)')
|
|
137
|
-
.option('--no-hooks', 'skip installing .githooks')
|
|
138
112
|
.option('--no-graph', 'skip graphify install/build')
|
|
139
113
|
.option('--no-openspec', 'skip the openspec CLI step')
|
|
140
|
-
.option('--force', 'overwrite existing config
|
|
114
|
+
.option('--force', 'overwrite existing governance config')
|
|
141
115
|
.action((opts) => initRepo(opts));
|
|
142
116
|
}
|
package/src/commands/lint.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { exists, readText, walkFiles } from '../lib/fs.js';
|
|
2
|
+
import { exists, readText, writeText, walkFiles } from '../lib/fs.js';
|
|
3
3
|
import { changeDir } from '../lib/paths.js';
|
|
4
4
|
import { requireRepo, toChangeSlug, readLintConfig, jsonOut } from '../lib/cliutil.js';
|
|
5
5
|
import { lintSpecText, countBlockers } from '../lib/speclint.js';
|
|
6
|
+
import { assess } from '../assess/index.js';
|
|
6
7
|
import { log, dim } from '../lib/log.js';
|
|
7
8
|
|
|
8
9
|
// THE spec check (v10: lint absorbed review). Deterministic:
|
|
@@ -90,7 +91,7 @@ export function runLint(changeId, opts = {}) {
|
|
|
90
91
|
|
|
91
92
|
const reviewPath = path.join(cdir, 'review.md');
|
|
92
93
|
if (!exists(reviewPath)) {
|
|
93
|
-
add('review.md', 'pass', 'delegated to
|
|
94
|
+
add('review.md', 'pass', 'delegated to independent review agent (review comments & summary posted on PR)');
|
|
94
95
|
add('review verdict', 'pass', 'pending human PR review on GitHub/GitLab');
|
|
95
96
|
} else {
|
|
96
97
|
const text = readText(reviewPath);
|
|
@@ -100,6 +101,35 @@ export function runLint(changeId, opts = {}) {
|
|
|
100
101
|
add('blocking findings', hasBlockingFindings(text) ? 'fail' : 'pass', hasBlockingFindings(text) ? 'blocking findings present' : '');
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
// Spec-stage risk assessment: ground in artifacts and sync level/workflow mode
|
|
105
|
+
const metaPath = path.join(cdir, '.openspec.yaml');
|
|
106
|
+
let currLvl = null;
|
|
107
|
+
if (exists(metaPath)) {
|
|
108
|
+
const lvlMatch = readText(metaPath).match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
109
|
+
currLvl = lvlMatch ? lvlMatch[1].toUpperCase() : null;
|
|
110
|
+
}
|
|
111
|
+
const agentAssessPath = path.join(cdir, '.agent-assess.json');
|
|
112
|
+
if (currLvl || exists(agentAssessPath) || exists(path.join(cdir, 'risk-history.jsonl'))) {
|
|
113
|
+
const assessment = assess({
|
|
114
|
+
stage: 'spec',
|
|
115
|
+
changeId: slug,
|
|
116
|
+
repoRoot,
|
|
117
|
+
persist: true
|
|
118
|
+
});
|
|
119
|
+
const effectiveLevel = assessment.risk.level;
|
|
120
|
+
if (exists(metaPath) && currLvl !== effectiveLevel) {
|
|
121
|
+
let metaText = readText(metaPath);
|
|
122
|
+
const upsertKey = (text, key, val) => {
|
|
123
|
+
const re = new RegExp(`^\\s*${key}:\\s*.*$`, 'm');
|
|
124
|
+
return re.test(text) ? text.replace(re, `${key}: "${val}"`) : `${text.trimEnd()}\n${key}: "${val}"\n`;
|
|
125
|
+
};
|
|
126
|
+
metaText = upsertKey(metaText, 'level', effectiveLevel);
|
|
127
|
+
metaText = upsertKey(metaText, 'workflowMode', assessment.governance.workflow_mode);
|
|
128
|
+
writeText(metaPath, metaText);
|
|
129
|
+
}
|
|
130
|
+
add('governance level', 'pass', `${effectiveLevel} (${assessment.governance.workflow_mode})`);
|
|
131
|
+
}
|
|
132
|
+
|
|
103
133
|
const { rules } = readLintConfig(repoRoot);
|
|
104
134
|
const findings = [];
|
|
105
135
|
for (const file of specFiles) {
|
package/src/commands/new.js
CHANGED
|
@@ -34,28 +34,8 @@ export function newChange(requirement, opts = {}) {
|
|
|
34
34
|
// Determine grill mode: 'none' (--no-grill), 'batch' (--batch-grill), or 'interactive' (default grill-me)
|
|
35
35
|
const grillMode = opts.grill === false ? 'none' : (opts.batchGrill ? 'batch' : 'interactive');
|
|
36
36
|
|
|
37
|
-
//
|
|
38
|
-
const
|
|
39
|
-
requirement,
|
|
40
|
-
explicitLevel: opts.level,
|
|
41
|
-
repoRoot,
|
|
42
|
-
changeId: slug
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Record requirement, grill mode, and governance level in change metadata (.openspec.yaml)
|
|
46
|
-
const metaPath = path.join(cdir, '.openspec.yaml');
|
|
47
|
-
if (exists(metaPath)) {
|
|
48
|
-
const existing = readText(metaPath).trimEnd();
|
|
49
|
-
writeText(metaPath, `${existing}\nrequirement: ${JSON.stringify(requirement)}\ngrillMode: "${grillMode}"\nchangeType: "${changeType}"\nworkflowMode: "${workflowMode}"\nlevel: "${level}"\nlevelReason: ${JSON.stringify(levelReason)}\n`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (workflowMode === 'single-pr') {
|
|
53
|
-
log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Single PR mode: code & specs in one PR]`);
|
|
54
|
-
} else {
|
|
55
|
-
log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Spec-first mode: Spec PR required before implementation]`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const g = ensureGraphify();
|
|
37
|
+
// Grounding in knowledge graph (explore.md) before assessing initial risk level
|
|
38
|
+
const g = ensureGraphify({ autoInstall: false });
|
|
59
39
|
if (!g.installed) {
|
|
60
40
|
log.warn('[WARN] explore.md generated without graph context (Graphify not installed). Run `asdlc init --graph` to enable architectural AST index.');
|
|
61
41
|
const fallbackMd = `# Explore: ${slug}
|
|
@@ -116,6 +96,27 @@ _(unavailable - graph query error)_
|
|
|
116
96
|
}
|
|
117
97
|
}
|
|
118
98
|
|
|
99
|
+
// Infer governance level (L0, L1, L2, L3) via unified assessment engine (grounded in explore.md)
|
|
100
|
+
const { level, changeType, workflowMode, reason: levelReason } = inferInitialLevel({
|
|
101
|
+
requirement,
|
|
102
|
+
explicitLevel: opts.level,
|
|
103
|
+
repoRoot,
|
|
104
|
+
changeId: slug
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Record requirement, grill mode, and governance level in change metadata (.openspec.yaml)
|
|
108
|
+
const metaPath = path.join(cdir, '.openspec.yaml');
|
|
109
|
+
if (exists(metaPath)) {
|
|
110
|
+
const existing = readText(metaPath).trimEnd();
|
|
111
|
+
writeText(metaPath, `${existing}\nrequirement: ${JSON.stringify(requirement)}\ngrillMode: "${grillMode}"\nchangeType: "${changeType}"\nworkflowMode: "${workflowMode}"\nlevel: "${level}"\nlevelReason: ${JSON.stringify(levelReason)}\n`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (workflowMode === 'single-pr') {
|
|
115
|
+
log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Single PR mode: code & specs in one PR]`);
|
|
116
|
+
} else {
|
|
117
|
+
log.ok(`assigned governance level: ${level} [Type: ${changeType}] (${levelReason}) - [Spec-first mode: Spec PR required before implementation]`);
|
|
118
|
+
}
|
|
119
|
+
|
|
119
120
|
// Seed the grilling interview / clarification record.
|
|
120
121
|
const clar = path.join(cdir, 'clarifications.md');
|
|
121
122
|
if (!exists(clar)) {
|
package/src/commands/pr.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
1
2
|
import path from 'node:path';
|
|
2
3
|
import { execFileSync } from 'node:child_process';
|
|
3
4
|
import { exists, readText, writeText } from '../lib/fs.js';
|
|
4
5
|
import { changeDir } from '../lib/paths.js';
|
|
5
6
|
import { requireRepo, toChangeSlug } from '../lib/cliutil.js';
|
|
6
|
-
import { git, isGitRepo, changeOnRef, lastCommitTouching } from '../lib/git.js';
|
|
7
|
+
import { git, isGitRepo, changeOnRef, lastCommitTouching, safeCommit } from '../lib/git.js';
|
|
8
|
+
import { loadPolicy, matchesAny } from '../lib/policy.js';
|
|
7
9
|
import { runLint } from './lint.js';
|
|
8
10
|
import { runVerify } from './verify.js';
|
|
9
11
|
import { fail } from '../lib/errors.js';
|
|
@@ -11,6 +13,77 @@ import { log } from '../lib/log.js';
|
|
|
11
13
|
import { assess, renderLabels, renderPRComment } from '../assess/index.js';
|
|
12
14
|
import { readEffectiveLevel } from '../lib/level.js';
|
|
13
15
|
|
|
16
|
+
const SAFE_ENV_TEMPLATE_RE = /(^|\/)\.env\.(example|sample|template|defaults|schema)$/i;
|
|
17
|
+
const SENSITIVE_OR_DUMP_PATTERNS = [
|
|
18
|
+
{ re: /(^|\/)\.env(\..+)?$/i, reason: 'dotenv file' },
|
|
19
|
+
{ re: /\.(pem|key|p12|pfx|jks|keystore)$/i, reason: 'cryptographic key/certificate' },
|
|
20
|
+
{ re: /(^|\/)id_(rsa|ed25519|ecdsa|dsa)(\.pub)?$/i, reason: 'SSH key' },
|
|
21
|
+
{ re: /(^|\/)(credentials|service-account[^/]*)\.(json|ya?ml)$/i, reason: 'credentials file' },
|
|
22
|
+
{ re: /(^|\/)\.?secrets?(\.(json|ya?ml|env|txt|toml))?$/i, reason: 'secrets file' },
|
|
23
|
+
{ re: /\.(hprof|dmp|core|heapdump)$/i, reason: 'crash/memory dump' },
|
|
24
|
+
{ re: /(^|\/)core\.\d+$/i, reason: 'core dump' },
|
|
25
|
+
{ re: /\.log(\.\d+)?$/i, reason: 'log artifact' },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Smart controlled staging for Implementation PRs:
|
|
30
|
+
* Stages modified/deleted tracked files and legitimate untracked source/assets,
|
|
31
|
+
* while skipping untracked secrets, crash dumps, logs, and oversized blobs (> 50MB default)
|
|
32
|
+
* with a warning so unattended automation never halts or leaks credentials.
|
|
33
|
+
*/
|
|
34
|
+
export function stageImplementationChanges(repoRoot, opts = {}) {
|
|
35
|
+
const policy = opts.policy ?? loadPolicy(repoRoot);
|
|
36
|
+
const maxMb = Number(opts.maxFileSizeMb ?? policy?.staging?.max_file_size_mb ?? 50);
|
|
37
|
+
const maxBytes = maxMb * 1024 * 1024;
|
|
38
|
+
const extraIgnoreGlobs = Array.isArray(policy?.staging?.ignore_patterns) ? policy.staging.ignore_patterns : [];
|
|
39
|
+
|
|
40
|
+
// 1. Stage all tracked file modifications & deletions
|
|
41
|
+
git(['add', '-u'], repoRoot, { allowFail: true });
|
|
42
|
+
|
|
43
|
+
// 2. Inspect untracked files respecting .gitignore
|
|
44
|
+
const untrackedOut = git(['ls-files', '--others', '--exclude-standard'], repoRoot, { allowFail: true }) ?? '';
|
|
45
|
+
const untracked = untrackedOut.split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
|
|
46
|
+
|
|
47
|
+
const staged = [];
|
|
48
|
+
const skipped = [];
|
|
49
|
+
|
|
50
|
+
for (const rel of untracked) {
|
|
51
|
+
const norm = rel.replace(/\\/g, '/');
|
|
52
|
+
|
|
53
|
+
if (extraIgnoreGlobs.length > 0 && matchesAny(norm, extraIgnoreGlobs)) {
|
|
54
|
+
const reason = 'matched policy.staging.ignore_patterns';
|
|
55
|
+
skipped.push({ file: norm, reason });
|
|
56
|
+
log.warn(`[WARN] Skipped untracked sensitive/artifact file: ${norm} (${reason})`);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!SAFE_ENV_TEMPLATE_RE.test(norm)) {
|
|
61
|
+
const matchedRule = SENSITIVE_OR_DUMP_PATTERNS.find((r) => r.re.test(norm));
|
|
62
|
+
if (matchedRule) {
|
|
63
|
+
skipped.push({ file: norm, reason: matchedRule.reason });
|
|
64
|
+
log.warn(`[WARN] Skipped untracked sensitive/artifact file: ${norm} (${matchedRule.reason})`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
const stat = fs.statSync(path.join(repoRoot, rel));
|
|
71
|
+
if (stat.isFile() && stat.size > maxBytes) {
|
|
72
|
+
const sizeMb = (stat.size / (1024 * 1024)).toFixed(1);
|
|
73
|
+
const reason = `size ${sizeMb}MB exceeds ${maxMb}MB limit`;
|
|
74
|
+
skipped.push({ file: norm, reason });
|
|
75
|
+
log.warn(`[WARN] Skipped untracked sensitive/artifact file: ${norm} (${reason})`);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
} catch { /* ignore stat race */ }
|
|
79
|
+
|
|
80
|
+
git(['add', '--', rel], repoRoot, { allowFail: true });
|
|
81
|
+
staged.push(norm);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return { staged, skipped };
|
|
85
|
+
}
|
|
86
|
+
|
|
14
87
|
export const ASDLC_LABELS = {
|
|
15
88
|
'asdlc:spec-review': {
|
|
16
89
|
color: '1d76db',
|
|
@@ -85,10 +158,14 @@ export async function createPR(changeId, targetBranch, opts = {}) {
|
|
|
85
158
|
|| changeOnRef(repoRoot, `origin/${targetBranch}`, slug)
|
|
86
159
|
|| Boolean(lastCommitTouching(repoRoot, targetBranch, [`openspec/changes/${slug}/proposal.md`]));
|
|
87
160
|
|
|
88
|
-
//
|
|
89
|
-
const
|
|
161
|
+
// Inspect both committed diff and uncommitted working-tree changes to correctly detect source modifications
|
|
162
|
+
const diffFilesPre = (git(['diff', '--name-only', `${targetBranch}...HEAD`], repoRoot, { allowFail: true }) ?? '')
|
|
163
|
+
.split(/\r?\n/).filter(Boolean);
|
|
164
|
+
const statusLines = (git(['status', '--porcelain', '-uall'], repoRoot, { allowFail: true }) ?? '')
|
|
90
165
|
.split(/\r?\n/).filter(Boolean);
|
|
91
|
-
const
|
|
166
|
+
const uncommittedFiles = statusLines.map((l) => l.replace(/^\s*\S+\s+/, '').trim()).filter(Boolean);
|
|
167
|
+
const allPotentialFiles = [...diffFilesPre, ...uncommittedFiles];
|
|
168
|
+
const hasSourceChanges = allPotentialFiles.some((f) => !f.startsWith(`openspec/changes/${slug}/`));
|
|
92
169
|
|
|
93
170
|
const lvlMatch = metaText.match(/^\s*level:\s*['"]?([^\s'"]+)['"]?\s*$/m);
|
|
94
171
|
const changeLevel = lvlMatch ? lvlMatch[1].toUpperCase() : null;
|
|
@@ -115,7 +192,30 @@ export async function createPR(changeId, targetBranch, opts = {}) {
|
|
|
115
192
|
const secondaryLabel = isSpec ? 'spec' : 'impl';
|
|
116
193
|
const prTypeName = isSpec ? 'Spec PR' : 'Implementation PR';
|
|
117
194
|
|
|
118
|
-
// 1.
|
|
195
|
+
// 1. Stage & commit any unstaged changes BEFORE running pre-flight gates,
|
|
196
|
+
// ensuring runVerify and runLint evaluate the true, complete state being pushed.
|
|
197
|
+
try {
|
|
198
|
+
if (isSpec) {
|
|
199
|
+
git(['add', `openspec/changes/${slug}`], repoRoot);
|
|
200
|
+
const status = git(['status', '--porcelain', `openspec/changes/${slug}`], repoRoot);
|
|
201
|
+
if (status) {
|
|
202
|
+
safeCommit(repoRoot, `spec(${slug}): specify feature intent`);
|
|
203
|
+
log.ok('committed latest spec changes');
|
|
204
|
+
}
|
|
205
|
+
} else {
|
|
206
|
+
stageImplementationChanges(repoRoot);
|
|
207
|
+
const diffCached = git(['diff', '--cached', '--name-only'], repoRoot, { allowFail: true });
|
|
208
|
+
if (diffCached && diffCached.trim()) {
|
|
209
|
+
safeCommit(repoRoot, `impl(${slug}): implement verified changes`);
|
|
210
|
+
log.ok('committed latest implementation changes');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
} catch { /* ignore */ }
|
|
214
|
+
|
|
215
|
+
const diffFiles = (git(['diff', '--name-only', `${targetBranch}...HEAD`], repoRoot, { allowFail: true }) ?? '')
|
|
216
|
+
.split(/\r?\n/).filter(Boolean);
|
|
217
|
+
|
|
218
|
+
// 2. Pre-flight self-check (evaluates committed HEAD vs targetBranch)
|
|
119
219
|
if (isSpec) {
|
|
120
220
|
log.step(`running spec lint pre-flight for ${slug}...`);
|
|
121
221
|
const lintExit = runLint(slug, { repoRoot, json: true });
|
|
@@ -138,7 +238,7 @@ export async function createPR(changeId, targetBranch, opts = {}) {
|
|
|
138
238
|
log.ok('implementation verify passed (all 12 gates passed)');
|
|
139
239
|
}
|
|
140
240
|
|
|
141
|
-
//
|
|
241
|
+
// 3. Extract Title and Description from proposal.md
|
|
142
242
|
const proposalPath = path.join(cdir, 'proposal.md');
|
|
143
243
|
if (!exists(proposalPath)) fail(`proposal.md missing for ${slug}`);
|
|
144
244
|
const proposalText = readText(proposalPath);
|
|
@@ -150,25 +250,6 @@ export async function createPR(changeId, targetBranch, opts = {}) {
|
|
|
150
250
|
if (raw) title = `${isSpec ? 'spec' : 'impl'}(${slug}): ${raw}`;
|
|
151
251
|
}
|
|
152
252
|
|
|
153
|
-
// 3. Stage & commit any unstaged changes
|
|
154
|
-
try {
|
|
155
|
-
if (isSpec) {
|
|
156
|
-
git(['add', `openspec/changes/${slug}`], repoRoot);
|
|
157
|
-
const status = git(['status', '--porcelain', `openspec/changes/${slug}`], repoRoot);
|
|
158
|
-
if (status) {
|
|
159
|
-
execFileSync('git', ['commit', '-m', `spec(${slug}): specify feature intent`], { cwd: repoRoot, stdio: 'ignore' });
|
|
160
|
-
log.ok('committed latest spec changes');
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
git(['add', '-A'], repoRoot);
|
|
164
|
-
const status = git(['status', '--porcelain'], repoRoot);
|
|
165
|
-
if (status) {
|
|
166
|
-
execFileSync('git', ['commit', '-m', `impl(${slug}): implement verified changes`], { cwd: repoRoot, stdio: 'ignore' });
|
|
167
|
-
log.ok('committed latest implementation changes');
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
} catch { /* ignore */ }
|
|
171
|
-
|
|
172
253
|
// 4. Push to remote
|
|
173
254
|
log.step(`pushing branch '${currentBranch}' to origin...`);
|
|
174
255
|
try {
|
package/src/commands/status.js
CHANGED
|
@@ -56,7 +56,7 @@ export function statusChange(changeId, opts = {}) {
|
|
|
56
56
|
let next;
|
|
57
57
|
if (!has('explore.md') && !has('proposal.md')) next = `asdlc new ${changeId}`;
|
|
58
58
|
else if (!has('proposal.md') || specFiles.length === 0) next = 'author proposal.md + specs/**';
|
|
59
|
-
else if (!approvedSha) next = `run: asdlc lint ${changeId} && asdlc pr ${changeId} (
|
|
59
|
+
else if (!approvedSha) next = `run: asdlc lint ${changeId} && asdlc pr ${changeId} (after independent spec review & merge, run: asdlc approve ${changeId})`;
|
|
60
60
|
else if (unchecked !== 0) next = `asdlc apply ${changeId}, then complete tasks in tasks.md`;
|
|
61
61
|
else next = `asdlc verify ${changeId}`;
|
|
62
62
|
|
package/src/commands/test.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { exists, readText, walkFiles } from '../lib/fs.js';
|
|
3
|
-
import { changeDir } from '../lib/paths.js';
|
|
3
|
+
import { changeDir, openspecDir } from '../lib/paths.js';
|
|
4
4
|
import { requireRepo, toChangeSlug } from '../lib/cliutil.js';
|
|
5
5
|
import { runShell } from '../lib/exec.js';
|
|
6
6
|
import { fail } from '../lib/errors.js';
|
|
7
7
|
import { log } from '../lib/log.js';
|
|
8
|
+
import { readYaml } from '../lib/yaml.js';
|
|
8
9
|
|
|
9
10
|
export function parseSpecAcceptanceCriteria(specText) {
|
|
10
11
|
const acs = [];
|
|
@@ -79,7 +80,7 @@ export function runTests(changeId, opts = {}) {
|
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
if (!opts.json) {
|
|
83
|
+
if (!opts.json && !opts.silent) {
|
|
83
84
|
log.info(`=== Running Acceptance Tests for ${slug} ===`);
|
|
84
85
|
log.info(`Mapped ACs: ${allAcs.length} across ${uniqueTestPaths.length} test file(s):`);
|
|
85
86
|
for (const ac of allAcs) {
|
|
@@ -88,9 +89,16 @@ export function runTests(changeId, opts = {}) {
|
|
|
88
89
|
log.info('');
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
const testCfg = path.join(openspecDir(repoRoot), 'config.yaml');
|
|
93
|
+
let configuredRunner = null;
|
|
94
|
+
if (exists(testCfg)) {
|
|
95
|
+
try {
|
|
96
|
+
const parsed = readYaml(testCfg);
|
|
97
|
+
configuredRunner = parsed?.test?.runner || parsed?.testing?.runner || null;
|
|
98
|
+
} catch { /* ignore config parse error */ }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const runnerCmd = opts.runner ?? configuredRunner ?? detectTestRunner(repoRoot, uniqueTestPaths);
|
|
94
102
|
|
|
95
103
|
const res = runShell(runnerCmd, repoRoot, {
|
|
96
104
|
env: { NODE_TEST_CONTEXT: undefined },
|
|
@@ -98,11 +106,16 @@ export function runTests(changeId, opts = {}) {
|
|
|
98
106
|
});
|
|
99
107
|
const passed = res.status === 0;
|
|
100
108
|
|
|
109
|
+
if (opts.silent) {
|
|
110
|
+
return passed ? 0 : 1;
|
|
111
|
+
}
|
|
112
|
+
|
|
101
113
|
if (opts.json) {
|
|
102
114
|
const output = {
|
|
103
115
|
changeId: slug,
|
|
104
116
|
pass: passed,
|
|
105
117
|
status: passed ? 'pass' : 'fail',
|
|
118
|
+
runner: runnerCmd,
|
|
106
119
|
acCount: allAcs.length,
|
|
107
120
|
testFiles: uniqueTestPaths,
|
|
108
121
|
acs: allAcs,
|
|
@@ -124,6 +137,89 @@ export function runTests(changeId, opts = {}) {
|
|
|
124
137
|
return passed ? 0 : 1;
|
|
125
138
|
}
|
|
126
139
|
|
|
140
|
+
export function detectTestRunner(repoRoot, uniqueTestPaths = []) {
|
|
141
|
+
const quotePath = (p) => (process.platform === 'win32' || /\s/.test(p) ? `"${p}"` : p);
|
|
142
|
+
const quotedPaths = uniqueTestPaths.map(quotePath).join(' ');
|
|
143
|
+
|
|
144
|
+
const allGo = uniqueTestPaths.length > 0 && uniqueTestPaths.every((p) => p.endsWith('.go'));
|
|
145
|
+
const allPy = uniqueTestPaths.length > 0 && uniqueTestPaths.every((p) => p.endsWith('.py'));
|
|
146
|
+
const allRs = uniqueTestPaths.length > 0 && uniqueTestPaths.every((p) => p.endsWith('.rs'));
|
|
147
|
+
const allJvm = uniqueTestPaths.length > 0 && uniqueTestPaths.every((p) => /\.(java|kt|scala)$/i.test(p));
|
|
148
|
+
|
|
149
|
+
if (allGo) {
|
|
150
|
+
const goPkgs = [...new Set(uniqueTestPaths.map((p) => {
|
|
151
|
+
const dir = path.dirname(p).replace(/\\/g, '/');
|
|
152
|
+
return dir === '.' ? '.' : `./${dir}`;
|
|
153
|
+
}))];
|
|
154
|
+
return `go test ${goPkgs.join(' ')}`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (allPy) {
|
|
158
|
+
return `pytest ${quotedPaths}`;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (allRs) {
|
|
162
|
+
return 'cargo test';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (allJvm) {
|
|
166
|
+
const classNames = [...new Set(uniqueTestPaths.map((p) => path.basename(p).replace(/\.(java|kt|scala)$/i, '')))];
|
|
167
|
+
const hasGradle = exists(path.join(repoRoot, 'build.gradle'))
|
|
168
|
+
|| exists(path.join(repoRoot, 'build.gradle.kts'))
|
|
169
|
+
|| exists(path.join(repoRoot, 'gradlew'));
|
|
170
|
+
if (hasGradle) {
|
|
171
|
+
const gradleBin = exists(path.join(repoRoot, 'gradlew'))
|
|
172
|
+
? (process.platform === 'win32' && exists(path.join(repoRoot, 'gradlew.bat')) ? 'gradlew.bat' : './gradlew')
|
|
173
|
+
: 'gradle';
|
|
174
|
+
const testsArgs = classNames.map((c) => `--tests ${c}`).join(' ');
|
|
175
|
+
return `${gradleBin} test ${testsArgs}`.trim();
|
|
176
|
+
}
|
|
177
|
+
const mvnBin = exists(path.join(repoRoot, 'mvnw'))
|
|
178
|
+
? (process.platform === 'win32' && exists(path.join(repoRoot, 'mvnw.cmd')) ? 'mvnw.cmd' : './mvnw')
|
|
179
|
+
: 'mvn';
|
|
180
|
+
return classNames.length > 0
|
|
181
|
+
? `${mvnBin} test -Dtest=${classNames.join(',')}`
|
|
182
|
+
: `${mvnBin} test`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// JS / TS ecosystem inspection via package.json & config files
|
|
186
|
+
const pkgPath = path.join(repoRoot, 'package.json');
|
|
187
|
+
let pkg = {};
|
|
188
|
+
if (exists(pkgPath)) {
|
|
189
|
+
try { pkg = JSON.parse(readText(pkgPath)); } catch { pkg = {}; }
|
|
190
|
+
}
|
|
191
|
+
const deps = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) };
|
|
192
|
+
const testScript = String(pkg.scripts?.test || '');
|
|
193
|
+
|
|
194
|
+
const hasVitest = Boolean(
|
|
195
|
+
deps.vitest ||
|
|
196
|
+
/\bvitest\b/.test(testScript) ||
|
|
197
|
+
['vitest.config.ts', 'vitest.config.js', 'vitest.config.mts', 'vitest.config.mjs'].some((f) => exists(path.join(repoRoot, f)))
|
|
198
|
+
);
|
|
199
|
+
if (hasVitest) {
|
|
200
|
+
return `npx vitest run ${quotedPaths}`;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const hasJest = Boolean(
|
|
204
|
+
deps.jest ||
|
|
205
|
+
/\bjest\b/.test(testScript) ||
|
|
206
|
+
['jest.config.ts', 'jest.config.js', 'jest.config.cjs', 'jest.config.mjs'].some((f) => exists(path.join(repoRoot, f)))
|
|
207
|
+
);
|
|
208
|
+
if (hasJest) {
|
|
209
|
+
return `npx jest ${quotedPaths}`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const hasTsFiles = uniqueTestPaths.some((p) => /\.(ts|tsx|mts|cts)$/i.test(p));
|
|
213
|
+
if (hasTsFiles) {
|
|
214
|
+
if (deps.tsx || /\btsx\b/.test(testScript)) {
|
|
215
|
+
return `npx tsx --test ${quotedPaths}`;
|
|
216
|
+
}
|
|
217
|
+
return `node --experimental-strip-types --test ${quotedPaths}`;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return `node --test ${quotedPaths}`;
|
|
221
|
+
}
|
|
222
|
+
|
|
127
223
|
export function register(program) {
|
|
128
224
|
program
|
|
129
225
|
.command('test <changeId>')
|
package/src/commands/update.js
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import { exists } from '../lib/fs.js';
|
|
3
3
|
import { resolveRepoRoot, openspecDir, OPENSPEC_DIR } from '../lib/paths.js';
|
|
4
4
|
import { log } from '../lib/log.js';
|
|
5
|
-
import { detectTools, installSkills, installCommands
|
|
5
|
+
import { detectTools, installSkills, installCommands } from './init.js';
|
|
6
6
|
import { ensureGraphify, buildGraph, ensureGitignore } from '../lib/graphify.js';
|
|
7
7
|
import { refreshAgents } from '../lib/agents.js';
|
|
8
8
|
|
|
@@ -76,15 +76,6 @@ export function updateRepo(opts = {}) {
|
|
|
76
76
|
log.warn(`AGENTS.md refresh failed: ${err.message}`);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
// 4) Git governance hooks
|
|
80
|
-
if (opts.hooks !== false) {
|
|
81
|
-
try {
|
|
82
|
-
installHooks(repoRoot);
|
|
83
|
-
} catch (err) {
|
|
84
|
-
log.warn(`git hooks refresh failed: ${err.message}`);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
79
|
log.info('');
|
|
89
80
|
log.ok('Repository SDLC state is fully up to date.');
|
|
90
81
|
return 0;
|
|
@@ -97,7 +88,6 @@ export function register(program) {
|
|
|
97
88
|
.option('--repo-root <path>', 'repository root (default: current repository)')
|
|
98
89
|
.option('--no-skills', 'skip refreshing agent skills')
|
|
99
90
|
.option('--no-graph', 'skip rebuilding codebase knowledge graph')
|
|
100
|
-
.option('--no-hooks', 'skip refreshing git hooks')
|
|
101
91
|
.action((opts) => {
|
|
102
92
|
process.exitCode = updateRepo(opts);
|
|
103
93
|
});
|