@ngockhoale/ukit 3.4.75 → 3.4.77

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngockhoale/ukit",
3
- "version": "3.4.75",
3
+ "version": "3.4.77",
4
4
  "description": "Install/update an index-first AI workspace for Claude Code, OpenAI Codex and omp (Oh My Pi).",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -36,6 +36,14 @@
36
36
  "!scripts/measure-decision-gateway.mjs",
37
37
  "!scripts/probe/codex-capability-probe.mjs",
38
38
  "!scripts/install/generate-semantic-engine.mjs",
39
+ "!scripts/install/sync-installed-mirror.mjs",
40
+ "!scripts/test/run-handoff-isolated.mjs",
41
+ "!scripts/docs/render-instructions.mjs",
42
+ "!scripts/index/build-index.mjs",
43
+ "!scripts/index/query-index.mjs",
44
+ "!scripts/index/refresh-index.mjs",
45
+ "!scripts/bug/triage.mjs",
46
+ "!scripts/skill/audit-skill.mjs",
39
47
  "!scripts/release/progress-reporter.mjs",
40
48
  "!scripts/release/publish-guard-core.mjs",
41
49
  "!scripts/audit/c100/attribution-gap.mjs",
@@ -51,10 +59,9 @@
51
59
  "template_user/",
52
60
  "!template_project/**/.smbdelete*",
53
61
  "!template_project/.smbdelete*",
62
+ "!template_project/.ukit/**",
63
+ "!template_project/**/skill-router-state.json",
54
64
  "CHANGELOG.md",
55
- "LICENSE",
56
- "template_project/CLAUDE.md",
57
- "template_project/AGENTS.md",
58
65
  "template_project/.gitignore",
59
66
  "manifests/"
60
67
  ],
@@ -0,0 +1,15 @@
1
+ import { migrateMarkerStore } from '../../core/markerStoreMigration.js';
2
+
3
+ export async function runMarkerStore({ projectRoot, argv = [] }) {
4
+ if (argv[0] !== 'migrate' || argv.includes('--help')) {
5
+ console.log('Usage: ukit marker-store migrate [--apply --writers-stopped]');
6
+ console.log('');
7
+ console.log('Plan (default) or apply the OMP bridge UNKNOWN marker-store migration. Apply needs --writers-stopped');
8
+ console.log('(you closed every OMP/bridge session of this project); UKit verifies, refuses when unverifiable,');
9
+ console.log('never kills processes and keeps the original store in a quarantine directory.');
10
+ return;
11
+ }
12
+ const result = await migrateMarkerStore({ projectRoot, apply: argv.includes('--apply'), attestWritersStopped: argv.includes('--writers-stopped') });
13
+ console.log(JSON.stringify(result, null, 2));
14
+ if (!result.ok) process.exitCode = 2;
15
+ }
package/src/cli/index.js CHANGED
@@ -14,6 +14,7 @@ import { runPlaybook } from './commands/playbook.js';
14
14
  import { runDecision } from './commands/decision.js';
15
15
  import { runSelfImproveCommand } from './commands/selfImprove.js';
16
16
  import { runVm } from './commands/vm.js';
17
+ import { runMarkerStore } from './commands/markerStore.js';
17
18
  const GLOBAL_FLAGS = new Set(['--help', '-h', '--version', '-v']);
18
19
 
19
20
  export async function runCli({ argv, packageRoot, projectRoot, packageVersion }) {
@@ -106,6 +107,11 @@ export async function runCli({ argv, packageRoot, projectRoot, packageVersion })
106
107
  return;
107
108
  }
108
109
 
110
+ if (command === 'marker-store') {
111
+ await runMarkerStore({ projectRoot, argv: commandArgv });
112
+ return;
113
+ }
114
+
109
115
  if (command === 'vm') {
110
116
  await runVm({ projectRoot, argv: commandArgv });
111
117
  return;
@@ -145,6 +151,7 @@ export async function runCli({ argv, packageRoot, projectRoot, packageVersion })
145
151
  console.log(' feedback Record or list wrong-route feedback labels');
146
152
  console.log(' self-improve Run the automatic learn/tune/collect pass now (hooks run it)');
147
153
  console.log(' vm Agent VM driver (list/show/status/shadow-run/evidence)');
154
+ console.log(' marker-store Plan/apply the OMP bridge UNKNOWN marker-store migration (refuses unless writers are verified stopped)');
148
155
  console.log(' update Upgrade the global UKit CLI to the latest version');
149
156
  console.log(' version Show UKit version');
150
157
  console.log('');
@@ -0,0 +1,122 @@
1
+ // Migration of the OMP bridge UNKNOWN repeat-marker store (.ukit/storage/cache/omp-bridge-unknown-markers).
2
+ // Writers are bridge processes with no registry/lock, so a rewrite is only allowed when the owner attests the old
3
+ // writers are stopped AND this tool finds no process with the project as cwd and an unchanged store. Otherwise it
4
+ // refuses. Never kills processes, never deletes: the original store is renamed to a quarantine directory.
5
+ // Every block marker becomes a sticky release marker (a dead writer's block would only ever release on repeat);
6
+ // release markers are kept byte-for-byte, so STOP, session and task isolation (hashed names) are untouched.
7
+ import fs from 'node:fs';
8
+ import path from 'node:path';
9
+ import crypto from 'node:crypto';
10
+ import { spawnSync } from 'node:child_process';
11
+
12
+ export const STORE_REL = path.join('.ukit', 'storage', 'cache', 'omp-bridge-unknown-markers');
13
+ const NAME = /^([0-9a-f]{64})\.([0-9a-f]{64})\.(block|release)$/;
14
+ const refuse = (reason, extra = {}) => ({ ok: false, reason, ...extra });
15
+
16
+ export function scanStore(store) {
17
+ const entries = [];
18
+ const invalid = [];
19
+ for (const name of fs.readdirSync(store)) {
20
+ const m = NAME.exec(name);
21
+ let body = null;
22
+ try { body = JSON.parse(fs.readFileSync(path.join(store, name), 'utf8')); } catch { /* invalid */ }
23
+ const ok = m && body && body.v === 2 && typeof body.p === 'string' && Number.isInteger(body.k);
24
+ if (ok) entries.push({ name, kind: m[3], stem: `${m[1]}.${m[2]}`, text: fs.readFileSync(path.join(store, name), 'utf8') });
25
+ else invalid.push(name);
26
+ }
27
+ return { entries, invalid };
28
+ }
29
+
30
+ // Processes (other than this one) whose cwd is inside the project. null = could not be enumerated.
31
+ export function liveProjectProcesses(projectRoot) {
32
+ const root = fs.realpathSync(projectRoot);
33
+ const inside = (cwd) => cwd === root || cwd.startsWith(root + path.sep);
34
+ const found = [];
35
+ try {
36
+ if (process.platform === 'linux') {
37
+ for (const pid of fs.readdirSync('/proc').filter((n) => /^\d+$/.test(n) && Number(n) !== process.pid)) {
38
+ try { if (inside(fs.readlinkSync(`/proc/${pid}/cwd`))) found.push(pid); } catch { /* exited or not ours */ }
39
+ }
40
+ return found;
41
+ }
42
+ if (process.platform === 'win32') return null;
43
+ const ps = spawnSync('ps', ['-axo', 'pid=,command='], { encoding: 'utf8', timeout: 20000 });
44
+ if (ps.error || ps.status !== 0) return null;
45
+ for (const line of ps.stdout.split('\n')) {
46
+ const m = /^\s*(\d+)\s+(.*)$/.exec(line);
47
+ if (m && Number(m[1]) !== process.pid && Number(m[1]) !== process.ppid && m[2].includes(root) && !m[2].includes('marker-store')) found.push(m[1]);
48
+ }
49
+ const r = spawnSync('lsof', ['-a', '-d', 'cwd', '-Fpn'], { encoding: 'utf8', timeout: 20000 });
50
+ if (r.error || !r.stdout) return null;
51
+ let pid = '';
52
+ for (const line of r.stdout.split('\n')) {
53
+ if (line[0] === 'p') pid = line.slice(1);
54
+ else if (line[0] === 'n' && Number(pid) !== process.pid && Number(pid) !== process.ppid && inside(line.slice(1))) found.push(pid);
55
+ }
56
+ return found;
57
+ } catch { return null; }
58
+ }
59
+
60
+ const fingerprint = (store) => crypto.createHash('sha256').update(fs.readdirSync(store).sort().map((n) => {
61
+ const s = fs.statSync(path.join(store, n));
62
+ return `${n}:${s.size}:${s.mtimeMs}`;
63
+ }).join('\n')).digest('hex');
64
+
65
+ export async function migrateMarkerStore({ projectRoot, apply = false, attestWritersStopped = false, observeMs = 2000, hooks = {} }) {
66
+ const store = path.join(projectRoot, STORE_REL);
67
+ const journal = `${store}.migration.json`;
68
+ const stat = fs.existsSync(store) ? fs.statSync(store) : null;
69
+ const pending = fs.existsSync(journal) ? JSON.parse(fs.readFileSync(journal, 'utf8')) : null;
70
+ if (!pending && !stat) return { ok: true, status: 'no-store' };
71
+ if (!pending && !stat.isDirectory()) return refuse('marker store path is not a directory');
72
+
73
+ const plan = !pending ? scanStore(store) : { entries: [], invalid: [] };
74
+ const blocks = plan.entries.filter((e) => e.kind === 'block').length;
75
+ const summary = { releases: plan.entries.length - blocks, blocks, invalid: plan.invalid.length, tempFiles: plan.invalid.filter((n) => n.includes('.tmp-')).length };
76
+ if (!pending && blocks === 0 && plan.invalid.length === 0) return { ok: true, status: 'already-migrated', ...summary };
77
+ if (!apply) return { ok: true, status: 'plan', ...summary };
78
+
79
+ if (!attestWritersStopped) return refuse('owner attestation missing: close every OMP/bridge session that uses this project, then pass --writers-stopped', summary);
80
+ const live = liveProjectProcesses(projectRoot);
81
+ if (live === null) return refuse('cannot verify that no process is using this project on this platform; migration refused (no automatic reclaim)', summary);
82
+ if (live.length) return refuse(`processes still use this project (pids ${live.join(', ')}); close them yourself, UKit never stops processes`, summary);
83
+
84
+ const id = pending?.id ?? crypto.randomBytes(6).toString('hex');
85
+ const quarantine = `${store}.migrated-${id}`;
86
+ const fresh = `${store}.new-${id}`;
87
+ const step = (name) => { try { hooks.step?.(name); } catch (e) { e.fromHook = true; throw e; } };
88
+
89
+ if (!pending) {
90
+ if (summary.tempFiles) return refuse('writer temp files present (a writer may be active); retry after all sessions are closed', summary);
91
+ const before = fingerprint(store);
92
+ await new Promise((r) => setTimeout(r, observeMs));
93
+ if (fingerprint(store) !== before) return refuse('marker store changed during the observation window; a writer is still active', summary);
94
+ try { fs.mkdirSync(fresh); } catch (error) { return refuse(`cannot create the fresh marker directory (${error.code ?? error.message}); nothing was changed`, summary); }
95
+ // A stem that already has a release keeps it byte-for-byte; its block adds nothing (a release is sticky).
96
+ const released = new Set(plan.entries.filter((e) => e.kind === 'release').map((e) => e.stem));
97
+ for (const e of plan.entries) {
98
+ if (e.kind === 'block' && released.has(e.stem)) continue;
99
+ fs.writeFileSync(path.join(fresh, `${e.stem}.release`), e.text, { flag: 'wx' });
100
+ }
101
+ // Last check before the store is touched: a writer arriving after the observation window aborts the run.
102
+ if (fingerprint(store) !== before) { fs.rmSync(fresh, { recursive: true, force: true }); return refuse('marker store changed just before the swap; a writer is still active', summary); }
103
+ fs.writeFileSync(journal, JSON.stringify({ v: 1, id }), { flag: 'wx' });
104
+ }
105
+ step('journaled');
106
+ // Recovery-safe sequence: quarantine -> fence file at the store path -> unlink fence -> publish new directory.
107
+ // A journal without its fresh directory is only valid after the final rename (quarantine kept, store a directory).
108
+ if (pending && !fs.existsSync(fresh) && !(fs.existsSync(quarantine) && stat?.isDirectory())) return refuse('migration journal has no fresh directory to resume from; nothing was changed, keep the files and contact the maintainer', summary);
109
+ try {
110
+ if (!fs.existsSync(fresh) && fs.existsSync(quarantine)) { fs.rmSync(journal, { force: true }); return { ok: true, status: 'migrated', ...summary, quarantine }; }
111
+ if (fs.existsSync(store) && fs.statSync(store).isDirectory()) { fs.renameSync(store, quarantine); step('quarantined'); }
112
+ if (!fs.existsSync(store)) fs.writeFileSync(store, 'ukit marker store migrating', { flag: 'wx' });
113
+ step('fenced');
114
+ if (fs.statSync(store).isFile()) fs.unlinkSync(store);
115
+ fs.renameSync(fresh, store);
116
+ } catch (error) {
117
+ if (error.fromHook) throw error;
118
+ return refuse(`migration did not complete (${error.code ?? error.message}); rerun the same command to resume, nothing was deleted`, { ...summary, quarantine });
119
+ }
120
+ fs.rmSync(journal, { force: true });
121
+ return { ok: true, status: 'migrated', ...summary, quarantine };
122
+ }