feat(ms-ai-architect): Sesjon 19 — B3 merge-apply (cross-skill + taksonomi-persist) [skip-docs]
Merge-apply = den tyngste destruktive op-en: eksekver en operatør-godkjent merge_skills-entry → faktisk cross-skill skills/-mutasjon. Tre mekanismer som sanitize/retire ikke trengte: kuratert relokasjon (ikke arkiv), taksonomi-persistering, retire-av-absorbert. - taxonomy.mjs (ny persist): saveTaxonomy (atomisk .tmp+rename, speiler saveDecisions) + ren applyCategoryReassignments (repointer KUN der eier === from; absent/allerede-flyttet = no-op). Lag-0 er normalt read-only; ENESTE writer = gated merge-apply. - applyApprovedAction merge-gren (skill-ops.mjs): re-plan fersk → revalidér (kollisjon → guardrail.ok=false → abort) → flytt absorbed-refs → absorber (moveFile; flyttingen ER bevaringen set-equality beviser) → persister taksonomi-repoint fra FERSK plan (drift-sikker) → arkivér absorbed-SKILL.md FØR rmdir → flipp ledger approved→applied. Description-forsoning forblir MANUELL (planner-kontrakt: apply rører aldri absorber-SKILL.md). archiveMove→moveFile (generisk: arkiv + kuratert flytt). - CLI apply-skill-op.mjs merge <absorber> <absorbed> — lookup via actionKey (merge_skills:<sortert par>); default PREVIEW, --apply = dobbel-gate. TDD, tmpdir-fixtures: 0 ekte skills/-mutasjon. Ny test-skill-ops-merge-apply (7) + 2 taksonomi-tester; fjernet foreldet merge-throws fra S18-fila. Tester: kb-eval 78→84, kb-update 137→139; validate 239 · kb-integrity 192/192 uendret. eval --json deterministisk uendret (K10 eng+infra FAIL, øvrige PASS). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4ac18a76c8
commit
de3a9a483b
6 changed files with 434 additions and 55 deletions
|
|
@ -2,27 +2,30 @@
|
|||
// apply-skill-op.mjs — Spor B / B3 (Sesjon 18) CLI: the DESTRUCTIVE apply-path.
|
||||
//
|
||||
// Executes an operator-APPROVED (status:approved) skill-lifecycle entry from
|
||||
// decisions.json into a real skills/ mutation. Single-skill ops only this
|
||||
// session: sanitize_skill + retire_skill (merge_skills is staged to S19).
|
||||
// decisions.json into a real skills/ mutation: sanitize_skill + retire_skill
|
||||
// (single-skill, S18) and merge_skills (cross-skill, S19). create_skill comes last.
|
||||
//
|
||||
// Two gates, in order: (1) the entry must already be status:approved in the
|
||||
// ledger (the operator's sign-off on a prior `plan-skill-op … --write` dry-run);
|
||||
// (2) this CLI mutates skills/ ONLY with --apply. Without --apply it is a PREVIEW
|
||||
// that re-plans from fresh disk, revalidates (drift-safe), and mutates nothing.
|
||||
//
|
||||
// Apply archives every file under archive/ BEFORE removing it, then flips the
|
||||
// ledger entry approved -> applied. Verify before/after: `git status`.
|
||||
// sanitize/retire archive every file under archive/ BEFORE removing it. merge
|
||||
// RELOCATES the absorbed skill's references under the absorber, persists the
|
||||
// taxonomy ownership repoint, then archives the absorbed SKILL.md + removes its
|
||||
// dir. Apply flips the ledger entry approved -> applied. Verify: `git status`.
|
||||
//
|
||||
// Usage:
|
||||
// node scripts/kb-eval/apply-skill-op.mjs list
|
||||
// node scripts/kb-eval/apply-skill-op.mjs sanitize <skill> [--apply] [--date YYYY-MM-DD]
|
||||
// node scripts/kb-eval/apply-skill-op.mjs retire <skill> [--apply] [--date YYYY-MM-DD]
|
||||
// node scripts/kb-eval/apply-skill-op.mjs merge <absorber> <absorbed> [--apply] [--date YYYY-MM-DD]
|
||||
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { loadTaxonomy } from '../kb-update/lib/taxonomy.mjs';
|
||||
import { loadDecisions, listActions, actionKey } from '../kb-update/lib/decisions-io.mjs';
|
||||
import { applyApprovedAction, SANITIZE_OPERATION, RETIRE_OPERATION } from './lib/skill-ops.mjs';
|
||||
import { applyApprovedAction, SANITIZE_OPERATION, RETIRE_OPERATION, MERGE_OPERATION } from './lib/skill-ops.mjs';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const PLUGIN_ROOT = join(__dirname, '..', '..');
|
||||
|
|
@ -30,13 +33,14 @@ const SKILLS_DIR = join(PLUGIN_ROOT, 'skills');
|
|||
const AGENTS_DIR = join(PLUGIN_ROOT, 'agents');
|
||||
const LEDGER_DATA_DIR = join(__dirname, '..', 'kb-update', 'data');
|
||||
|
||||
const OP_BY_VERB = { sanitize: SANITIZE_OPERATION, retire: RETIRE_OPERATION };
|
||||
const OP_BY_VERB = { sanitize: SANITIZE_OPERATION, retire: RETIRE_OPERATION, merge: MERGE_OPERATION };
|
||||
|
||||
const USAGE =
|
||||
'Usage:\n' +
|
||||
' node scripts/kb-eval/apply-skill-op.mjs list\n' +
|
||||
' node scripts/kb-eval/apply-skill-op.mjs sanitize <skill> [--apply] [--date YYYY-MM-DD]\n' +
|
||||
' node scripts/kb-eval/apply-skill-op.mjs retire <skill> [--apply] [--date YYYY-MM-DD]';
|
||||
' node scripts/kb-eval/apply-skill-op.mjs retire <skill> [--apply] [--date YYYY-MM-DD]\n' +
|
||||
' node scripts/kb-eval/apply-skill-op.mjs merge <absorber> <absorbed> [--apply] [--date YYYY-MM-DD]';
|
||||
|
||||
/** List approved actions awaiting apply (operator's apply queue). */
|
||||
function listApproved() {
|
||||
|
|
@ -54,24 +58,38 @@ function listApproved() {
|
|||
console.log('');
|
||||
}
|
||||
|
||||
function printResult(res, verb, skill, apply) {
|
||||
function printResult(res, verb, label, apply) {
|
||||
const r = res.revalidate;
|
||||
console.log(`\n${verb}_skill — ${apply ? 'APPLY' : 'PREVIEW'}: ${skill}\n`);
|
||||
console.log(`\n${verb} — ${apply ? 'APPLY' : 'PREVIEW'}: ${label}\n`);
|
||||
console.log(`Revalidering (mot fersk disk):`);
|
||||
console.log(` fersk-guardrail-ok=${r.freshOk} drift=${r.drift} => ${r.ok ? 'OK' : 'BLOKKERT'}`);
|
||||
if (r.reason) console.log(` grunn: ${r.reason}`);
|
||||
if (!res.applied) {
|
||||
if (res.preview && r.ok) {
|
||||
const d = res.plan?.diff ?? {};
|
||||
const n = verb === 'sanitize' ? (d.removals?.length ?? 0) : (d.archiveMoves?.length ?? 0);
|
||||
console.log(`\n Ville arkivert+fjernet ${n} fil(er). Kjør på nytt med --apply for å eksekvere.`);
|
||||
if (verb === 'merge') {
|
||||
console.log(
|
||||
`\n Ville flyttet ${d.fileMoves?.length ?? 0} ref-fil(er) -> absorber, reassignet ` +
|
||||
`${d.taxonomyReassignments?.length ?? 0} kategori(er), arkivert absorbed-SKILL.md. ` +
|
||||
`Kjør på nytt med --apply for å eksekvere.`,
|
||||
);
|
||||
} else {
|
||||
const n = verb === 'sanitize' ? (d.removals?.length ?? 0) : (d.archiveMoves?.length ?? 0);
|
||||
console.log(`\n Ville arkivert+fjernet ${n} fil(er). Kjør på nytt med --apply for å eksekvere.`);
|
||||
}
|
||||
}
|
||||
console.log(`\nStatus: INGEN mutasjon utført.${res.preview && r.ok ? '' : ' (revalidering blokkerte eller ingen --apply.)'}\n`);
|
||||
return;
|
||||
}
|
||||
const rep = res.report;
|
||||
console.log(`\nUtført:`);
|
||||
console.log(` arkivert: ${rep.moves} fil(er) -> archive/`);
|
||||
if (rep.op === MERGE_OPERATION) {
|
||||
console.log(` flyttet: ${rep.refMoves} ref-fil(er) -> absorber`);
|
||||
console.log(` taksonomi: ${rep.taxonomyReassignments} kategori(er) reassignet + persistert`);
|
||||
if (rep.archivedSkillMd) console.log(` arkivert: ${rep.archivedSkillMd}`);
|
||||
} else {
|
||||
console.log(` arkivert: ${rep.moves} fil(er) -> archive/`);
|
||||
}
|
||||
if (rep.removedDir) console.log(` fjernet katalog: ${rep.removedDir}`);
|
||||
console.log(` ledger: ${actionKey({ operation_type: rep.op, targets: rep.target })} -> ${rep.ledgerStatus}`);
|
||||
console.log(`\nStatus: APPLIED. Verifiser med 'git status' og re-kjør validate/kb-integrity/kb-eval.\n`);
|
||||
|
|
@ -88,14 +106,31 @@ function main() {
|
|||
const decided_at = dateIdx >= 0 ? args[dateIdx + 1] : new Date().toISOString().slice(0, 10);
|
||||
|
||||
const op = OP_BY_VERB[verb];
|
||||
if (!op || positional.length < 2) {
|
||||
if (!op) {
|
||||
console.error(USAGE);
|
||||
process.exit(2);
|
||||
}
|
||||
const skill = positional[1];
|
||||
|
||||
// Resolve targets + ledger key per op arity (merge takes two skills).
|
||||
let targets, label;
|
||||
if (op === MERGE_OPERATION) {
|
||||
if (positional.length < 3) {
|
||||
console.error(USAGE);
|
||||
process.exit(2);
|
||||
}
|
||||
targets = { absorber: positional[1], absorbed: positional[2] };
|
||||
label = `${targets.absorbed} -> ${targets.absorber}`;
|
||||
} else {
|
||||
if (positional.length < 2) {
|
||||
console.error(USAGE);
|
||||
process.exit(2);
|
||||
}
|
||||
targets = { skill: positional[1] };
|
||||
label = positional[1];
|
||||
}
|
||||
const key = actionKey({ operation_type: op, targets });
|
||||
|
||||
const led = loadDecisions(LEDGER_DATA_DIR);
|
||||
const key = `${op}:${skill}`;
|
||||
const entry = led.actions?.[key];
|
||||
if (!entry) {
|
||||
console.error(`Fant ingen ledger-handling "${key}". Kjør 'apply-skill-op.mjs list' for å se godkjente.`);
|
||||
|
|
@ -106,16 +141,19 @@ function main() {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
// retire + merge both consult the taxonomy (owned-category awareness / repoint).
|
||||
const needsTaxonomy = op === RETIRE_OPERATION || op === MERGE_OPERATION;
|
||||
const res = applyApprovedAction(entry, {
|
||||
pluginRoot: PLUGIN_ROOT,
|
||||
skillsDir: SKILLS_DIR,
|
||||
agentsDir: AGENTS_DIR,
|
||||
dataDir: LEDGER_DATA_DIR,
|
||||
taxonomyDataDir: LEDGER_DATA_DIR,
|
||||
apply,
|
||||
decided_at: apply ? decided_at : null,
|
||||
categorySkill: op === RETIRE_OPERATION ? loadTaxonomy(LEDGER_DATA_DIR).category_skill : undefined,
|
||||
categorySkill: needsTaxonomy ? loadTaxonomy(LEDGER_DATA_DIR).category_skill : undefined,
|
||||
});
|
||||
printResult(res, verb, skill, apply);
|
||||
printResult(res, verb, label, apply);
|
||||
}
|
||||
|
||||
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue