polydeukes 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ko.md +54 -74
- package/README.md +55 -86
- package/dist/baseline.d.ts +82 -0
- package/dist/baseline.js +166 -0
- package/dist/bin.d.ts +1 -1
- package/dist/bin.js +26 -6
- package/dist/claude-code-hook.d.ts +7 -5
- package/dist/claude-code-hook.js +69 -17
- package/dist/claude-code.d.ts +6 -0
- package/dist/claude-code.js +6 -0
- package/dist/covenant-check.d.ts +10 -17
- package/dist/covenant-check.js +44 -12
- package/dist/covenant-module.d.ts +2 -2
- package/dist/covenant-module.js +9 -1
- package/dist/docs/README.ko.md +60 -0
- package/dist/docs/README.md +64 -0
- package/dist/docs/catalog.json +464 -0
- package/dist/docs/concepts/judgment.ko.md +113 -0
- package/dist/docs/concepts/judgment.md +113 -0
- package/dist/docs/how-to/configure-project.ko.md +99 -0
- package/dist/docs/how-to/configure-project.md +95 -0
- package/dist/docs/how-to/connect-surfaces.ko.md +115 -0
- package/dist/docs/how-to/connect-surfaces.md +118 -0
- package/dist/docs/how-to/write-disciplines.ko.md +124 -0
- package/dist/docs/how-to/write-disciplines.md +125 -0
- package/dist/docs/index.json +2046 -0
- package/dist/docs/reference/cli/covenant-check.ko.md +101 -0
- package/dist/docs/reference/cli/covenant-check.md +98 -0
- package/dist/docs/reference/cli/docs.ko.md +97 -0
- package/dist/docs/reference/cli/docs.md +95 -0
- package/dist/docs/reference/cli/explain.ko.md +79 -0
- package/dist/docs/reference/cli/explain.md +84 -0
- package/dist/docs/reference/cli/init.ko.md +119 -0
- package/dist/docs/reference/cli/init.md +131 -0
- package/dist/docs/reference/configuration/index.ko.md +448 -0
- package/dist/docs/reference/configuration/index.md +474 -0
- package/dist/docs/reference/packages/adapter-claude-code.ko.md +83 -0
- package/dist/docs/reference/{adapter-claude-code.md → packages/adapter-claude-code.md} +16 -10
- package/dist/docs/reference/packages/adapter-git.ko.md +101 -0
- package/dist/docs/reference/{adapter-git.md → packages/adapter-git.md} +25 -15
- package/dist/docs/reference/packages/core.ko.md +128 -0
- package/dist/docs/reference/{core.md → packages/core.md} +32 -13
- package/dist/docs/reference/packages/covenant.ko.md +115 -0
- package/dist/docs/reference/{covenant.md → packages/covenant.md} +41 -26
- package/dist/docs/reference/packages/polydeukes.ko.md +134 -0
- package/dist/docs/reference/packages/polydeukes.md +139 -0
- package/dist/docs/troubleshooting.ko.md +142 -0
- package/dist/docs/troubleshooting.md +97 -122
- package/dist/docs/tutorials/first-judgment.ko.md +82 -0
- package/dist/docs/tutorials/first-judgment.md +81 -0
- package/dist/docs-catalog.d.ts +25 -0
- package/dist/docs-catalog.js +450 -0
- package/dist/docs-library.d.ts +23 -0
- package/dist/docs-library.js +347 -0
- package/dist/docs-markdown.d.ts +32 -0
- package/dist/docs-markdown.js +150 -0
- package/dist/docs-query.d.ts +11 -40
- package/dist/docs-query.js +28 -122
- package/dist/docs-types.d.ts +105 -0
- package/dist/docs-types.js +2 -0
- package/dist/explain.d.ts +3 -5
- package/dist/explain.js +48 -47
- package/dist/index.d.ts +2 -3
- package/dist/index.js +1 -2
- package/dist/init-claude-code.d.ts +5 -3
- package/dist/init-claude-code.js +226 -63
- package/dist/init-grok.d.ts +51 -0
- package/dist/init-grok.js +242 -0
- package/dist/load-config.d.ts +5 -1
- package/dist/load-config.js +2 -1
- package/dist/pre-state-reader.d.ts +22 -0
- package/dist/pre-state-reader.js +32 -0
- package/dist/scaffold-project.js +48 -8
- package/dist/schema/polydeukes.schema.json +38 -91
- package/package.json +7 -7
- package/dist/docs/configuration.md +0 -103
- package/dist/docs/installation.md +0 -212
- package/dist/docs/reference/configuration.md +0 -338
- package/dist/docs/reference/polydeukes.md +0 -287
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `initGrok` — the Grok session-surface installer.
|
|
3
|
+
*
|
|
4
|
+
* Preflight first, then the shared project-side scaffold, then the generated hook and the
|
|
5
|
+
* `.grok/hooks` JSON registration. When a Claude delegator is already on disk, the JSON
|
|
6
|
+
* command names that file instead of planting a second one — two command strings would
|
|
7
|
+
* spawn two judges per call.
|
|
8
|
+
*
|
|
9
|
+
* Nothing existing is overwritten, with one command-field exception: a grok JSON whose
|
|
10
|
+
* `command` is still the grok-mjs string is rewritten to the Claude-hook command when that
|
|
11
|
+
* Claude file is on disk — otherwise grok-then-claude leaves two command strings. Any entry
|
|
12
|
+
* naming the Claude-hook command also takes the matcher of the `.claude/settings.json` entry
|
|
13
|
+
* carrying that command, because the host collapses the two registrations only when command
|
|
14
|
+
* and matcher are byte-identical; with no such entry the matcher stays. Timeout stays either
|
|
15
|
+
* way, and a command that is not the grok-mjs string is left byte-identical.
|
|
16
|
+
*
|
|
17
|
+
* Rules and skills are not copied; `.claude/settings.json` is not written.
|
|
18
|
+
*/
|
|
19
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
20
|
+
import { findPackageJSON } from 'node:module';
|
|
21
|
+
import { dirname, join } from 'node:path';
|
|
22
|
+
import { isPlainObject } from '@polydeukes/core';
|
|
23
|
+
import { scaffoldProject } from './scaffold-project.js';
|
|
24
|
+
/** The published entry point the generated hook loads the judge through. */
|
|
25
|
+
const HOOK_SPECIFIER = 'polydeukes/claude-code';
|
|
26
|
+
/** The registration artifacts, as `projectRoot`-relative paths (the report vocabulary). */
|
|
27
|
+
const GROK_HOOK_RELATIVE = '.grok/hooks/covenant-pretooluse.mjs';
|
|
28
|
+
const GROK_JSON_RELATIVE = '.grok/hooks/covenant-pretooluse.json';
|
|
29
|
+
/** The Claude delegator this installer reuses when it is already on disk. */
|
|
30
|
+
const CLAUDE_HOOK_RELATIVE = '.claude/hooks/covenant-pretooluse.mjs';
|
|
31
|
+
/** Where that delegator's own registration — and the matcher it was registered under — lives. */
|
|
32
|
+
const CLAUDE_SETTINGS_RELATIVE = '.claude/settings.json';
|
|
33
|
+
const GROK_HOOK_COMMAND = `node "$CLAUDE_PROJECT_DIR"/${GROK_HOOK_RELATIVE}`;
|
|
34
|
+
const CLAUDE_HOOK_COMMAND = `node "$CLAUDE_PROJECT_DIR"/${CLAUDE_HOOK_RELATIVE}`;
|
|
35
|
+
/**
|
|
36
|
+
* Which calls reach the judge — Grok's mutating+shell roster plus the Claude aliases a
|
|
37
|
+
* host without Grok's alias table still sends.
|
|
38
|
+
*/
|
|
39
|
+
const HOOK_MATCHER = 'write|search_replace|run_terminal_command|Edit|Write|MultiEdit|NotebookEdit|Bash';
|
|
40
|
+
/**
|
|
41
|
+
* The generated hook. It carries no assembly at all, so upgrading the package upgrades the
|
|
42
|
+
* judge without regenerating this file. Same text as the Claude installer besides the
|
|
43
|
+
* header: the session subpath, `repoRoot` from this file's location, and `process.exitCode`
|
|
44
|
+
* rather than `process.exit`.
|
|
45
|
+
*/
|
|
46
|
+
const GENERATED_HOOK = `#!/usr/bin/env node
|
|
47
|
+
/**
|
|
48
|
+
* Polydeukes PreToolUse covenant hook — generated by \`pdks init grok\`.
|
|
49
|
+
*
|
|
50
|
+
* A delegator and nothing more: the judgment assembly lives in the \`polydeukes\` package as
|
|
51
|
+
* \`runClaudeCodeHook\`, reached here through its session subpath. The package barrel would
|
|
52
|
+
* work too and is the wrong door — its re-exports are eager, so every session call would
|
|
53
|
+
* load the commit surface and its git adapter alongside the judge it actually needs.
|
|
54
|
+
*
|
|
55
|
+
* \`repoRoot\` comes from this file's own location, never from the working directory. A hook
|
|
56
|
+
* is spawned with whatever directory the agent happened to hold, and what config discovery
|
|
57
|
+
* and the protection list need is the project that CONTAINS this hook — always \`../..\`
|
|
58
|
+
* from here.
|
|
59
|
+
*
|
|
60
|
+
* fail-closed: \`runClaudeCodeHook\` translates every failure it can reach into exit 2 with
|
|
61
|
+
* one blocked record. This catch answers only for what it cannot reach — the package failing
|
|
62
|
+
* to resolve or load at all (never installed, or installed without a build) — where no
|
|
63
|
+
* telemetry writer exists yet. Recovery is installing the package again.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
import { dirname, join } from 'node:path';
|
|
67
|
+
import { fileURLToPath } from 'node:url';
|
|
68
|
+
|
|
69
|
+
const repoRoot = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
|
|
70
|
+
|
|
71
|
+
try {
|
|
72
|
+
const { runClaudeCodeHook } = await import('${HOOK_SPECIFIER}');
|
|
73
|
+
const { exitCode } = await runClaudeCodeHook({ repoRoot });
|
|
74
|
+
// Assign and let the process end naturally instead of process.exit(): an explicit exit
|
|
75
|
+
// can preempt a buffered stderr write on platforms with async pipes, dropping the break
|
|
76
|
+
// reason the agent needs to read.
|
|
77
|
+
process.exitCode = exitCode;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error(\`covenant hook failed closed: \${error?.message ?? error}\`);
|
|
80
|
+
process.exitCode = 2;
|
|
81
|
+
}
|
|
82
|
+
`;
|
|
83
|
+
/**
|
|
84
|
+
* The default preflight: is `polydeukes` installed where `projectRoot` can reach it?
|
|
85
|
+
*
|
|
86
|
+
* ESM resolution specifically, because that is what the generated hook's `await import(...)`
|
|
87
|
+
* runs. The generated hook loads `polydeukes/claude-code`, so that is the subpath this
|
|
88
|
+
* checks — a Grok-named entry point is not added.
|
|
89
|
+
*/
|
|
90
|
+
function resolveFromProjectRoot(projectRoot) {
|
|
91
|
+
const manifestPath = findPackageJSON('polydeukes', join(projectRoot, 'package.json'));
|
|
92
|
+
if (manifestPath === undefined) {
|
|
93
|
+
throw new Error('polydeukes is not installed where this project can reach it');
|
|
94
|
+
}
|
|
95
|
+
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
96
|
+
const subpath = isPlainObject(manifest) && isPlainObject(manifest.exports)
|
|
97
|
+
? manifest.exports[`./${HOOK_SPECIFIER.split('/')[1]}`]
|
|
98
|
+
: undefined;
|
|
99
|
+
const target = isPlainObject(subpath) ? subpath.import : undefined;
|
|
100
|
+
if (typeof target !== 'string' || !existsSync(join(dirname(manifestPath), target))) {
|
|
101
|
+
throw new Error(`the installed polydeukes does not expose '${HOOK_SPECIFIER}' — update or rebuild it`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Write one generated artifact unless it is already there, recording which happened. */
|
|
105
|
+
function writeIfAbsent(projectRoot, relative, contents, report) {
|
|
106
|
+
const path = join(projectRoot, relative);
|
|
107
|
+
if (existsSync(path)) {
|
|
108
|
+
report.skipped.push(relative);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
112
|
+
writeFileSync(path, contents);
|
|
113
|
+
report.created.push(relative);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The matcher `.claude/settings.json` registered `command` under, when it has one. Anything
|
|
117
|
+
* unreadable, unparseable, or shaped otherwise answers `undefined` — the caller then keeps its
|
|
118
|
+
* own roster rather than narrowing the registration to a shape it could not read.
|
|
119
|
+
*/
|
|
120
|
+
function claudeSettingsMatcherFor(projectRoot, command) {
|
|
121
|
+
const path = join(projectRoot, CLAUDE_SETTINGS_RELATIVE);
|
|
122
|
+
if (!existsSync(path)) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
let root;
|
|
126
|
+
try {
|
|
127
|
+
root = JSON.parse(readFileSync(path, 'utf-8'));
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
if (!isPlainObject(root) || !isPlainObject(root.hooks) || !Array.isArray(root.hooks.PreToolUse)) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
for (const entry of root.hooks.PreToolUse) {
|
|
136
|
+
if (!isPlainObject(entry) || !Array.isArray(entry.hooks)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (entry.hooks.some((hook) => isPlainObject(hook) && hook.command === command)) {
|
|
140
|
+
return typeof entry.matcher === 'string' ? entry.matcher : undefined;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
function grokHookJson(command, matcher) {
|
|
146
|
+
return `${JSON.stringify({
|
|
147
|
+
hooks: {
|
|
148
|
+
PreToolUse: [
|
|
149
|
+
{
|
|
150
|
+
matcher,
|
|
151
|
+
hooks: [{ type: 'command', command, timeout: 60 }],
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
}, null, 2)}\n`;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Rewrite the grok JSON `command` from the grok-mjs string to the Claude-hook string.
|
|
159
|
+
*
|
|
160
|
+
* The Claude installer calls this after writing its delegator; this installer calls it on
|
|
161
|
+
* re-run when that file is already on disk. Only the installer-generated grok-mjs command
|
|
162
|
+
* is rewritten; any other string is the consumer's spawn target and the file is not touched.
|
|
163
|
+
* Every entry naming the Claude-hook command — rewritten now or by an earlier install — takes
|
|
164
|
+
* the matcher the Claude settings file registered that command under, so the host sees one
|
|
165
|
+
* pair rather than two and a re-run converges. Parse failure leaves the file as it was —
|
|
166
|
+
* existence is presence, not parse success.
|
|
167
|
+
*/
|
|
168
|
+
export function retargetGrokHookCommandToClaude(projectRoot) {
|
|
169
|
+
const path = join(projectRoot, GROK_JSON_RELATIVE);
|
|
170
|
+
if (!existsSync(path)) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
let root;
|
|
174
|
+
try {
|
|
175
|
+
root = JSON.parse(readFileSync(path, 'utf-8'));
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (!isPlainObject(root) || !isPlainObject(root.hooks) || !Array.isArray(root.hooks.PreToolUse)) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const settingsMatcher = claudeSettingsMatcherFor(projectRoot, CLAUDE_HOOK_COMMAND);
|
|
184
|
+
let changed = false;
|
|
185
|
+
for (const entry of root.hooks.PreToolUse) {
|
|
186
|
+
if (!isPlainObject(entry) || !Array.isArray(entry.hooks)) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
let namesClaudeHook = false;
|
|
190
|
+
for (const hook of entry.hooks) {
|
|
191
|
+
if (!isPlainObject(hook)) {
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (hook.command === GROK_HOOK_COMMAND) {
|
|
195
|
+
hook.command = CLAUDE_HOOK_COMMAND;
|
|
196
|
+
changed = true;
|
|
197
|
+
}
|
|
198
|
+
namesClaudeHook ||= hook.command === CLAUDE_HOOK_COMMAND;
|
|
199
|
+
}
|
|
200
|
+
// Whether this pass rewrote the command or an earlier install already did, an entry
|
|
201
|
+
// naming the Claude hook pairs with the settings entry only on the same matcher.
|
|
202
|
+
if (namesClaudeHook && settingsMatcher !== undefined && entry.matcher !== settingsMatcher) {
|
|
203
|
+
entry.matcher = settingsMatcher;
|
|
204
|
+
changed = true;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (changed) {
|
|
208
|
+
writeFileSync(path, `${JSON.stringify(root, null, 2)}\n`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Install the Grok session surface into `spec.projectRoot`, skipping whatever is already
|
|
213
|
+
* there and reporting both halves per artifact.
|
|
214
|
+
*
|
|
215
|
+
* Throws before any write when the package cannot be resolved from that root — that leaves
|
|
216
|
+
* zero files. Translating a throw into exit 2 with the install command is the bin's job.
|
|
217
|
+
*/
|
|
218
|
+
export function initGrok(spec) {
|
|
219
|
+
const resolvePolydeukes = spec.resolvePolydeukes ?? resolveFromProjectRoot;
|
|
220
|
+
try {
|
|
221
|
+
resolvePolydeukes(spec.projectRoot);
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
throw new Error(`cannot use 'polydeukes' from ${spec.projectRoot} — install or update it there first ` +
|
|
225
|
+
"(e.g. 'npm install --save-dev polydeukes'), then run this command again: " +
|
|
226
|
+
`${error instanceof Error ? error.message : String(error)}`);
|
|
227
|
+
}
|
|
228
|
+
const report = scaffoldProject(spec.projectRoot);
|
|
229
|
+
const claudeHookExists = existsSync(join(spec.projectRoot, CLAUDE_HOOK_RELATIVE));
|
|
230
|
+
if (!claudeHookExists) {
|
|
231
|
+
writeIfAbsent(spec.projectRoot, GROK_HOOK_RELATIVE, GENERATED_HOOK, report);
|
|
232
|
+
}
|
|
233
|
+
const command = claudeHookExists ? CLAUDE_HOOK_COMMAND : GROK_HOOK_COMMAND;
|
|
234
|
+
const matcher = claudeHookExists
|
|
235
|
+
? (claudeSettingsMatcherFor(spec.projectRoot, CLAUDE_HOOK_COMMAND) ?? HOOK_MATCHER)
|
|
236
|
+
: HOOK_MATCHER;
|
|
237
|
+
writeIfAbsent(spec.projectRoot, GROK_JSON_RELATIVE, grokHookJson(command, matcher), report);
|
|
238
|
+
if (claudeHookExists) {
|
|
239
|
+
retargetGrokHookCommandToClaude(spec.projectRoot);
|
|
240
|
+
}
|
|
241
|
+
return report;
|
|
242
|
+
}
|
package/dist/load-config.d.ts
CHANGED
|
@@ -16,6 +16,10 @@ import type { ResolvedConfig } from '@polydeukes/core';
|
|
|
16
16
|
* create a second spelling and make every later load ambiguous.
|
|
17
17
|
*/
|
|
18
18
|
export declare const CONFIG_FILENAMES: readonly ['polydeukes.config.yaml', 'polydeukes.config.yml', 'polydeukes.config.json'];
|
|
19
|
+
/** {@link loadConfig} input — the directory the config is discovered in. */
|
|
20
|
+
export type LoadConfigSpec = {
|
|
21
|
+
rootDir: string;
|
|
22
|
+
};
|
|
19
23
|
/** `LoadedConfig` — the loader's return value. */
|
|
20
24
|
export type LoadedConfig = {
|
|
21
25
|
/** defineConfig() resolution — protectedPaths already includes configPath */
|
|
@@ -38,4 +42,4 @@ export type LoadedConfig = {
|
|
|
38
42
|
* `config.protectedPaths` unless already present — the config file itself joins the
|
|
39
43
|
* protection surface, guaranteed here so no assembler has to remember.
|
|
40
44
|
*/
|
|
41
|
-
export declare function loadConfig(
|
|
45
|
+
export declare function loadConfig(spec: LoadConfigSpec): LoadedConfig;
|
package/dist/load-config.js
CHANGED
|
@@ -38,7 +38,8 @@ export const CONFIG_FILENAMES = [
|
|
|
38
38
|
* `config.protectedPaths` unless already present — the config file itself joins the
|
|
39
39
|
* protection surface, guaranteed here so no assembler has to remember.
|
|
40
40
|
*/
|
|
41
|
-
export function loadConfig(
|
|
41
|
+
export function loadConfig(spec) {
|
|
42
|
+
const { rootDir } = spec;
|
|
42
43
|
const found = CONFIG_FILENAMES.filter((name) => existsSync(join(rootDir, name)));
|
|
43
44
|
if (found.length === 0) {
|
|
44
45
|
throw new Error(`no Polydeukes config found in ${rootDir} — expected one of: ${CONFIG_FILENAMES.join(', ')}`);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pre-state readers the two surfaces inject into the discipline compiler — the disk
|
|
3
|
+
* access that the judge package must not carry.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The session surface's reader: the hook runs before the tool does, so the working tree at
|
|
7
|
+
* an absolute location IS the pre-state.
|
|
8
|
+
*
|
|
9
|
+
* Three answers, three consequences. Text is a modify; `null` — the file is not there — is a
|
|
10
|
+
* create, so nothing is forgiven as pre-existing debt; `undefined` is a location that cannot
|
|
11
|
+
* be read at all, which the judge escalates to the fail-closed exit. A permission error or a
|
|
12
|
+
* race collapsed into either of the first two would record the run as `passed`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sessionPreStateReader(location: string): string | null | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* The commit surface's reader: it observes a staged diff, whose payloads already carry the
|
|
17
|
+
* pre their own observation saw, and it registers no shell axis — so no derivation ever asks
|
|
18
|
+
* for a pre-state here. Should one arrive, the working tree is not what this surface judges,
|
|
19
|
+
* and answering from it would compare the diff against the wrong baseline; `undefined` says
|
|
20
|
+
* so and fails that call closed.
|
|
21
|
+
*/
|
|
22
|
+
export declare function unobservedPreStateReader(): undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pre-state readers the two surfaces inject into the discipline compiler — the disk
|
|
3
|
+
* access that the judge package must not carry.
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
/**
|
|
7
|
+
* The session surface's reader: the hook runs before the tool does, so the working tree at
|
|
8
|
+
* an absolute location IS the pre-state.
|
|
9
|
+
*
|
|
10
|
+
* Three answers, three consequences. Text is a modify; `null` — the file is not there — is a
|
|
11
|
+
* create, so nothing is forgiven as pre-existing debt; `undefined` is a location that cannot
|
|
12
|
+
* be read at all, which the judge escalates to the fail-closed exit. A permission error or a
|
|
13
|
+
* race collapsed into either of the first two would record the run as `passed`.
|
|
14
|
+
*/
|
|
15
|
+
export function sessionPreStateReader(location) {
|
|
16
|
+
try {
|
|
17
|
+
return readFileSync(location, 'utf-8');
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
return error.code === 'ENOENT' ? null : undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The commit surface's reader: it observes a staged diff, whose payloads already carry the
|
|
25
|
+
* pre their own observation saw, and it registers no shell axis — so no derivation ever asks
|
|
26
|
+
* for a pre-state here. Should one arrive, the working tree is not what this surface judges,
|
|
27
|
+
* and answering from it would compare the diff against the wrong baseline; `undefined` says
|
|
28
|
+
* so and fails that call closed.
|
|
29
|
+
*/
|
|
30
|
+
export function unobservedPreStateReader() {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
package/dist/scaffold-project.js
CHANGED
|
@@ -50,9 +50,9 @@ languages:
|
|
|
50
50
|
# The protection list. A tool call whose proven target is one of these paths is blocked, and
|
|
51
51
|
# so is a shell command that mentions one without a read-only head.
|
|
52
52
|
#
|
|
53
|
-
# .claude/hooks, .claude/settings.json — the gate definitions themselves.
|
|
54
|
-
# does not evade a judgment, it removes the judgment; the session surface
|
|
55
|
-
# layer that can watch it happen.
|
|
53
|
+
# .claude/hooks, .claude/settings.json, .grok/hooks — the gate definitions themselves.
|
|
54
|
+
# Editing them does not evade a judgment, it removes the judgment; the session surface
|
|
55
|
+
# is the only layer that can watch it happen.
|
|
56
56
|
#
|
|
57
57
|
# A minimum. Add entries as you find you want them.
|
|
58
58
|
#
|
|
@@ -61,6 +61,7 @@ languages:
|
|
|
61
61
|
protectedPaths:
|
|
62
62
|
- '.claude/hooks'
|
|
63
63
|
- '.claude/settings.json'
|
|
64
|
+
- '.grok/hooks'
|
|
64
65
|
|
|
65
66
|
# The time-boxed witness — the human valve on a blocked verdict. A human types this token so
|
|
66
67
|
# it stands alone on a message's FIRST line, the window holds for ttlMinutes, then blocking
|
|
@@ -68,9 +69,9 @@ protectedPaths:
|
|
|
68
69
|
# window is always recorded as \`witnessed\` and never silent, and no agent can open one for
|
|
69
70
|
# itself. The token is not a secret: the defence is provenance, not confidentiality.
|
|
70
71
|
#
|
|
71
|
-
# Keep this block. Without it no block can be opened by anyone, and
|
|
72
|
-
# list above — so the first block would freeze the project until a human edits
|
|
73
|
-
# from their own terminal.
|
|
72
|
+
# Keep this block. Without it no block can be opened by anyone, and the hook directories
|
|
73
|
+
# are on the list above — so the first block would freeze the project until a human edits
|
|
74
|
+
# these files from their own terminal.
|
|
74
75
|
witness:
|
|
75
76
|
token: 'pdks witness'
|
|
76
77
|
ttlMinutes: 10
|
|
@@ -86,15 +87,54 @@ witness:
|
|
|
86
87
|
#
|
|
87
88
|
# # Promoted to a judgment. Advise is the default — recorded as \`advised\`, never stops
|
|
88
89
|
# # the call — so this line is optional; it is written here to show the rung.
|
|
90
|
+
# #
|
|
91
|
+
# # The declaration keys each side's matched lines by the matched text and breaks on what
|
|
92
|
+
# # the edit ADDED, so occurrences already in the tree are forgiven.
|
|
89
93
|
# - id: 'no-todo-in-shipped-code'
|
|
90
94
|
# why: 'a TODO nobody owns is a decision deferred out of sight'
|
|
91
|
-
#
|
|
95
|
+
# declare:
|
|
96
|
+
# mechanism: 'added-only'
|
|
97
|
+
# scope: { source: 'target.path', include: ['^src/'] }
|
|
98
|
+
# supply: { pre: 'empty', post: 'empty' }
|
|
99
|
+
# extract:
|
|
100
|
+
# before:
|
|
101
|
+
# - { op: 'source', of: 'pre' }
|
|
102
|
+
# - { op: 'lines' }
|
|
103
|
+
# - { op: 'keyByPattern', re: '(TODO)' }
|
|
104
|
+
# after:
|
|
105
|
+
# - { op: 'source', of: 'post' }
|
|
106
|
+
# - { op: 'lines' }
|
|
107
|
+
# - { op: 'keyByPattern', re: '(TODO)' }
|
|
108
|
+
# added:
|
|
109
|
+
# - { op: 'onlyIn', of: 'after', notIn: 'before' }
|
|
110
|
+
# relate:
|
|
111
|
+
# - id: 'nothing-added'
|
|
112
|
+
# relation: { op: 'empty', of: 'added' }
|
|
113
|
+
# message: 'adds {key}: {value}'
|
|
92
114
|
# enforce: advise
|
|
93
115
|
#
|
|
94
116
|
# # The promotion — block is your choice, never the default.
|
|
95
117
|
# - id: 'no-todo-in-shipped-code-blocking'
|
|
96
118
|
# why: 'a TODO nobody owns is a decision deferred out of sight'
|
|
97
|
-
#
|
|
119
|
+
# declare:
|
|
120
|
+
# mechanism: 'added-only'
|
|
121
|
+
# scope: { source: 'target.path', include: ['^src/'] }
|
|
122
|
+
# supply: { pre: 'empty', post: 'empty' }
|
|
123
|
+
# extract:
|
|
124
|
+
# before:
|
|
125
|
+
# - { op: 'source', of: 'pre' }
|
|
126
|
+
# - { op: 'lines' }
|
|
127
|
+
# - { op: 'keyByPattern', re: '(TODO)' }
|
|
128
|
+
# after:
|
|
129
|
+
# - { op: 'source', of: 'post' }
|
|
130
|
+
# - { op: 'lines' }
|
|
131
|
+
# - { op: 'keyByPattern', re: '(TODO)' }
|
|
132
|
+
# added:
|
|
133
|
+
# - { op: 'onlyIn', of: 'after', notIn: 'before' }
|
|
134
|
+
# relate:
|
|
135
|
+
# - id: 'nothing-added'
|
|
136
|
+
# relation: { op: 'empty', of: 'added' }
|
|
137
|
+
# message: 'adds {key}: {value}'
|
|
98
138
|
# enforce: block
|
|
99
139
|
`;
|
|
100
140
|
/** The schema's path from a config sitting in `projectRoot`, as the directive spells it. */
|
|
@@ -104,32 +104,8 @@
|
|
|
104
104
|
"description": "The entry's own level. 'advise' records a break without stopping it; 'block' pins the entry at block. Composes with the surface's level, the lenient side winning; absent means advise; 'block' is the promotion rung.",
|
|
105
105
|
"enum": ["block", "advise"]
|
|
106
106
|
},
|
|
107
|
-
"globOrGlobs": {
|
|
108
|
-
"anyOf": [
|
|
109
|
-
{ "type": "string", "minLength": 1 },
|
|
110
|
-
{
|
|
111
|
-
"type": "array",
|
|
112
|
-
"minItems": 1,
|
|
113
|
-
"items": { "type": "string", "minLength": 1 }
|
|
114
|
-
}
|
|
115
|
-
]
|
|
116
|
-
},
|
|
117
|
-
"requirePrecedent": {
|
|
118
|
-
"description": "Context family — the session evidence one edit requires beforehand. Exactly one evidence key. The core owns and fully validates 'command'; every other key is adapter vocabulary whose value passes through verbatim (unconstrained here, judged by that adapter).",
|
|
119
|
-
"type": "object",
|
|
120
|
-
"minProperties": 1,
|
|
121
|
-
"maxProperties": 1,
|
|
122
|
-
"properties": {
|
|
123
|
-
"command": {
|
|
124
|
-
"description": "Core evidence vocabulary — regex over the shell command strings observed in the session.",
|
|
125
|
-
"type": "string",
|
|
126
|
-
"minLength": 1,
|
|
127
|
-
"format": "regex"
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
107
|
"discipline": {
|
|
132
|
-
"description": "One discipline entry —
|
|
108
|
+
"description": "One discipline entry — a judged entry (id + declare, optionally why and enforce), or a draft (id + why + draft: true, no declaration).",
|
|
133
109
|
"oneOf": [
|
|
134
110
|
{
|
|
135
111
|
"type": "object",
|
|
@@ -151,79 +127,50 @@
|
|
|
151
127
|
{
|
|
152
128
|
"type": "object",
|
|
153
129
|
"additionalProperties": false,
|
|
154
|
-
"required": ["id", "
|
|
155
|
-
"properties": {
|
|
156
|
-
"id": { "$ref": "#/$defs/disciplineId" },
|
|
157
|
-
"why": { "$ref": "#/$defs/disciplineWhy" },
|
|
158
|
-
"enforce": { "$ref": "#/$defs/enforceLevel" },
|
|
159
|
-
"in": { "$ref": "#/$defs/globOrGlobs" },
|
|
160
|
-
"except": { "$ref": "#/$defs/globOrGlobs" },
|
|
161
|
-
"forbid": {
|
|
162
|
-
"description": "Delta family — string shorthand is equivalent to { added }.",
|
|
163
|
-
"anyOf": [
|
|
164
|
-
{ "type": "string", "minLength": 1, "format": "regex" },
|
|
165
|
-
{
|
|
166
|
-
"type": "object",
|
|
167
|
-
"additionalProperties": false,
|
|
168
|
-
"required": ["added"],
|
|
169
|
-
"properties": {
|
|
170
|
-
"added": { "type": "string", "minLength": 1, "format": "regex" }
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
]
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
{
|
|
178
|
-
"type": "object",
|
|
179
|
-
"additionalProperties": false,
|
|
180
|
-
"required": ["id", "immutable"],
|
|
181
|
-
"properties": {
|
|
182
|
-
"id": { "$ref": "#/$defs/disciplineId" },
|
|
183
|
-
"why": { "$ref": "#/$defs/disciplineWhy" },
|
|
184
|
-
"enforce": { "$ref": "#/$defs/enforceLevel" },
|
|
185
|
-
"immutable": {
|
|
186
|
-
"description": "Path family — its own glob is the scope.",
|
|
187
|
-
"$ref": "#/$defs/globOrGlobs"
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
"type": "object",
|
|
193
|
-
"additionalProperties": false,
|
|
194
|
-
"required": ["id", "forbidCommand"],
|
|
195
|
-
"properties": {
|
|
196
|
-
"id": { "$ref": "#/$defs/disciplineId" },
|
|
197
|
-
"why": { "$ref": "#/$defs/disciplineWhy" },
|
|
198
|
-
"enforce": { "$ref": "#/$defs/enforceLevel" },
|
|
199
|
-
"forbidCommand": {
|
|
200
|
-
"description": "Command family — regex over shell command strings.",
|
|
201
|
-
"type": "string",
|
|
202
|
-
"minLength": 1,
|
|
203
|
-
"format": "regex"
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
"type": "object",
|
|
209
|
-
"additionalProperties": false,
|
|
210
|
-
"required": ["id", "requirePrecedent"],
|
|
130
|
+
"required": ["id", "declare"],
|
|
211
131
|
"properties": {
|
|
212
132
|
"id": { "$ref": "#/$defs/disciplineId" },
|
|
213
133
|
"why": { "$ref": "#/$defs/disciplineWhy" },
|
|
214
134
|
"enforce": { "$ref": "#/$defs/enforceLevel" },
|
|
215
|
-
"
|
|
216
|
-
"except": { "$ref": "#/$defs/globOrGlobs" },
|
|
217
|
-
"when": {
|
|
218
|
-
"description": "Context-family trigger — added-direction delta regex. Absent means every in-scope change triggers.",
|
|
219
|
-
"type": "string",
|
|
220
|
-
"minLength": 1,
|
|
221
|
-
"format": "regex"
|
|
222
|
-
},
|
|
223
|
-
"requirePrecedent": { "$ref": "#/$defs/requirePrecedent" }
|
|
135
|
+
"declare": { "$ref": "#/$defs/declarationBody" }
|
|
224
136
|
}
|
|
225
137
|
}
|
|
226
138
|
]
|
|
139
|
+
},
|
|
140
|
+
"declarationBody": {
|
|
141
|
+
"description": "Declaration family — one judgment written as data, in the grammar of the algebra declaration schema published beside this one, minus its 'discipline' key: the entry id is the declaration's name. The blocks' interiors are validated against that schema by the runtime validator.",
|
|
142
|
+
"type": "object",
|
|
143
|
+
"additionalProperties": false,
|
|
144
|
+
"required": ["mechanism", "extract", "relate"],
|
|
145
|
+
"properties": {
|
|
146
|
+
"mechanism": {
|
|
147
|
+
"enum": [
|
|
148
|
+
"pairing",
|
|
149
|
+
"companion",
|
|
150
|
+
"monotonic-order",
|
|
151
|
+
"fingerprint-sync",
|
|
152
|
+
"producer-owned",
|
|
153
|
+
"self-absolution-ban",
|
|
154
|
+
"actor-scope",
|
|
155
|
+
"precedent",
|
|
156
|
+
"phase-order",
|
|
157
|
+
"turn-locality",
|
|
158
|
+
"stated-ground",
|
|
159
|
+
"controlled-vocabulary",
|
|
160
|
+
"naming",
|
|
161
|
+
"added-only",
|
|
162
|
+
"one-way-marker",
|
|
163
|
+
"scoped-valve",
|
|
164
|
+
"forbidden-command"
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
"scope": { "type": "object" },
|
|
168
|
+
"sources": { "type": "object" },
|
|
169
|
+
"supply": { "type": "object" },
|
|
170
|
+
"extract": { "type": "object", "minProperties": 1 },
|
|
171
|
+
"relate": { "type": "array", "minItems": 1 },
|
|
172
|
+
"witness": { "type": "object" }
|
|
173
|
+
}
|
|
227
174
|
}
|
|
228
175
|
}
|
|
229
176
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polydeukes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "A development discipline framework for building alongside an AI coding partner — deterministic covenants, a verifiable work ledger, local memory, and adversarial verification. Alpha.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"harness",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"import": "./dist/index.js"
|
|
38
38
|
},
|
|
39
39
|
"./claude-code": {
|
|
40
|
-
"types": "./dist/claude-code
|
|
41
|
-
"import": "./dist/claude-code
|
|
40
|
+
"types": "./dist/claude-code.d.ts",
|
|
41
|
+
"import": "./dist/claude-code.js"
|
|
42
42
|
},
|
|
43
43
|
"./schema.json": "./dist/schema/polydeukes.schema.json"
|
|
44
44
|
},
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"yaml": "2.9.0",
|
|
57
|
-
"@polydeukes/adapter-claude-code": "^0.
|
|
58
|
-
"@polydeukes/
|
|
59
|
-
"@polydeukes/covenant": "^0.
|
|
60
|
-
"@polydeukes/
|
|
57
|
+
"@polydeukes/adapter-claude-code": "^0.6.1",
|
|
58
|
+
"@polydeukes/core": "^0.6.1",
|
|
59
|
+
"@polydeukes/covenant": "^0.6.1",
|
|
60
|
+
"@polydeukes/adapter-git": "^0.6.1"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@types/node": "^24.0.0",
|