@sockulags/agent-os 0.15.0 → 0.17.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 +105 -59
- package/cli/doctor.mjs +351 -0
- package/cli/index.mjs +328 -151
- package/cli/index.test.mjs +436 -9
- package/package.json +5 -6
- package/plugins/agent-os-core/.claude-plugin/plugin.json +18 -0
- package/plugins/agent-os-core/.codex-plugin/plugin.json +24 -0
- package/plugins/agent-os-core/skills/capture-intent/SKILL.md +68 -0
- package/plugins/agent-os-core/skills/capture-intent/references/intent-template.md +47 -0
- package/plugins/agent-os-core/skills/explain-work/SKILL.md +42 -0
- package/{skills → plugins/agent-os-core/skills}/list-skills/SKILL.md +16 -7
- package/{skills → plugins/agent-os-core/skills}/plain-voice/SKILL.md +7 -4
- package/plugins/agent-os-core/skills/plan-work/SKILL.md +151 -0
- package/{skills → plugins/agent-os-core/skills}/plan-work/references/elicitation.md +7 -3
- package/plugins/agent-os-core/skills/plan-work/references/spec-template.md +65 -0
- package/plugins/agent-os-core/skills/record-lesson/SKILL.md +47 -0
- package/{skills → plugins/agent-os-core/skills}/scope-guard/SKILL.md +11 -6
- package/{skills → plugins/agent-os-core/skills}/verify-before-done/SKILL.md +6 -2
- package/plugins/agent-os-dev/.claude-plugin/plugin.json +18 -0
- package/plugins/agent-os-dev/.codex-plugin/plugin.json +24 -0
- package/plugins/agent-os-dev/hooks/hooks.json +42 -0
- package/{skills → plugins/agent-os-dev/skills}/batch-work/SKILL.md +6 -2
- package/{skills → plugins/agent-os-dev/skills}/check-work/SKILL.md +33 -14
- package/{skills/deliver-work/workflow.md → plugins/agent-os-dev/skills/deliver-work/SKILL.md} +126 -57
- package/plugins/agent-os-dev/skills/deliver-work/references/work-records.md +20 -0
- package/plugins/agent-os-dev/skills/design-work/SKILL.md +160 -0
- package/plugins/agent-os-dev/skills/design-work/scripts/render-sketch.mjs +233 -0
- package/plugins/agent-os-dev/skills/design-work/scripts/render-sketch.test.mjs +73 -0
- package/plugins/agent-os-dev/skills/diagnose-before-fix/SKILL.md +29 -0
- package/{skills → plugins/agent-os-dev/skills}/dispatch-next/SKILL.md +11 -3
- package/plugins/agent-os-dev/skills/init-agent-os/SKILL.md +131 -0
- package/plugins/agent-os-dev/skills/init-agent-os/policy.md +91 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/guards.md +40 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/repository-init.md +115 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/review-template.md +35 -0
- package/plugins/agent-os-dev/skills/init-agent-os/references/workflow-template.md +80 -0
- package/plugins/agent-os-dev/skills/init-agent-os/scripts/policy-block.mjs +187 -0
- package/plugins/agent-os-dev/skills/init-agent-os/templates/agent-review.yml +59 -0
- package/plugins/agent-os-dev/skills/init-agent-os/templates/lint-intents.yml +30 -0
- package/{skills → plugins/agent-os-dev/skills}/proportional-testing/SKILL.md +1 -1
- package/plugins/agent-os-dev/skills/quality-ratchet/SKILL.md +104 -0
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/references/project-controls.md +31 -3
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/analyzers.mjs +145 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/analyzers.test.mjs +158 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/guards.mjs +372 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/guards.test.mjs +138 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/intent-files.mjs +322 -0
- package/plugins/agent-os-dev/skills/quality-ratchet/scripts/intent-files.test.mjs +177 -0
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/project-controls.mjs +59 -8
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/project-controls.test.mjs +134 -8
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/quality-delta.mjs +296 -22
- package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/scripts/quality-delta.test.mjs +114 -6
- package/plugins/agent-os-dev/skills/shape-work/SKILL.md +135 -0
- package/plugins/agent-os-dev/skills/shape-work/references/implementation-issues.md +163 -0
- package/{skills/plan-work → plugins/agent-os-dev/skills/shape-work}/references/prototypes.md +9 -10
- package/plugins/agent-os-dev/skills/simplify/SKILL.md +91 -0
- package/plugins/agent-os-dev/skills/simplify/scripts/audit-evidence.mjs +166 -0
- package/plugins/agent-os-dev/skills/simplify/scripts/audit-evidence.test.mjs +49 -0
- package/policy.md +57 -30
- package/hooks/hooks.json +0 -17
- package/skills/deliver-work/SKILL.md +0 -12
- package/skills/diagnose-before-fix/SKILL.md +0 -24
- package/skills/explain-work/SKILL.md +0 -28
- package/skills/init-agent-os/SKILL.md +0 -55
- package/skills/init-agent-os/references/repository-init.md +0 -75
- package/skills/init-agent-os/scripts/policy-block.ps1 +0 -87
- package/skills/notice-lesson/SKILL.md +0 -20
- package/skills/plan-work/SKILL.md +0 -100
- package/skills/quality-ratchet/SKILL.md +0 -72
- package/skills/record-lesson/SKILL.md +0 -31
- package/skills/shape-work/SKILL.md +0 -71
- package/skills/shape-work/references/implementation-issues.md +0 -90
- package/skills/shape-work/references/mockups.md +0 -23
- package/skills/simplifier/SKILL.md +0 -35
- package/skills/simplifier-audit/SKILL.md +0 -30
- package/skills/simplifier-review/SKILL.md +0 -40
- package/skills/understand-work/SKILL.md +0 -32
- package/skills/understand-work/agents/openai.yaml +0 -2
- package/skills/writing-skills/SKILL.md +0 -68
- package/skills/writing-skills/agents/openai.yaml +0 -2
- /package/{skills/batch-work → plugins/agent-os-core/skills/capture-intent}/agents/openai.yaml +0 -0
- /package/{skills/deliver-work → plugins/agent-os-core/skills/explain-work}/agents/openai.yaml +0 -0
- /package/{skills/dispatch-next → plugins/agent-os-core/skills/list-skills}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-core/skills}/plain-voice/references/tells.md +0 -0
- /package/{skills/explain-work → plugins/agent-os-core/skills/plan-work}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-core/skills}/plan-work/references/map.md +0 -0
- /package/{skills/init-agent-os → plugins/agent-os-dev/skills/batch-work}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/batch-work/references/manifest.md +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/batch-work/scripts/manifest-hash.mjs +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/batch-work/scripts/test-manifest-hash.mjs +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/check-work/references/findings.md +0 -0
- /package/{skills/list-skills → plugins/agent-os-dev/skills/deliver-work}/agents/openai.yaml +0 -0
- /package/{skills/plan-work → plugins/agent-os-dev/skills/design-work}/agents/openai.yaml +0 -0
- /package/{skills/record-lesson → plugins/agent-os-dev/skills/dispatch-next}/agents/openai.yaml +0 -0
- /package/{skills/shape-work → plugins/agent-os-dev/skills/init-agent-os}/agents/openai.yaml +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/proportional-testing/references/strategy.md +0 -0
- /package/{skills → plugins/agent-os-dev/skills}/quality-ratchet/references/structure.md +0 -0
- /package/{skills/simplifier-audit → plugins/agent-os-dev/skills/shape-work}/agents/openai.yaml +0 -0
- /package/{skills/simplifier → plugins/agent-os-dev/skills/simplify}/agents/openai.yaml +0 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Collects deterministic simplification candidates for a repository-wide audit: the most complex
|
|
3
|
+
// functions (lizard), duplicated blocks (jscpd), and unused code (knip for JavaScript/TypeScript,
|
|
4
|
+
// vulture for Python). Each tool is optional and never installed here; a missing tool is reported
|
|
5
|
+
// as unavailable. The output is a ranked candidate list to verify, not a list of findings.
|
|
6
|
+
|
|
7
|
+
import { spawnSync } from 'node:child_process'
|
|
8
|
+
import fs from 'node:fs'
|
|
9
|
+
import os from 'node:os'
|
|
10
|
+
import path from 'node:path'
|
|
11
|
+
import { pathToFileURL } from 'node:url'
|
|
12
|
+
import { findLizard, lizardFunctions } from '../../quality-ratchet/scripts/analyzers.mjs'
|
|
13
|
+
import { isSourcePath } from '../../quality-ratchet/scripts/quality-delta.mjs'
|
|
14
|
+
|
|
15
|
+
const TIMEOUT_MS = 300000
|
|
16
|
+
const LINE_LIMIT = 40
|
|
17
|
+
|
|
18
|
+
function run(command, args, cwd, spawn) {
|
|
19
|
+
return spawn(command, args, {
|
|
20
|
+
cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: TIMEOUT_MS, maxBuffer: 64 * 1024 * 1024,
|
|
21
|
+
shell: process.platform === 'win32' && /\.(?:cmd|bat)$/i.test(command)
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function sourceFiles(root, spawn) {
|
|
26
|
+
const result = run('git', ['-C', root, 'ls-files', '-z', '--cached', '--others', '--exclude-standard'], root, spawn)
|
|
27
|
+
if (result.status !== 0) throw new Error(`git ls-files failed: ${result.stderr?.trim()}`)
|
|
28
|
+
return result.stdout.split('\0').filter(Boolean).map((file) => file.replaceAll('\\', '/')).filter(isSourcePath)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function localBin(root, name) {
|
|
32
|
+
const base = path.join(root, 'node_modules', '.bin', name)
|
|
33
|
+
return [base + (process.platform === 'win32' ? '.cmd' : ''), base].find((file) => fs.existsSync(file)) || null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Resolves a command to its full path so Windows .cmd shims can be launched.
|
|
37
|
+
function onPath(command, spawn) {
|
|
38
|
+
try {
|
|
39
|
+
const result = run(process.platform === 'win32' ? 'where.exe' : 'which', [command], process.cwd(), spawn)
|
|
40
|
+
if (result.status !== 0) return null
|
|
41
|
+
const hits = result.stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean)
|
|
42
|
+
// where.exe also lists extensionless shell shims that Windows cannot launch.
|
|
43
|
+
return (process.platform === 'win32' ? hits.find((hit) => /\.(?:exe|cmd|bat)$/i.test(hit)) : hits[0]) || null
|
|
44
|
+
} catch {
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function firstLines(text, limit = LINE_LIMIT) {
|
|
50
|
+
const lines = text.split(/\r?\n/).filter((line) => line.trim())
|
|
51
|
+
return { lines: lines.slice(0, limit), omitted: Math.max(0, lines.length - limit) }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function complexitySection(root, files, { analyze, limit = 15 } = {}) {
|
|
55
|
+
const functions = analyze(root, files)
|
|
56
|
+
if (functions === null) return { status: 'unavailable', reason: 'lizard is not installed.' }
|
|
57
|
+
const ranked = [...functions].sort((left, right) => right.ccn - left.ccn).slice(0, limit)
|
|
58
|
+
return { status: 'available', functions: ranked, analyzed: functions.length }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function summarizeJscpd(report, limit = 10) {
|
|
62
|
+
const total = report.statistics?.total || {}
|
|
63
|
+
const clones = (report.duplicates || [])
|
|
64
|
+
.map((clone) => ({
|
|
65
|
+
lines: clone.lines,
|
|
66
|
+
first: `${clone.firstFile.name.replaceAll('\\', '/')}:${clone.firstFile.start}-${clone.firstFile.end}`,
|
|
67
|
+
second: `${clone.secondFile.name.replaceAll('\\', '/')}:${clone.secondFile.start}-${clone.secondFile.end}`
|
|
68
|
+
}))
|
|
69
|
+
.sort((left, right) => right.lines - left.lines)
|
|
70
|
+
return { status: 'available', percentage: total.percentage ?? 0, clones: clones.slice(0, limit), total: clones.length }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function duplicationSection(root, spawn) {
|
|
74
|
+
const command = localBin(root, 'jscpd') || onPath('jscpd', spawn)
|
|
75
|
+
if (!command) return { status: 'unavailable', reason: 'jscpd is not installed in node_modules/.bin or on PATH.' }
|
|
76
|
+
const output = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-os-jscpd-'))
|
|
77
|
+
try {
|
|
78
|
+
run(command, ['--silent', '--reporters', 'json', '--output', output, '--gitignore',
|
|
79
|
+
'--ignore', '**/node_modules/**,**/dist/**,**/build/**,**/coverage/**,**/.git/**', '.'], root, spawn)
|
|
80
|
+
const reportPath = path.join(output, 'jscpd-report.json')
|
|
81
|
+
if (!fs.existsSync(reportPath)) return { status: 'unavailable', reason: 'jscpd produced no report.' }
|
|
82
|
+
return summarizeJscpd(JSON.parse(fs.readFileSync(reportPath, 'utf8')))
|
|
83
|
+
} finally {
|
|
84
|
+
fs.rmSync(output, { recursive: true, force: true })
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function deadCodeSection(root, files, spawn) {
|
|
89
|
+
const sections = []
|
|
90
|
+
const knip = localBin(root, 'knip')
|
|
91
|
+
if (knip) {
|
|
92
|
+
const result = run(knip, ['--reporter', 'compact', '--no-progress'], root, spawn)
|
|
93
|
+
sections.push({ tool: 'knip', status: 'available', ...firstLines(`${result.stdout}`) })
|
|
94
|
+
} else if (files.some((file) => /\.(?:[cm]?[jt]sx?)$/.test(file))) {
|
|
95
|
+
sections.push({ tool: 'knip', status: 'unavailable', reason: 'knip is not installed in node_modules/.bin.' })
|
|
96
|
+
}
|
|
97
|
+
const python = files.filter((file) => file.endsWith('.py'))
|
|
98
|
+
if (python.length) {
|
|
99
|
+
const vulture = onPath('vulture', spawn)
|
|
100
|
+
if (vulture) {
|
|
101
|
+
const result = run(vulture, ['--min-confidence', '80', ...python], root, spawn)
|
|
102
|
+
sections.push({ tool: 'vulture', status: 'available', ...firstLines(`${result.stdout}`) })
|
|
103
|
+
} else {
|
|
104
|
+
sections.push({ tool: 'vulture', status: 'unavailable', reason: 'vulture is not on PATH.' })
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return sections
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function collectEvidence(root, { spawn = spawnSync, analyze } = {}) {
|
|
111
|
+
const files = sourceFiles(root, spawn)
|
|
112
|
+
const launcher = analyze ? undefined : findLizard({ spawn })
|
|
113
|
+
const analyzer = analyze || ((cwd, list) => lizardFunctions(cwd, list, { launcher, spawn }))
|
|
114
|
+
const safe = (fn) => {
|
|
115
|
+
try { return fn() } catch (cause) { return { status: 'unavailable', reason: cause.message } }
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
root,
|
|
119
|
+
sourceFiles: files.length,
|
|
120
|
+
complexity: safe(() => complexitySection(root, files, { analyze: analyzer })),
|
|
121
|
+
duplication: safe(() => duplicationSection(root, spawn)),
|
|
122
|
+
deadCode: safe(() => deadCodeSection(root, files, spawn))
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function formatEvidence(evidence) {
|
|
127
|
+
const lines = [`Agent OS simplification evidence for ${evidence.root} (${evidence.sourceFiles} source files)`, '']
|
|
128
|
+
const { complexity, duplication, deadCode } = evidence
|
|
129
|
+
lines.push('Most complex functions (lizard, cyclomatic complexity):')
|
|
130
|
+
if (complexity.status === 'available') {
|
|
131
|
+
lines.push(...complexity.functions.map((fn) => ` ${fn.ccn} ${fn.file}:${fn.line} ${fn.function}`))
|
|
132
|
+
} else lines.push(` unavailable: ${complexity.reason}`)
|
|
133
|
+
lines.push('', 'Duplicated blocks (jscpd):')
|
|
134
|
+
if (duplication.status === 'available') {
|
|
135
|
+
lines.push(` ${duplication.percentage}% duplicated lines, ${duplication.total} clones`)
|
|
136
|
+
lines.push(...duplication.clones.map((clone) => ` ${clone.lines} lines ${clone.first} = ${clone.second}`))
|
|
137
|
+
} else lines.push(` unavailable: ${duplication.reason}`)
|
|
138
|
+
lines.push('', 'Unused code:')
|
|
139
|
+
const dead = Array.isArray(deadCode) ? deadCode : [deadCode]
|
|
140
|
+
if (!dead.length) lines.push(' no supported language detected')
|
|
141
|
+
for (const section of dead) {
|
|
142
|
+
if (section.status !== 'available') {
|
|
143
|
+
lines.push(` ${section.tool || 'dead-code'} unavailable: ${section.reason}`)
|
|
144
|
+
continue
|
|
145
|
+
}
|
|
146
|
+
lines.push(` ${section.tool}:`, ...section.lines.map((line) => ` ${line}`))
|
|
147
|
+
if (section.omitted) lines.push(` ... ${section.omitted} more lines`)
|
|
148
|
+
}
|
|
149
|
+
lines.push('', 'These are candidates. Verify usage and intent before reporting any of them as a finding.')
|
|
150
|
+
return lines.join('\n')
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function main() {
|
|
154
|
+
const args = process.argv.slice(2)
|
|
155
|
+
const json = args.includes('--json')
|
|
156
|
+
const rootArgument = args.find((arg) => !arg.startsWith('--'))
|
|
157
|
+
try {
|
|
158
|
+
const evidence = collectEvidence(path.resolve(rootArgument || process.cwd()))
|
|
159
|
+
console.log(json ? JSON.stringify(evidence, null, 2) : formatEvidence(evidence))
|
|
160
|
+
} catch (cause) {
|
|
161
|
+
console.error(`audit-evidence: ${cause.message}`)
|
|
162
|
+
process.exitCode = 1
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) main()
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import assert from 'node:assert/strict'
|
|
2
|
+
import { execFileSync, spawnSync } from 'node:child_process'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
import test from 'node:test'
|
|
7
|
+
import { collectEvidence, formatEvidence, summarizeJscpd } from './audit-evidence.mjs'
|
|
8
|
+
|
|
9
|
+
// Every external tool is reported missing; git still runs.
|
|
10
|
+
function withoutTools(command, args, options) {
|
|
11
|
+
if (['where.exe', 'which'].includes(command)) return { status: 1, stdout: '', stderr: '' }
|
|
12
|
+
return spawnSync(command, args, options)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
test('ranks complex functions and reports missing tools as unavailable', (t) => {
|
|
16
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-os-audit-'))
|
|
17
|
+
t.after(() => fs.rmSync(root, { recursive: true, force: true }))
|
|
18
|
+
execFileSync('git', ['init', '-q', root])
|
|
19
|
+
fs.writeFileSync(path.join(root, 'a.js'), 'export const a = 1\n')
|
|
20
|
+
fs.writeFileSync(path.join(root, 'b.py'), 'b = 1\n')
|
|
21
|
+
fs.writeFileSync(path.join(root, 'notes.md'), '# not source\n')
|
|
22
|
+
const analyze = (cwd, files) => files.map((file, index) => ({ file, function: `f${index}`, line: 1, ccn: index + 5, nloc: 1 }))
|
|
23
|
+
|
|
24
|
+
const evidence = collectEvidence(root, { spawn: withoutTools, analyze })
|
|
25
|
+
assert.equal(evidence.sourceFiles, 2)
|
|
26
|
+
assert.deepEqual(evidence.complexity.functions.map((fn) => [fn.file, fn.ccn]), [['b.py', 6], ['a.js', 5]])
|
|
27
|
+
assert.equal(evidence.duplication.status, 'unavailable')
|
|
28
|
+
assert.deepEqual(evidence.deadCode.map((section) => [section.tool, section.status]), [
|
|
29
|
+
['knip', 'unavailable'],
|
|
30
|
+
['vulture', 'unavailable']
|
|
31
|
+
])
|
|
32
|
+
const text = formatEvidence(evidence)
|
|
33
|
+
assert.match(text, /6 {2}b\.py:1 f1/)
|
|
34
|
+
assert.match(text, /These are candidates/)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('summarizes jscpd clones largest first with forward-slash paths', () => {
|
|
38
|
+
const clone = (lines, first, second) => ({
|
|
39
|
+
lines,
|
|
40
|
+
firstFile: { name: first, start: 1, end: lines },
|
|
41
|
+
secondFile: { name: second, start: 10, end: 9 + lines }
|
|
42
|
+
})
|
|
43
|
+
const summary = summarizeJscpd({
|
|
44
|
+
statistics: { total: { percentage: 4.2 } },
|
|
45
|
+
duplicates: [clone(5, 'src\\a.js', 'src\\b.js'), clone(30, 'src/c.js', 'src/d.js')]
|
|
46
|
+
})
|
|
47
|
+
assert.equal(summary.percentage, 4.2)
|
|
48
|
+
assert.deepEqual(summary.clones.map((entry) => [entry.lines, entry.first]), [[30, 'src/c.js:1-30'], [5, 'src/a.js:1-5']])
|
|
49
|
+
})
|
package/policy.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
# Agent OS
|
|
1
|
+
# Agent OS global policy
|
|
2
2
|
|
|
3
3
|
Source of truth for the managed policy block installed into `~/.claude/CLAUDE.md` and
|
|
4
|
-
`~/.codex/AGENTS.md` by `init-agent-os global`. Edit here, never inside the
|
|
4
|
+
`~/.codex/AGENTS.md` by the installer and `init-agent-os global`. Edit here, never inside the
|
|
5
|
+
installed blocks. Everything above `## Development workflows` is the core policy; the installer adds
|
|
6
|
+
that section only when `agent-os-dev` is installed.
|
|
5
7
|
|
|
6
8
|
## Core policy
|
|
7
9
|
|
|
@@ -22,43 +24,68 @@ Rules:
|
|
|
22
24
|
- Keep scope and diffs narrow; when work drifts beyond the task, flag it instead of building on.
|
|
23
25
|
- Escalate only product decisions that cannot be resolved from context and would materially change
|
|
24
26
|
the outcome. Make reversible implementation choices and report them.
|
|
25
|
-
- Use the Git identity configured by the repository or current session. Never add AI attribution or `Co-Authored-By` trailers.
|
|
26
27
|
- Respond in the language used by the user. Code, commits, and technical artifacts are English unless the project says otherwise.
|
|
27
28
|
- Lead with the outcome: the first sentence answers "what happened" or "what did you find". Supporting detail comes after.
|
|
28
29
|
- Readable beats brief: shorten by leaving out what does not change the reader's next step, not by compressing language. Full sentences; no arrow chains, fragment style, or invented shorthand the reader must decode.
|
|
29
|
-
-
|
|
30
|
+
- Plain voice in every reply and every text you write: each sentence carries a fact, an instruction,
|
|
31
|
+
or a number. Cut claims with no source or mechanism, promotional adjectives, filler openers,
|
|
32
|
+
restated questions, stacked hedges, abstract metaphors in place of the concrete noun, structure
|
|
33
|
+
forced onto the content (ideas in threes, "not just X but Y", bold labels that repeat their line),
|
|
34
|
+
and closing offers of help. State a claim that stays unverified after checking once, plainly. No
|
|
35
|
+
dashes in running text. Established technical terms stay in English in any language. Never rewrite
|
|
36
|
+
code, identifiers, structured data, quoted source material, or the user's own prose unless asked.
|
|
37
|
+
The `plain-voice` skill holds the full checklist for documentation, commits, and pull request text.
|
|
38
|
+
- Never force the reader to cross-reference labels or numbering invented earlier in the text; say what you mean in place.
|
|
30
39
|
- Explanations belong in prose; tables only for short enumerable facts.
|
|
31
40
|
- Calibrate tone to the topic: playfulness is fine, neutral and factual the moment the subject is serious. When in doubt, it is serious.
|
|
32
|
-
- Orchestration is opt-in:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
41
|
+
- Orchestration is opt-in: manual agent-os skills run only when the person invokes them by the name
|
|
42
|
+
the host exposes (`/plan-work`, `/agent-os-core:plan-work`, or `$plan-work`). Never self-invoke one.
|
|
43
|
+
When a request clearly matches a manual skill the person did not name, suggest it once in one
|
|
44
|
+
sentence with its invocation and why it fits, then do what was asked. Planning alone never starts
|
|
45
|
+
implementation.
|
|
46
|
+
- End every agent-os workflow with a route line: the kind of work, the steps done and left, and the
|
|
47
|
+
exact command that resumes it, such as `/deliver-work #42`. Take the route from the project's
|
|
48
|
+
`.agent-os/workflow.md` when the project policy points to one, else from a default path the policy
|
|
49
|
+
states, else from the default routes; with agent-os-core alone, name the next installed step. Then
|
|
50
|
+
follow the `Next step:` line in the person's `## My working preferences`: `ask`, the default, asks
|
|
51
|
+
once whether to start the next step; `continue` starts the next planning step, including the
|
|
52
|
+
issues `shape-work` creates, and asks before delivery; `recommend` only recommends. Never skip a
|
|
53
|
+
step, decide an open product question, merge, or deploy on that basis.
|
|
54
|
+
- Recommend one concrete next action with its reason and any blocker. Authority persists across unit
|
|
55
|
+
boundaries but never expands to unrelated backlog work; when nothing useful remains, say so.
|
|
56
|
+
- Sort discoveries with `scope-guard`: required work the mandate covers stays in scope, adjacent work
|
|
57
|
+
is a follow-up, unrelated work gets no proposal, and risk never grants permission by itself.
|
|
58
|
+
- Tracker writes need a tracker mandate in the request or the project policy's `## Tracker mandate`,
|
|
59
|
+
except the new issues an invoked `shape-work` creates. A mandate never covers acceptance, owners,
|
|
60
|
+
new deliveries, or closure. Without one, keep corrections local and report the unsynced delta.
|
|
61
|
+
- Only an initiative, work that several pull requests deliver and whose product decisions someone
|
|
62
|
+
other than the requester must agree to, or work the person or project policy asks files for, gets
|
|
63
|
+
`intents/<id>/intent.md` and `spec.md`. Other work lives in tracker issues and pull requests. Those
|
|
64
|
+
files change only through review, and one whose `built_on` revision is older than its source is
|
|
65
|
+
stale until it is reconsidered.
|
|
57
66
|
|
|
58
|
-
## Preferences (seed defaults
|
|
67
|
+
## Preferences (seed defaults; project policy overrides)
|
|
59
68
|
|
|
60
69
|
- UI feedback under ~250 ms; feedback must not block the next interaction.
|
|
61
70
|
- Own design identity; do not imitate the look of well-known apps.
|
|
62
71
|
- Every repo keeps a living project policy (planning surface, design system location, verify
|
|
63
72
|
commands, conventions, gotchas, and delivery defaults). It grows over time; `init-agent-os`
|
|
64
73
|
seeds it and `record-lesson` grows it.
|
|
74
|
+
|
|
75
|
+
## Development workflows
|
|
76
|
+
|
|
77
|
+
- Use the Git identity configured by the repository or current session. Never add AI attribution or `Co-Authored-By` trailers.
|
|
78
|
+
- The development skills are manual too. Authority may continue into the workflow a skill's exit
|
|
79
|
+
contract names. A request that covers a bounded set of shaped units, or finishing an intent, covers
|
|
80
|
+
delivering them one at a time; parallel batch execution needs explicit selection. `check-work` may
|
|
81
|
+
start from an implicit review request; its report mode is read-only and its fix mode needs explicit
|
|
82
|
+
authority.
|
|
83
|
+
- Default routes: a bug with a known fix, `shape-work` for one issue and then `deliver-work`; a small
|
|
84
|
+
change or a bug whose fix holds a choice, `plan-work`, `shape-work`, and `deliver-work`; a feature,
|
|
85
|
+
the same with `plan-work` only when something is unclear; an initiative, every step and the
|
|
86
|
+
project's finishing tasks. Each route gives the work an issue unless the request skips it, and
|
|
87
|
+
routes guide only agent-os workflows: a request made without one is done as asked.
|
|
88
|
+
- Delivery status is never written into `plan.md`: a draft pull request claims a unit, by its
|
|
89
|
+
`Intent-Unit: <intent-id>/<unit-key>` line or by linking its issue, and its merge delivers it.
|
|
90
|
+
- Agent OS hooks read `.agent-os/guards.json`. A hook block is a boundary, not an obstacle: change
|
|
91
|
+
course or ask, and never work around it by another tool or path.
|
package/hooks/hooks.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"description": "Agent OS quality-ratchet lifecycle hook.",
|
|
3
|
-
"hooks": {
|
|
4
|
-
"Stop": [
|
|
5
|
-
{
|
|
6
|
-
"hooks": [
|
|
7
|
-
{
|
|
8
|
-
"type": "command",
|
|
9
|
-
"command": "node \"${CLAUDE_PLUGIN_ROOT}/skills/quality-ratchet/scripts/quality-delta.mjs\" hook --agent-os-hook=quality-ratchet",
|
|
10
|
-
"commandWindows": "powershell.exe -NoProfile -NonInteractive -EncodedCommand JAByAHUAbgBuAGUAcgAgAD0AIABKAG8AaQBuAC0AUABhAHQAaAAgACQAZQBuAHYAOgBQAEwAVQBHAEkATgBfAFIATwBPAFQAIAAnAHMAawBpAGwAbABzAFwAcQB1AGEAbABpAHQAeQAtAHIAYQB0AGMAaABlAHQAXABzAGMAcgBpAHAAdABzAFwAcQB1AGEAbABpAHQAeQAtAGQAZQBsAHQAYQAuAG0AagBzACcAOwAgAG4AbwBkAGUAIAAkAHIAdQBuAG4AZQByACAAaABvAG8AawAgAC0ALQBhAGcAZQBuAHQALQBvAHMALQBoAG8AbwBrAD0AcQB1AGEAbABpAHQAeQAtAHIAYQB0AGMAaABlAHQA",
|
|
11
|
-
"timeout": 10
|
|
12
|
-
}
|
|
13
|
-
]
|
|
14
|
-
}
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: deliver-work
|
|
3
|
-
description: Delivers one decision-ready change against explicit boundaries and ground truth. User-invoked for implementation, including as a batch worker. Not for exploration or specification-only work.
|
|
4
|
-
disable-model-invocation: true
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Deliver work
|
|
8
|
-
|
|
9
|
-
Read [workflow.md](workflow.md), then execute its contract. The invocation grants authority to change
|
|
10
|
-
repository files inside the requested scope. It does not grant authority to choose unresolved product
|
|
11
|
-
behavior or to merge, deploy, perform destructive cleanup, or affect external systems unless the
|
|
12
|
-
request or project policy includes those actions.
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: diagnose-before-fix
|
|
3
|
-
description: Finds the root cause of reproducible technical failures before code is changed. It activates when investigating a bug, regression, failing test, crash, or unexpected behavior whose cause is not yet established, before proposing or applying a fix. It skips known-cause mechanical edits, feature implementation, general review, and post-fix verification.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Diagnose before fix
|
|
7
|
-
|
|
8
|
-
Find the smallest supported explanation that accounts for the failure and predicts a useful check.
|
|
9
|
-
|
|
10
|
-
## Contract
|
|
11
|
-
|
|
12
|
-
- **Ground truth:** the narrowest reliable reproduction or observed failure.
|
|
13
|
-
- **Working surface:** tests, diagnostics, logs, and instrumentation inside the task scope.
|
|
14
|
-
- **Boundary:** do not commit a production fix whose causal story is still guesswork.
|
|
15
|
-
|
|
16
|
-
## Loop
|
|
17
|
-
|
|
18
|
-
Reproduce, reduce, trace the nearest seam, and compare plausible causes with high-information checks.
|
|
19
|
-
Use temporary instrumentation when it helps. Once evidence supports a cause, implement the smallest
|
|
20
|
-
fix and add a regression check when practical. Re-run the original failing path.
|
|
21
|
-
|
|
22
|
-
If the failure cannot be reproduced or competing explanations cannot be distinguished, report the
|
|
23
|
-
bounded uncertainty and the next discriminating check. Do not turn a plausible hypothesis into a
|
|
24
|
-
confirmed diagnosis.
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: explain-work
|
|
3
|
-
description: Explains the current task or plan in plain language with no technical vocabulary, so the developer can judge it beyond the jargon. User-invoked directly when a real decision needs a plain-language summary or as a plan-work aid. Not a substitute for technical review or verification.
|
|
4
|
-
disable-model-invocation: true
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Explain work
|
|
8
|
-
|
|
9
|
-
Say what the work solves as if the reader knows no technical terms — then let the developer judge
|
|
10
|
-
it.
|
|
11
|
-
|
|
12
|
-
## The summary
|
|
13
|
-
|
|
14
|
-
Cover, in everyday language: the problem it solves, who feels that problem, what changes in their
|
|
15
|
-
day when it works, and what it deliberately will not do. No technical vocabulary at all — if the
|
|
16
|
-
summary cannot stand without a technical term, the understanding is not finished; go back and
|
|
17
|
-
understand before explaining. Keep it short enough to read in under a minute: a TLDR, not a report.
|
|
18
|
-
|
|
19
|
-
## The gate
|
|
20
|
-
|
|
21
|
-
Present the summary when it is needed for an actual decision and let the developer approve or
|
|
22
|
-
challenge it. A challenge means the understanding was wrong somewhere: name what was misunderstood
|
|
23
|
-
and reopen the questioning or the plan at that point rather than defending the summary. Under
|
|
24
|
-
plan-work, the summary may be linked from the canonical planning artifact; it is not a general
|
|
25
|
-
workflow gate.
|
|
26
|
-
|
|
27
|
-
Standalone, explain-work can run against any plan, diff, or pull request; the deliverable is the
|
|
28
|
-
plain-language summary itself and the developer's verdict on it.
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: init-agent-os
|
|
3
|
-
description: Sets up agent-os globally on a machine, or initializes a repo's living project policy through an interview. User-invoked only, at machine setup or when onboarding a repo. Not for ordinary tasks.
|
|
4
|
-
disable-model-invocation: true
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# init-agent-os
|
|
8
|
-
|
|
9
|
-
The invocation authorizes setup writes for the named target. Use one mode per run.
|
|
10
|
-
|
|
11
|
-
## Mode: `global` (once per machine)
|
|
12
|
-
|
|
13
|
-
Invoked as `init-agent-os global`.
|
|
14
|
-
|
|
15
|
-
1. Verify the plugin is visible on this platform (skills listed under the `agent-os` namespace). Report what you find.
|
|
16
|
-
2. Run `scripts/policy-block.ps1 -Check` and report drift between `policy.md` and the managed blocks in `~/.claude/CLAUDE.md` and `~/.codex/AGENTS.md`.
|
|
17
|
-
3. Run `scripts/policy-block.ps1` to apply the managed blocks and show the resulting diff. This
|
|
18
|
-
deterministic writer shares its marker contract with the npm installer's policy writer.
|
|
19
|
-
|
|
20
|
-
## Mode: repo init (default)
|
|
21
|
-
|
|
22
|
-
Invoked in a repo working directory. Read [repository-init.md](references/repository-init.md)
|
|
23
|
-
for the detailed contract.
|
|
24
|
-
|
|
25
|
-
1. Inspect broadly before asking: instruction and policy surfaces, README and docs, package/build
|
|
26
|
-
files, test and CI configuration, and evidence of conditional areas. Before writing, every live
|
|
27
|
-
host-consumed policy surface must have unambiguous ownership and precedence. Shared identical
|
|
28
|
-
content or a clear canonical cross-reference is sufficient; do not select one file while
|
|
29
|
-
conflicting applicable rules remain elsewhere. If target ownership cannot be resolved, ask one
|
|
30
|
-
ownership question and block the write.
|
|
31
|
-
2. Maintain a transient completeness ledger while working. Every applicable material field ends as
|
|
32
|
-
repository-evidenced or confirmed, `N/A`, explicitly deferred/open, or conflicting. Do not
|
|
33
|
-
guess through a conflict, and do not write the ledger or interview history to the policy.
|
|
34
|
-
3. Before writing, each mandatory core field must reach one allowed terminal state: repository-
|
|
35
|
-
evidenced or confirmed, `N/A`, explicitly deferred/open, or conflicting. The core covers policy
|
|
36
|
-
ownership and canonical instruction surface; delivery boundary, stopping point, and external
|
|
37
|
-
effects; verification and ground truth, including when commands are insufficient; coherent
|
|
38
|
-
planning identities, claims, handoffs, readiness, epic ownership, and dependencies; and
|
|
39
|
-
maintenance of durable lessons and gotchas. Only
|
|
40
|
-
an unresolved policy ownership/write-target conflict blocks writing; other explicit deferrals
|
|
41
|
-
may be written concisely under **Open setup questions**.
|
|
42
|
-
4. Activate only conditional modules supported by repository evidence: frontend/design/rendered QA;
|
|
43
|
-
package/release/docs; CI/deploy; auth/security/billing/external writes; database/migration/
|
|
44
|
-
concurrency; batch/monorepo; and native/desktop. Omit inactive modules from the output.
|
|
45
|
-
5. Ask only unresolved material questions, one at a time, with a recommendation and consequence.
|
|
46
|
-
Explicit deferral is an answer: record it under **Open setup questions** without inventing a
|
|
47
|
-
default. Do not ask feature-specific outcome, acceptance, or UI-product questions.
|
|
48
|
-
6. Write only durable behavior-changing defaults and relevant sections to the resolved existing
|
|
49
|
-
instruction surface, or a new `policy.md` when none exists. Preserve unrelated instructions,
|
|
50
|
-
show the resulting diff, and do not request a second approval for this setup write.
|
|
51
|
-
|
|
52
|
-
Block handling remains deterministic: add one missing block, update only well-formed managed content,
|
|
53
|
-
and stop on duplicate or malformed markers. Global mode touches no repository files; repo mode
|
|
54
|
-
touches one repository. The direct request or recorded delivery defaults govern merge and deploy
|
|
55
|
-
actions.
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# Repository initialization contract
|
|
2
|
-
|
|
3
|
-
Repository mode is a facts-first onboarding pass, not a fixed questionnaire. Inspect the
|
|
4
|
-
repository and conversation, then use an internal transient ledger to make omissions visible while
|
|
5
|
-
keeping the written policy small.
|
|
6
|
-
|
|
7
|
-
## Inspect and choose ownership
|
|
8
|
-
|
|
9
|
-
Read broadly enough to find the current source of truth: every applicable `AGENTS.md`, `CLAUDE.md`,
|
|
10
|
-
and `policy.md` in scope; README and project docs; package/build/test configuration; CI and release
|
|
11
|
-
configuration; and evidence of frontend, deployment, security, data, batch, or native work. Do not
|
|
12
|
-
ask for a fact already established by those sources or by the current conversation.
|
|
13
|
-
|
|
14
|
-
Before writing, inventory every live host-consumed policy surface and give each unambiguous ownership
|
|
15
|
-
and precedence. Shared identical content or a clear canonical cross-reference is sufficient; do not
|
|
16
|
-
mandate duplication. Selecting one file while leaving conflicting applicable rules elsewhere is
|
|
17
|
-
forbidden. If ownership or the write target cannot be resolved, ask one ownership question and block
|
|
18
|
-
the write. A clean repository with no policy surface may receive a new `policy.md`; otherwise update
|
|
19
|
-
the resolved canonical surface and preserve unrelated content.
|
|
20
|
-
|
|
21
|
-
## Completeness ledger
|
|
22
|
-
|
|
23
|
-
The ledger is internal and transient. For every material field, record one terminal state:
|
|
24
|
-
|
|
25
|
-
- **evidenced/confirmed** — supported by repository evidence or the user's answer;
|
|
26
|
-
- **N/A** — repository evidence makes the field inapplicable;
|
|
27
|
-
- **deferred/open** — the user explicitly defers it, to be listed under `Open setup questions`;
|
|
28
|
-
- **conflicting** — sources or answers disagree and must be resolved before a default is chosen.
|
|
29
|
-
|
|
30
|
-
Never treat silence as confirmation. Do not write `N/A`, interview history, or the full ledger to the
|
|
31
|
-
policy. Before writing, each core field must reach one of the four terminal states above. Only an
|
|
32
|
-
unresolved policy ownership/write-target conflict blocks writing; other explicitly deferred fields
|
|
33
|
-
may be written concisely under `Open setup questions`. A conflict is not permission to guess through
|
|
34
|
-
the conflict; keep an unresolved conflict visible under `Open setup questions` until it is resolved.
|
|
35
|
-
|
|
36
|
-
## Required core
|
|
37
|
-
|
|
38
|
-
Bring each of these fields to one allowed terminal state before the write, asking only where evidence
|
|
39
|
-
is insufficient:
|
|
40
|
-
|
|
41
|
-
1. **Ownership:** the canonical instruction surface and how overlapping policy files are governed.
|
|
42
|
-
2. **Delivery boundary:** the default stopping point, branch/PR/merge/deploy expectations, and
|
|
43
|
-
whether external writes, publication, or other effects require a separate explicit request.
|
|
44
|
-
3. **Verification:** exact useful commands and the ground truth they establish; record what must be
|
|
45
|
-
inspected manually or otherwise checked when commands are insufficient.
|
|
46
|
-
4. **Planning:** the coherent planning surface, stable plan and decision-ticket identities, claims
|
|
47
|
-
and handoff conventions, readiness states or labels, epic ownership, and dependency conventions
|
|
48
|
-
for implementation work.
|
|
49
|
-
5. **Maintenance:** where durable lessons, recurring gotchas, and policy changes are recorded.
|
|
50
|
-
|
|
51
|
-
## Evidence-gated modules
|
|
52
|
-
|
|
53
|
-
Add a module only when inspection finds the corresponding concern. Resolve its material defaults and
|
|
54
|
-
omit it entirely when inactive:
|
|
55
|
-
|
|
56
|
-
- frontend/design/rendered QA;
|
|
57
|
-
- package, release, or documentation publication;
|
|
58
|
-
- CI or deployment;
|
|
59
|
-
- authentication, security, billing, or external writes;
|
|
60
|
-
- database, migrations, or concurrency;
|
|
61
|
-
- batch execution or a monorepo;
|
|
62
|
-
- native or desktop tooling.
|
|
63
|
-
|
|
64
|
-
When a module is active but a decision is not yet safe to infer, ask one question at a time. Each
|
|
65
|
-
question includes the recommended option and the consequence of choosing differently. Explicitly
|
|
66
|
-
deferred answers are written only as concise `Open setup questions`; they do not become guessed
|
|
67
|
-
defaults. They do not block the write unless the deferral leaves policy ownership or the write target
|
|
68
|
-
unresolved.
|
|
69
|
-
|
|
70
|
-
## Write contract
|
|
71
|
-
|
|
72
|
-
Write only durable behavior-changing defaults and relevant active sections. Keep the policy sparse:
|
|
73
|
-
do not add a schema, checklist, or interview transcript. Preserve existing unrelated instructions.
|
|
74
|
-
The explicit `init-agent-os` invocation authorizes this setup write, so do not ask for a second
|
|
75
|
-
approval. Show the resulting diff.
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
# Manages the AGENT OS block in global instruction files.
|
|
2
|
-
# Source of truth: policy.md at the plugin root (two levels up from this script).
|
|
3
|
-
#
|
|
4
|
-
# Semantics (locked in the agent-os plan, M3):
|
|
5
|
-
# - No block in target -> append exactly one block, preserve everything else.
|
|
6
|
-
# - Empty target file -> treated as "no block"; the block becomes the whole file.
|
|
7
|
-
# - Exactly one well-formed -> replace only the content between the markers.
|
|
8
|
-
# - Duplicated, crossed, or half-open markers -> abort without mutation, exit 2.
|
|
9
|
-
# - -Check -> read-only; exit 0 in sync, exit 1 on drift/missing, never writes.
|
|
10
|
-
# - Text outside the block is never touched or normalized.
|
|
11
|
-
|
|
12
|
-
[CmdletBinding()]
|
|
13
|
-
param(
|
|
14
|
-
[switch]$Check,
|
|
15
|
-
[string[]]$Targets = @(
|
|
16
|
-
(Join-Path (Join-Path $HOME '.claude') 'CLAUDE.md'),
|
|
17
|
-
(Join-Path (Join-Path $HOME '.codex') 'AGENTS.md')
|
|
18
|
-
)
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
$ErrorActionPreference = 'Stop'
|
|
22
|
-
$BeginMarker = '<!-- BEGIN AGENT OS -->'
|
|
23
|
-
$EndMarker = '<!-- END AGENT OS -->'
|
|
24
|
-
|
|
25
|
-
$policyPath = Join-Path $PSScriptRoot '..\..\..\policy.md' | Resolve-Path
|
|
26
|
-
$policy = (Get-Content -Raw -Path $policyPath).TrimEnd()
|
|
27
|
-
$block = "$BeginMarker`n$policy`n$EndMarker"
|
|
28
|
-
|
|
29
|
-
$exit = 0
|
|
30
|
-
|
|
31
|
-
foreach ($target in $Targets) {
|
|
32
|
-
$label = $target
|
|
33
|
-
if (-not (Test-Path $target)) {
|
|
34
|
-
if ($Check) {
|
|
35
|
-
Write-Output "DRIFT $label : file missing"
|
|
36
|
-
$exit = 1
|
|
37
|
-
} else {
|
|
38
|
-
$dir = Split-Path $target
|
|
39
|
-
if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Force -Path $dir | Out-Null }
|
|
40
|
-
Set-Content -NoNewline -Path $target -Value ($block + "`n")
|
|
41
|
-
Write-Output "ADDED $label : created file with managed block"
|
|
42
|
-
}
|
|
43
|
-
continue
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
# An empty file returns $null from -Raw, which would throw in Matches below.
|
|
47
|
-
$content = Get-Content -Raw -Path $target
|
|
48
|
-
if ($null -eq $content) { $content = '' }
|
|
49
|
-
$beginCount = ([regex]::Matches($content, [regex]::Escape($BeginMarker))).Count
|
|
50
|
-
$endCount = ([regex]::Matches($content, [regex]::Escape($EndMarker))).Count
|
|
51
|
-
|
|
52
|
-
if ($beginCount -eq 0 -and $endCount -eq 0) {
|
|
53
|
-
if ($Check) {
|
|
54
|
-
Write-Output "DRIFT $label : managed block missing"
|
|
55
|
-
$exit = 1
|
|
56
|
-
} else {
|
|
57
|
-
$sep = if ($content.Length -eq 0) { '' } elseif ($content.EndsWith("`n")) { "`n" } else { "`n`n" }
|
|
58
|
-
Set-Content -NoNewline -Path $target -Value ($content + $sep + $block + "`n")
|
|
59
|
-
Write-Output "ADDED $label : appended managed block"
|
|
60
|
-
}
|
|
61
|
-
continue
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
$wellFormed = ($beginCount -eq 1 -and $endCount -eq 1 -and
|
|
65
|
-
$content.IndexOf($BeginMarker) -lt $content.IndexOf($EndMarker))
|
|
66
|
-
if (-not $wellFormed) {
|
|
67
|
-
Write-Output "ERROR $label : malformed markers (begin=$beginCount end=$endCount) - no mutation"
|
|
68
|
-
exit 2
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
$start = $content.IndexOf($BeginMarker)
|
|
72
|
-
$end = $content.IndexOf($EndMarker) + $EndMarker.Length
|
|
73
|
-
$current = $content.Substring($start, $end - $start)
|
|
74
|
-
|
|
75
|
-
if ($current -eq $block) {
|
|
76
|
-
Write-Output "OK $label : in sync"
|
|
77
|
-
} elseif ($Check) {
|
|
78
|
-
Write-Output "DRIFT $label : block differs from policy.md"
|
|
79
|
-
$exit = 1
|
|
80
|
-
} else {
|
|
81
|
-
$updated = $content.Substring(0, $start) + $block + $content.Substring($end)
|
|
82
|
-
Set-Content -NoNewline -Path $target -Value $updated
|
|
83
|
-
Write-Output "UPDATED $label : block replaced from policy.md"
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
exit $exit
|