@ngockhoale/ukit 2.6.11 → 2.7.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/CHANGELOG.md +70 -0
- package/manifests/documentation.yaml +24 -2
- package/manifests/instructionRules.yaml +62 -0
- package/package.json +1 -1
- package/scripts/perf/audit-perf.mjs +920 -0
- package/src/cli/commands/doctor.js +23 -4
- package/src/core/diffPlan.js +8 -0
- package/src/core/ompConfigMerge.js +222 -0
- package/src/core/runInstallPipeline.js +11 -0
- package/src/core/runtimeConfig.js +11 -0
- package/src/core/unattendedDoctor.js +227 -0
- package/templates/.claude/hooks/block-dangerous.sh +76 -9
- package/templates/.claude/hooks/context-hardcap-gate.sh +26 -8
- package/templates/.claude/hooks/project-important.sh +70 -9
- package/templates/.claude/hooks/protect-files.sh +24 -7
- package/templates/.claude/hooks/sensitive-data-guard.sh +57 -5
- package/templates/.claude/settings.json +22 -117
- package/templates/.claude/ukit/runtime/hook-chain-runner.mjs +217 -10
- package/templates/.claude/ukit/runtime/hook-input.sh +119 -0
- package/templates/.omp/config.yml +32 -4
- package/templates/.omp/hooks/pre/ukit-bridge.js +12 -1
- package/templates/AGENTS.md +22 -10
- package/templates/CLAUDE.md +22 -10
- package/templates/adapter-presets/opencode/opencode.template.json +1 -1
- package/templates/instructions/core.md +22 -10
- package/templates/instructions/layout.yaml +12 -12
- package/templates/ukit/storage/config.json +2 -0
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
inspectProjectImportantWiring,
|
|
24
24
|
} from '../../core/projectImportant.js';
|
|
25
25
|
import { runDocContractChecks } from '../../core/docContracts.js';
|
|
26
|
+
import { inspectUnattendedMode } from '../../core/unattendedDoctor.js';
|
|
26
27
|
|
|
27
28
|
export const DOCTOR_HELP_FLAGS = new Set(['--help', '-h']);
|
|
28
29
|
const KNOWN_FLAGS = new Set([...DOCTOR_HELP_FLAGS, '--skills', '--gateway', '--docs']);
|
|
@@ -40,7 +41,7 @@ export function printDoctorHelp() {
|
|
|
40
41
|
console.log(' --docs Run doc-contract checks (manifests/documentation.yaml projects only)');
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
export async function runDoctor({ packageRoot, projectRoot, argv = [], homeDir = os.homedir() }) {
|
|
44
|
+
export async function runDoctor({ packageRoot, projectRoot, argv = [], homeDir = os.homedir(), ompPath = 'omp' }) {
|
|
44
45
|
const unknownFlags = argv.filter((flag) => !KNOWN_FLAGS.has(flag));
|
|
45
46
|
if (unknownFlags.length > 0) {
|
|
46
47
|
throw new Error(`Unknown option: ${unknownFlags[0]}. Supported: ${SUPPORTED_FLAGS_LIST}`);
|
|
@@ -254,6 +255,20 @@ export async function runDoctor({ packageRoot, projectRoot, argv = [], homeDir =
|
|
|
254
255
|
console.log(`[UKit] ${ok(check.passed)} ${check.label}`);
|
|
255
256
|
}
|
|
256
257
|
|
|
258
|
+
// TASK-011 / SPEC §8 (FR-007): unattended-mode checks — same remediation-class
|
|
259
|
+
// shape as projectChecks; install-repairable/owner-action failures block the
|
|
260
|
+
// exit code, advisory never does.
|
|
261
|
+
const unattended = await inspectUnattendedMode({ projectRoot, ompPath });
|
|
262
|
+
console.log('[UKit] Unattended-mode checks:');
|
|
263
|
+
for (const check of unattended.checks) {
|
|
264
|
+
if (check.applicable === false) continue;
|
|
265
|
+
console.log(`[UKit] ${ok(check.passed)} ${check.label}`);
|
|
266
|
+
if (check.detail) console.log(`[UKit] detail: ${check.detail}`);
|
|
267
|
+
if (!check.passed && check.remedy) {
|
|
268
|
+
console.log(`[UKit] remedy: ${check.remedy}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
257
272
|
if (runtimeConfigInspection.errors.length > 0) {
|
|
258
273
|
console.log(`[UKit] Runtime config issues: ${runtimeConfigInspection.errors.join(' | ')}`);
|
|
259
274
|
}
|
|
@@ -402,13 +417,17 @@ export async function runDoctor({ packageRoot, projectRoot, argv = [], homeDir =
|
|
|
402
417
|
const failedProjectChecks = projectChecks.filter(
|
|
403
418
|
(check) => check.applicable !== false && !check.passed,
|
|
404
419
|
);
|
|
405
|
-
const
|
|
420
|
+
const failedUnattendedChecks = unattended.checks.filter(
|
|
421
|
+
(check) => check.applicable !== false && !check.passed,
|
|
422
|
+
);
|
|
423
|
+
const allFailedChecks = [...failedProjectChecks, ...failedUnattendedChecks];
|
|
424
|
+
const blockingFailures = allFailedChecks.filter(
|
|
406
425
|
(check) => check.remediationClass === 'install-repairable' || check.remediationClass === 'owner-action',
|
|
407
426
|
);
|
|
408
427
|
|
|
409
|
-
if (
|
|
428
|
+
if (allFailedChecks.length > 0) {
|
|
410
429
|
console.log('[UKit] Remedies:');
|
|
411
|
-
for (const check of
|
|
430
|
+
for (const check of allFailedChecks) {
|
|
412
431
|
console.log(`[UKit] - [${check.remediationClass}] ${check.remedy}`);
|
|
413
432
|
}
|
|
414
433
|
}
|
package/src/core/diffPlan.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import { isSymlinkTo } from './fileOps.js';
|
|
3
3
|
import { GATEWAY_RESILIENCE_ENV_DEFAULTS } from './gatewayResilienceEnv.js';
|
|
4
|
+
import { isOmpConfigTarget, mergeOmpConfig } from './ompConfigMerge.js';
|
|
4
5
|
|
|
5
6
|
const GATEWAY_RESILIENCE_KEYS = new Set(Object.keys(GATEWAY_RESILIENCE_ENV_DEFAULTS));
|
|
6
7
|
|
|
@@ -116,6 +117,13 @@ function resolveFileAction(entry, existingContent) {
|
|
|
116
117
|
: entry.mergeStrategy === 'skip'
|
|
117
118
|
? 'skip'
|
|
118
119
|
: 'update';
|
|
120
|
+
} else if (isOmpConfigTarget(entry.targetPath) && typeof existingContent === 'string' && typeof entry.renderedContent === 'string') {
|
|
121
|
+
// SPEC §7 step 9: `.omp/config.yml` gets a semantic, comment-safe migration
|
|
122
|
+
// merge — the action compares the MERGED text against the existing file, so
|
|
123
|
+
// preserved user regions do not count as drift.
|
|
124
|
+
const merged = mergeOmpConfig(existingContent, entry.renderedContent);
|
|
125
|
+
action = merged.text === existingContent ? 'unchanged' : 'update';
|
|
126
|
+
return { ...entry, renderedContent: merged.text, migrationReport: merged.report, exists, action, existingContent };
|
|
119
127
|
} else if (entry.mergeStrategy === 'merge_env_overwrite_with_backup' && typeof existingContent === 'string') {
|
|
120
128
|
// Settings.json: ignore UKit-managed gateway resilience env keys (post-apply written
|
|
121
129
|
// and may carry user overrides). All other top-level keys — and the rest of the env
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import YAML from 'yaml';
|
|
2
|
+
|
|
3
|
+
// TASK-010 / SPEC §5.2 + §7 (FR-006): semantic, comment-safe migration merge for
|
|
4
|
+
// `.omp/config.yml`. Operates on the rendered template TEXT with surgical splices
|
|
5
|
+
// so the template's load-bearing comments survive — a full YAML round-trip
|
|
6
|
+
// (parse + stringify) would drop every comment.
|
|
7
|
+
|
|
8
|
+
export const PRESERVED_MARKER = '# Preserved by UKit unattended migration (C35):';
|
|
9
|
+
|
|
10
|
+
const OMP_CONFIG_SUFFIX = '.omp/config.yml';
|
|
11
|
+
|
|
12
|
+
export function isOmpConfigTarget(targetPath) {
|
|
13
|
+
return typeof targetPath === 'string' && targetPath.replace(/\\/g, '/').endsWith(OMP_CONFIG_SUFFIX);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function emptyReport() {
|
|
17
|
+
return {
|
|
18
|
+
migrated: false,
|
|
19
|
+
legacyApprovalMode: null,
|
|
20
|
+
strippedPromptApprovals: [],
|
|
21
|
+
coercedPromptPatterns: [],
|
|
22
|
+
preservedModelRoles: false,
|
|
23
|
+
preservedTopLevelKeys: [],
|
|
24
|
+
preservedPatterns: [],
|
|
25
|
+
parseError: null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Extract a top-level scalar map's value span: the `key:` line plus following
|
|
30
|
+
// lines that are indented or blank. Stops before the next non-indented,
|
|
31
|
+
// non-blank line — comments preceding the next top-level key stay with it.
|
|
32
|
+
function extractScalarMapSpan(lines, key) {
|
|
33
|
+
const start = lines.findIndex((line) => new RegExp(`^${key}:\\s*$`).test(line) || new RegExp(`^${key}:\\s`).test(line));
|
|
34
|
+
if (start === -1) return null;
|
|
35
|
+
let end = start + 1;
|
|
36
|
+
while (end < lines.length) {
|
|
37
|
+
const line = lines[end];
|
|
38
|
+
if (line.trim() === '' || /^\s/.test(line)) {
|
|
39
|
+
end += 1;
|
|
40
|
+
} else {
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Trim trailing blank lines out of the span — they belong to the gap before
|
|
45
|
+
// the next key, not to this block.
|
|
46
|
+
let blockEnd = end;
|
|
47
|
+
while (blockEnd > start + 1 && lines[blockEnd - 1].trim() === '') {
|
|
48
|
+
blockEnd -= 1;
|
|
49
|
+
}
|
|
50
|
+
return { start, end: blockEnd, lines: lines.slice(start, blockEnd) };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function isPlainObject(value) {
|
|
54
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Indent every line of a YAML fragment by `indent` spaces.
|
|
58
|
+
function indentFragment(fragment, indent) {
|
|
59
|
+
const pad = ' '.repeat(indent);
|
|
60
|
+
return fragment
|
|
61
|
+
.split('\n')
|
|
62
|
+
.filter((line) => line !== '')
|
|
63
|
+
.map((line) => pad + line);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function mergeOmpConfig(existingText, renderedText) {
|
|
67
|
+
const report = emptyReport();
|
|
68
|
+
|
|
69
|
+
let existing;
|
|
70
|
+
try {
|
|
71
|
+
existing = YAML.parse(existingText);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
report.parseError = error?.message ?? String(error);
|
|
74
|
+
return { text: renderedText, report };
|
|
75
|
+
}
|
|
76
|
+
if (!isPlainObject(existing)) {
|
|
77
|
+
report.parseError = 'existing .omp/config.yml did not parse to a mapping';
|
|
78
|
+
return { text: renderedText, report };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let rendered;
|
|
82
|
+
try {
|
|
83
|
+
rendered = YAML.parse(renderedText);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
// A broken template is not a migration problem — surface it as parseError so
|
|
86
|
+
// the caller falls back to plain overwrite rather than crashing install.
|
|
87
|
+
report.parseError = `rendered template failed to parse: ${error?.message ?? error}`;
|
|
88
|
+
return { text: renderedText, report };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const existingTools = isPlainObject(existing.tools) ? existing.tools : {};
|
|
92
|
+
const existingApproval = isPlainObject(existingTools.approval) ? existingTools.approval : {};
|
|
93
|
+
const renderedApproval = isPlainObject(rendered?.tools?.approval) ? rendered.tools.approval : {};
|
|
94
|
+
|
|
95
|
+
report.legacyApprovalMode = typeof existingTools.approvalMode === 'string'
|
|
96
|
+
? existingTools.approvalMode
|
|
97
|
+
: null;
|
|
98
|
+
|
|
99
|
+
// §7.2 — user-defined tools.approval.<k> keys absent from the canonical map:
|
|
100
|
+
// preserved only when allow|deny; every `prompt` value (canonical or custom)
|
|
101
|
+
// is recorded in strippedPromptApprovals.
|
|
102
|
+
const extraApprovalEntries = [];
|
|
103
|
+
for (const [key, value] of Object.entries(existingApproval)) {
|
|
104
|
+
if (value === 'prompt') {
|
|
105
|
+
report.strippedPromptApprovals.push(key);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (!(key in renderedApproval) && (value === 'allow' || value === 'deny')) {
|
|
109
|
+
extraApprovalEntries.push([key, value]);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// §7.4 — bash.patterns union: existing-only entries (dedupe by match) appended
|
|
114
|
+
// before the trailing `- match: "*"` allow; `prompt` re-emitted as `deny`.
|
|
115
|
+
const existingPatterns = Array.isArray(existing?.bash?.patterns) ? existing.bash.patterns : [];
|
|
116
|
+
const renderedPatterns = Array.isArray(rendered?.bash?.patterns) ? rendered.bash.patterns : [];
|
|
117
|
+
const renderedMatches = new Set(renderedPatterns.map((p) => p?.match));
|
|
118
|
+
const extraPatterns = [];
|
|
119
|
+
for (const pattern of existingPatterns) {
|
|
120
|
+
if (!isPlainObject(pattern) || typeof pattern.match !== 'string') continue;
|
|
121
|
+
if (renderedMatches.has(pattern.match)) continue;
|
|
122
|
+
let approval = pattern.approval;
|
|
123
|
+
if (approval === 'prompt') {
|
|
124
|
+
approval = 'deny';
|
|
125
|
+
report.coercedPromptPatterns.push(pattern.match);
|
|
126
|
+
}
|
|
127
|
+
extraPatterns.push({ ...pattern, approval });
|
|
128
|
+
report.preservedPatterns.push(pattern.match);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// §7.6 — extra top-level keys absent from the rendered template.
|
|
132
|
+
const extraTopLevel = {};
|
|
133
|
+
if (isPlainObject(rendered)) {
|
|
134
|
+
for (const [key, value] of Object.entries(existing)) {
|
|
135
|
+
if (!(key in rendered)) {
|
|
136
|
+
extraTopLevel[key] = value;
|
|
137
|
+
report.preservedTopLevelKeys.push(key);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const lines = renderedText.split('\n');
|
|
143
|
+
|
|
144
|
+
// §7.3 — modelRoles block splice: replace the rendered `modelRoles:` scalar
|
|
145
|
+
// map span with the existing span (maintainer edits for non-UNIC providers).
|
|
146
|
+
const renderedRoles = extractScalarMapSpan(lines, 'modelRoles');
|
|
147
|
+
const existingLines = existingText.split('\n');
|
|
148
|
+
const existingRoles = extractScalarMapSpan(existingLines, 'modelRoles');
|
|
149
|
+
if (renderedRoles && existingRoles && isPlainObject(existing.modelRoles)) {
|
|
150
|
+
lines.splice(renderedRoles.start, renderedRoles.end - renderedRoles.start, ...existingRoles.lines);
|
|
151
|
+
report.preservedModelRoles = true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// §7.2 splice — append preserved allow/deny keys to the rendered
|
|
155
|
+
// tools.approval map (before the first line that leaves the map's indent).
|
|
156
|
+
if (extraApprovalEntries.length > 0) {
|
|
157
|
+
const approvalStart = lines.findIndex((line) => /^\s+approval:\s*$/.test(line));
|
|
158
|
+
if (approvalStart !== -1) {
|
|
159
|
+
const baseIndent = lines[approvalStart].match(/^\s*/)[0].length;
|
|
160
|
+
let insertAt = approvalStart + 1;
|
|
161
|
+
while (insertAt < lines.length) {
|
|
162
|
+
const line = lines[insertAt];
|
|
163
|
+
if (line.trim() === '') {
|
|
164
|
+
insertAt += 1;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
const indent = line.match(/^\s*/)[0].length;
|
|
168
|
+
if (indent <= baseIndent) break;
|
|
169
|
+
insertAt += 1;
|
|
170
|
+
}
|
|
171
|
+
const fragment = extraApprovalEntries.map(([k, v]) => `${' '.repeat(baseIndent + 2)}${k}: ${v}`);
|
|
172
|
+
lines.splice(insertAt, 0, ...fragment);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// §7.4 splice — insert preserved patterns before the trailing `- match: "*"`
|
|
177
|
+
// allow (or at the end of the patterns list if no wildcard exists).
|
|
178
|
+
if (extraPatterns.length > 0) {
|
|
179
|
+
// YAML.stringify emits sequence items at column 0; preserve each line's
|
|
180
|
+
// relative indentation and shift the whole fragment to the list's indent.
|
|
181
|
+
const rawFragment = YAML.stringify(extraPatterns).trimEnd().split('\n');
|
|
182
|
+
const wildcardIdx = lines.findIndex((line) => /- match: ["']?\*["']?\s*$/.test(line));
|
|
183
|
+
if (wildcardIdx !== -1) {
|
|
184
|
+
const itemIndent = lines[wildcardIdx].match(/^\s*/)[0].length;
|
|
185
|
+
lines.splice(wildcardIdx, 0, ...rawFragment.map((line) => ' '.repeat(itemIndent) + line));
|
|
186
|
+
} else {
|
|
187
|
+
const patternsStart = lines.findIndex((line) => /^\s+patterns:\s*$/.test(line));
|
|
188
|
+
if (patternsStart !== -1) {
|
|
189
|
+
const baseIndent = lines[patternsStart].match(/^\s*/)[0].length;
|
|
190
|
+
let insertAt = patternsStart + 1;
|
|
191
|
+
while (insertAt < lines.length) {
|
|
192
|
+
const line = lines[insertAt];
|
|
193
|
+
if (line.trim() === '') {
|
|
194
|
+
insertAt += 1;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
const indent = line.match(/^\s*/)[0].length;
|
|
198
|
+
if (indent <= baseIndent) break;
|
|
199
|
+
insertAt += 1;
|
|
200
|
+
}
|
|
201
|
+
const itemIndent = baseIndent + 2;
|
|
202
|
+
lines.splice(insertAt, 0, ...rawFragment.map((line) => ' '.repeat(itemIndent) + line));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// §7.6 splice — append extra top-level keys under the preserved marker.
|
|
208
|
+
if (report.preservedTopLevelKeys.length > 0) {
|
|
209
|
+
const fragment = YAML.stringify(extraTopLevel).trimEnd().split('\n');
|
|
210
|
+
let end = lines.length;
|
|
211
|
+
while (end > 0 && lines[end - 1].trim() === '') end -= 1;
|
|
212
|
+
lines.splice(end, lines.length - end, '', PRESERVED_MARKER, ...fragment, '');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const text = lines.join('\n');
|
|
216
|
+
// "migrated" = the merge changed anything relative to what is on disk —
|
|
217
|
+
// includes the approval-surface rewrite itself (legacy approvalMode, prompt
|
|
218
|
+
// values) even when no user region needed splicing.
|
|
219
|
+
report.migrated = text !== existingText;
|
|
220
|
+
|
|
221
|
+
return { text, report };
|
|
222
|
+
}
|
|
@@ -310,6 +310,17 @@ export async function runInstallPipeline({
|
|
|
310
310
|
projectRoot: pathConfig.projectRoot,
|
|
311
311
|
});
|
|
312
312
|
|
|
313
|
+
// SPEC §7 step 9: surface the .omp/config.yml unattended migration result.
|
|
314
|
+
for (const entry of diffResults) {
|
|
315
|
+
const report = entry?.migrationReport;
|
|
316
|
+
if (!report?.migrated) continue;
|
|
317
|
+
const removed = (report.strippedPromptApprovals?.length ?? 0) + (report.coercedPromptPatterns?.length ?? 0);
|
|
318
|
+
const preserved = (report.preservedModelRoles ? 1 : 0)
|
|
319
|
+
+ (report.preservedTopLevelKeys?.length ?? 0)
|
|
320
|
+
+ (report.preservedPatterns?.length ?? 0);
|
|
321
|
+
console.log(`[UKit] .omp/config.yml: migrated approval surface (prompt→removed: ${removed}, preserved: ${preserved})`);
|
|
322
|
+
}
|
|
323
|
+
|
|
313
324
|
// BUG-C22-19: bound the .bak accumulation — every overwrite_with_backup write
|
|
314
325
|
// adds one and nothing removed them. Advisory: a prune failure must never
|
|
315
326
|
// fail the install.
|
|
@@ -12,6 +12,10 @@ const { version: PACKAGE_VERSION } = require('../../package.json');
|
|
|
12
12
|
// config.json naming it must not become invalid.
|
|
13
13
|
const VALID_AGENTS = new Set(['claude-code', 'codex', 'antigravity', 'opencode', 'omp']);
|
|
14
14
|
|
|
15
|
+
// Reserved permission modes for orchestration.permissionMode (single source of truth).
|
|
16
|
+
// 'unattended' is the only mode implemented this cycle; interactive/safe-auto are reserved.
|
|
17
|
+
export const VALID_PERMISSION_MODES = new Set(['interactive', 'safe-auto', 'unattended']);
|
|
18
|
+
|
|
15
19
|
const BLOCKED_MERGE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
16
20
|
|
|
17
21
|
function isPlainObject(value) {
|
|
@@ -137,6 +141,7 @@ export function buildDefaultRuntimeConfig(overrides = {}) {
|
|
|
137
141
|
enabled: true,
|
|
138
142
|
orchestratorModel: 'claude-sonnet-5',
|
|
139
143
|
advisorEnabled: true,
|
|
144
|
+
permissionMode: 'unattended',
|
|
140
145
|
contracts: buildConfigContracts(),
|
|
141
146
|
modelTiers: {
|
|
142
147
|
lite: { claudeModel: 'claude-haiku-4-5', genericModel: 'unic-lite' },
|
|
@@ -393,6 +398,12 @@ export function validateRuntimeConfig(config) {
|
|
|
393
398
|
pushBooleanError(errors, config.orchestration.enabled, 'orchestration.enabled');
|
|
394
399
|
pushNonEmptyStringError(errors, config.orchestration.orchestratorModel, 'orchestration.orchestratorModel');
|
|
395
400
|
pushBooleanError(errors, config.orchestration.advisorEnabled, 'orchestration.advisorEnabled');
|
|
401
|
+
// permissionMode is optional-present: absent → tolerated (pre-C35 configs);
|
|
402
|
+
// present → must be a reserved mode.
|
|
403
|
+
if (config.orchestration.permissionMode !== undefined
|
|
404
|
+
&& !VALID_PERMISSION_MODES.has(config.orchestration.permissionMode)) {
|
|
405
|
+
errors.push(`orchestration.permissionMode must be one of: ${[...VALID_PERMISSION_MODES].join(', ')}.`);
|
|
406
|
+
}
|
|
396
407
|
if (!isPlainObject(config.orchestration.contracts)) {
|
|
397
408
|
errors.push('orchestration.contracts must be an object.');
|
|
398
409
|
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import { execFile } from 'node:child_process';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { parse } from 'yaml';
|
|
6
|
+
import { pathExists, readJsonIfExists } from './fileOps.js';
|
|
7
|
+
import { VALID_PERMISSION_MODES } from './runtimeConfig.js';
|
|
8
|
+
|
|
9
|
+
// TASK-011 / SPEC §8 — unattended-mode doctor checks (FR-007).
|
|
10
|
+
// Seven checks, each returning the projectChecks remediation-class shape:
|
|
11
|
+
// { label, passed, applicable?, failed, remediationClass, remedy, detail? }
|
|
12
|
+
// remediationClass ∈ install-repairable | owner-action | advisory.
|
|
13
|
+
|
|
14
|
+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
|
|
15
|
+
const INSTALL_REPAIR = 'Run ukit install';
|
|
16
|
+
const OMP_CONFIG_TIMEOUT_MS = 5000;
|
|
17
|
+
const COMPLETION_LOOP_HEADER = '## Unattended Completion Loop';
|
|
18
|
+
|
|
19
|
+
async function readOmpConfig(projectRoot) {
|
|
20
|
+
const configPath = path.join(projectRoot, '.omp', 'config.yml');
|
|
21
|
+
try {
|
|
22
|
+
const text = await fs.readFile(configPath, 'utf8');
|
|
23
|
+
const parsed = parse(text);
|
|
24
|
+
return { exists: true, parsed: parsed && typeof parsed === 'object' ? parsed : {}, parseError: null };
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (error?.code === 'ENOENT') return { exists: false, parsed: null, parseError: null };
|
|
27
|
+
return { exists: true, parsed: null, parseError: error?.message ?? String(error) };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const ANSI_PATTERN = /\u001b\[[0-9;]*m/g;
|
|
32
|
+
|
|
33
|
+
function execOmpConfigGet(projectRoot, ompPath) {
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
execFile(
|
|
36
|
+
ompPath,
|
|
37
|
+
['config', 'get', 'tools.approvalMode'],
|
|
38
|
+
{ cwd: projectRoot, timeout: OMP_CONFIG_TIMEOUT_MS },
|
|
39
|
+
(error, stdout) => {
|
|
40
|
+
if (error) {
|
|
41
|
+
resolve({ ok: false, value: null });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const value = String(stdout ?? '').replace(ANSI_PATTERN, '').trim();
|
|
45
|
+
resolve({ ok: value.length > 0, value: value || null });
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function readTemplateDenyMatches() {
|
|
52
|
+
try {
|
|
53
|
+
const text = await fs.readFile(path.join(PACKAGE_ROOT, 'templates', '.omp', 'config.yml'), 'utf8');
|
|
54
|
+
const parsed = parse(text);
|
|
55
|
+
const patterns = parsed?.bash?.patterns;
|
|
56
|
+
if (!Array.isArray(patterns)) return [];
|
|
57
|
+
return patterns
|
|
58
|
+
.filter((entry) => entry && entry.approval === 'deny' && typeof entry.match === 'string')
|
|
59
|
+
.map((entry) => entry.match);
|
|
60
|
+
} catch {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export async function inspectUnattendedMode({ projectRoot, ompPath = 'omp' }) {
|
|
66
|
+
const runtimeConfig = await readJsonIfExists(
|
|
67
|
+
path.join(projectRoot, '.ukit', 'storage', 'config.json'),
|
|
68
|
+
);
|
|
69
|
+
const permissionModeRaw = runtimeConfig?.orchestration?.permissionMode;
|
|
70
|
+
const permissionModeValid = permissionModeRaw === undefined
|
|
71
|
+
|| VALID_PERMISSION_MODES.has(permissionModeRaw);
|
|
72
|
+
const permissionMode = permissionModeRaw === undefined ? 'unattended' : permissionModeRaw;
|
|
73
|
+
|
|
74
|
+
const omp = await readOmpConfig(projectRoot);
|
|
75
|
+
const tools = omp.parsed?.tools ?? {};
|
|
76
|
+
const approvalMap = tools.approval && typeof tools.approval === 'object' ? tools.approval : {};
|
|
77
|
+
const bashPatterns = Array.isArray(omp.parsed?.bash?.patterns) ? omp.parsed.bash.patterns : [];
|
|
78
|
+
|
|
79
|
+
// Check 2 — effective approvalMode: `omp config get` first (5s timeout), YAML fallback.
|
|
80
|
+
let effectiveApprovalMode = null;
|
|
81
|
+
let approvalSource = null;
|
|
82
|
+
if (omp.exists) {
|
|
83
|
+
const ompResult = await execOmpConfigGet(projectRoot, ompPath);
|
|
84
|
+
if (ompResult.ok) {
|
|
85
|
+
effectiveApprovalMode = ompResult.value;
|
|
86
|
+
approvalSource = 'omp config get';
|
|
87
|
+
} else if (tools.approvalMode !== undefined) {
|
|
88
|
+
effectiveApprovalMode = tools.approvalMode ?? null;
|
|
89
|
+
approvalSource = '.omp/config.yml (omp binary unavailable)';
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const promptValues = [tools.approvalMode, ...Object.values(approvalMap)];
|
|
94
|
+
for (const entry of bashPatterns) {
|
|
95
|
+
if (entry && typeof entry === 'object' && 'approval' in entry) promptValues.push(entry.approval);
|
|
96
|
+
}
|
|
97
|
+
const promptPolicyCount = promptValues.filter((v) => v === 'prompt').length;
|
|
98
|
+
|
|
99
|
+
const bridgePath = path.join(projectRoot, '.omp', 'hooks', 'pre', 'ukit-bridge.js');
|
|
100
|
+
const bridgeExists = await pathExists(bridgePath);
|
|
101
|
+
const requiredDenyMatches = await readTemplateDenyMatches();
|
|
102
|
+
const installedDenyMatches = new Set(
|
|
103
|
+
bashPatterns
|
|
104
|
+
.filter((entry) => entry && entry.approval === 'deny' && typeof entry.match === 'string')
|
|
105
|
+
.map((entry) => entry.match),
|
|
106
|
+
);
|
|
107
|
+
const missingDenyMatches = requiredDenyMatches.filter((m) => !installedDenyMatches.has(m));
|
|
108
|
+
const guardState = !bridgeExists
|
|
109
|
+
? 'degraded'
|
|
110
|
+
: (missingDenyMatches.length > 0 ? 'partial' : 'enabled');
|
|
111
|
+
|
|
112
|
+
let loopGuidanceInstalled = false;
|
|
113
|
+
let instructionDocExists = false;
|
|
114
|
+
for (const docName of ['CLAUDE.md', 'AGENTS.md']) {
|
|
115
|
+
try {
|
|
116
|
+
const text = await fs.readFile(path.join(projectRoot, docName), 'utf8');
|
|
117
|
+
instructionDocExists = true;
|
|
118
|
+
if (text.includes(COMPLETION_LOOP_HEADER)) {
|
|
119
|
+
loopGuidanceInstalled = true;
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
} catch {
|
|
123
|
+
// file may not exist
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const check = (label, passed, remediationClass, remedy, extra = {}) => ({
|
|
128
|
+
label,
|
|
129
|
+
passed,
|
|
130
|
+
failed: !passed,
|
|
131
|
+
remediationClass,
|
|
132
|
+
remedy,
|
|
133
|
+
...extra,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const checks = [
|
|
137
|
+
// 1 — permissionMode declared
|
|
138
|
+
check(
|
|
139
|
+
'`permissionMode` declared',
|
|
140
|
+
permissionModeValid,
|
|
141
|
+
'owner-action',
|
|
142
|
+
`Set orchestration.permissionMode in .ukit/storage/config.json to one of: ${[...VALID_PERMISSION_MODES].join(', ')}.`,
|
|
143
|
+
permissionModeRaw === undefined ? { detail: 'unattended (default)' } : {},
|
|
144
|
+
),
|
|
145
|
+
// 2 — effective approvalMode is yolo
|
|
146
|
+
effectiveApprovalMode === null
|
|
147
|
+
? check(
|
|
148
|
+
'effective approvalMode is `yolo`',
|
|
149
|
+
false,
|
|
150
|
+
'install-repairable',
|
|
151
|
+
INSTALL_REPAIR,
|
|
152
|
+
{
|
|
153
|
+
applicable: false,
|
|
154
|
+
detail: omp.exists
|
|
155
|
+
? 'no tools.approvalMode readable (omp unavailable and YAML value absent)'
|
|
156
|
+
: 'no .omp/config.yml project override',
|
|
157
|
+
},
|
|
158
|
+
)
|
|
159
|
+
: check(
|
|
160
|
+
'effective approvalMode is `yolo`',
|
|
161
|
+
effectiveApprovalMode === 'yolo',
|
|
162
|
+
'install-repairable',
|
|
163
|
+
'Run ukit install to pin tools.approvalMode: yolo in .omp/config.yml.',
|
|
164
|
+
{ detail: `value: ${effectiveApprovalMode} (source: ${approvalSource})` },
|
|
165
|
+
),
|
|
166
|
+
// 3 — eval/bash policy allow
|
|
167
|
+
check(
|
|
168
|
+
"eval/bash policy 'allow'",
|
|
169
|
+
omp.exists && approvalMap.eval === 'allow' && approvalMap.bash === 'allow',
|
|
170
|
+
'install-repairable',
|
|
171
|
+
'Run ukit install to restore tools.approval.eval/bash: allow.',
|
|
172
|
+
omp.exists
|
|
173
|
+
? {}
|
|
174
|
+
: { applicable: false, detail: '.omp/config.yml absent' },
|
|
175
|
+
),
|
|
176
|
+
// 4 — zero prompt policies
|
|
177
|
+
check(
|
|
178
|
+
'zero `prompt` policies',
|
|
179
|
+
promptPolicyCount === 0,
|
|
180
|
+
'install-repairable',
|
|
181
|
+
'Run ukit install to strip `prompt` approvals (unattended mode cannot surface prompts).',
|
|
182
|
+
{
|
|
183
|
+
...(omp.exists ? {} : { applicable: false, detail: '.omp/config.yml absent' }),
|
|
184
|
+
detail: `${promptPolicyCount} prompt policy(ies)`,
|
|
185
|
+
},
|
|
186
|
+
),
|
|
187
|
+
// 5 — project override active
|
|
188
|
+
check(
|
|
189
|
+
'project override active',
|
|
190
|
+
omp.exists,
|
|
191
|
+
'advisory',
|
|
192
|
+
'Run ukit install to materialize the project .omp/config.yml override.',
|
|
193
|
+
omp.exists ? {} : { applicable: false, detail: '.omp/config.yml absent' },
|
|
194
|
+
),
|
|
195
|
+
// 6 — completion loop guidance installed
|
|
196
|
+
check(
|
|
197
|
+
'completion loop guidance installed',
|
|
198
|
+
loopGuidanceInstalled,
|
|
199
|
+
'install-repairable',
|
|
200
|
+
`Run ukit install to add the '${COMPLETION_LOOP_HEADER}' section to CLAUDE.md/AGENTS.md.`,
|
|
201
|
+
instructionDocExists ? {} : { applicable: false, detail: 'no CLAUDE.md/AGENTS.md' },
|
|
202
|
+
),
|
|
203
|
+
// 7 — safety guard enabled
|
|
204
|
+
check(
|
|
205
|
+
'safety guard enabled',
|
|
206
|
+
guardState === 'enabled',
|
|
207
|
+
'advisory',
|
|
208
|
+
!bridgeExists
|
|
209
|
+
? 'Restore .omp/hooks/pre/ukit-bridge.js (run ukit install); guard is degraded.'
|
|
210
|
+
: `Add the missing deny patterns to .omp/config.yml bash.patterns (${missingDenyMatches.length} missing).`,
|
|
211
|
+
{
|
|
212
|
+
...(omp.exists || bridgeExists ? {} : { applicable: false }),
|
|
213
|
+
detail: `guard state: ${guardState}${missingDenyMatches.length > 0 ? ` (${missingDenyMatches.length} deny pattern(s) missing)` : ''}`,
|
|
214
|
+
},
|
|
215
|
+
),
|
|
216
|
+
];
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
checks,
|
|
220
|
+
summary: {
|
|
221
|
+
permissionMode,
|
|
222
|
+
effectiveApprovalMode,
|
|
223
|
+
promptPolicyCount,
|
|
224
|
+
guardState,
|
|
225
|
+
},
|
|
226
|
+
};
|
|
227
|
+
}
|