@vaultcompass/conductor 0.2.0 → 0.2.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.md CHANGED
@@ -393,8 +393,8 @@ promotion would want and which the audits do by hand today; and anything that
393
393
  runs inside an agent session or on save, which intent-guard's own optional
394
394
  session hooks already cover.
395
395
 
396
- 0.2.0 is the first release, of a young tool rather than a finished one. The
397
- gates are still the product; this is the convenience layer over them.
396
+ This is a young tool rather than a finished one. The gates are still the
397
+ product; this is the convenience layer over them.
398
398
 
399
399
  ## Design notes
400
400
 
package/dist/init.d.ts CHANGED
@@ -24,7 +24,7 @@ export declare const INTENT_GUARD_HOOK_MARKER = "conductor-managed-pre-commit";
24
24
  * once in a repository somebody else already wired up.
25
25
  */
26
26
  export type HookManager = 'native' | 'husky' | 'lefthook' | 'precommit';
27
- export type ConflictReason = 'not-a-git-repository' | 'foreign-hook' | 'gate-hook' | 'generated-hook' | 'hooks-path-outside-repository' | 'no-manifest' | 'changed-since-init' | 'write-failed';
27
+ export type ConflictReason = 'not-a-git-repository' | 'foreign-hook' | 'gate-hook' | 'generated-hook' | 'hooks-path-outside-repository' | 'no-manifest' | 'manifest-unreadable' | 'changed-since-init' | 'write-failed';
28
28
  export interface InitConflict {
29
29
  path: string;
30
30
  reason: ConflictReason;
package/dist/init.js CHANGED
@@ -52,7 +52,7 @@
52
52
  // directory, which is the state this whole property exists to survive.
53
53
  import { createHash } from 'node:crypto';
54
54
  import { execFileSync } from 'node:child_process';
55
- import { chmodSync, mkdirSync, readFileSync, rmSync, rmdirSync, statSync, writeFileSync, } from 'node:fs';
55
+ import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, rmdirSync, statSync, writeFileSync, } from 'node:fs';
56
56
  import path from 'node:path';
57
57
  import { DEFAULT_STAGE_FOR_ROLE, GATE_ROLES, POLICY_FILE_NAME, PRODUCT_FOR_ROLE } from './policy.js';
58
58
  import { CANDIDATES } from './resolve.js';
@@ -820,7 +820,28 @@ export function revertInit(options) {
820
820
  });
821
821
  return { ok: false, actions, conflicts };
822
822
  }
823
- const manifest = JSON.parse(raw);
823
+ // Not routed through readManifest, which answers null for both a missing
824
+ // file and an unparseable one. Revert has to tell those apart: a missing
825
+ // manifest means there is no record to act on, an unreadable one means the
826
+ // record exists and cannot be trusted, and the second is a file somebody
827
+ // has to look at by hand.
828
+ let manifest;
829
+ try {
830
+ manifest = JSON.parse(raw);
831
+ }
832
+ catch {
833
+ conflicts.push({
834
+ path: MANIFEST_RELATIVE_PATH,
835
+ reason: 'manifest-unreadable',
836
+ guidance: `${MANIFEST_RELATIVE_PATH} will not parse, so there is no usable record of what init ` +
837
+ 'wrote. Nothing was removed and nothing was guessed. Repair the file by hand if you ' +
838
+ 'know what belongs in it. If init ran with --adopt, this file holds the only copy of ' +
839
+ 'the hook that --adopt replaced, so recover that content from it before deleting ' +
840
+ 'anything. Only then delete it and remove the hook and the policy file yourself, and ' +
841
+ 're-run init.',
842
+ });
843
+ return { ok: false, actions, conflicts };
844
+ }
824
845
  const relative = (file) => path.relative(root, file).split(path.sep).join('/');
825
846
  const planned = manifest.files.map((file) => {
826
847
  const current = readIfExists(file.path);
@@ -848,14 +869,10 @@ export function revertInit(options) {
848
869
  return { ok: false, actions, conflicts };
849
870
  }
850
871
  const remaining = [];
851
- let hookRemoved = false;
852
872
  for (const { file, state } of planned) {
853
873
  const rel = relative(file.path);
854
874
  if (state === 'gone') {
855
875
  actions.push({ kind: 'skip', path: rel, detail: 'already gone' });
856
- if (file.kind === 'hook') {
857
- hookRemoved = true;
858
- }
859
876
  continue;
860
877
  }
861
878
  if (state === 'changed' && !force) {
@@ -874,15 +891,24 @@ export function revertInit(options) {
874
891
  path: rel,
875
892
  detail: state === 'changed' ? 'removed (--force, it had changed)' : 'removed',
876
893
  });
877
- if (file.kind === 'hook') {
878
- hookRemoved = true;
879
- }
880
894
  }
881
895
  // Only restore an adopted hook once the umbrella hook that replaced it is
882
896
  // actually gone. Putting the old hook back next to a hook the user has
883
- // since edited would give them two.
897
+ // since edited would give them two at one path, and the edit they asked to
898
+ // keep is the one that gets written over.
899
+ //
900
+ // Read off the world rather than off a flag raised while removing. This
901
+ // used to be a `hookRemoved` boolean, and every path that reached here with
902
+ // a hook in the manifest had already set it, because a hook that changed
903
+ // with no --force returns at the changed-hook check far above. So the flag
904
+ // said what this pass INTENDED and the early return was what actually held
905
+ // the rule, which meant a refactor that flattened that return would satisfy
906
+ // the flag and restore a hook next to a surviving one. existsSync says what
907
+ // is there, which is the thing the rule is about.
908
+ const recordedHooks = planned.filter((entry) => entry.file.kind === 'hook');
909
+ const umbrellaHookGone = recordedHooks.length > 0 && recordedHooks.every((entry) => !existsSync(entry.file.path));
884
910
  let adopted = manifest.adopted;
885
- if (adopted !== null && hookRemoved) {
911
+ if (adopted !== null && umbrellaHookGone) {
886
912
  mkdirSync(path.dirname(adopted.path), { recursive: true });
887
913
  writeFileSync(adopted.path, adopted.content, 'utf8');
888
914
  chmodSync(adopted.path, 0o755);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaultcompass/conductor",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "Umbrella installer and combined report over the independently installable guardrail gates.",
6
6
  "license": "MIT",
@@ -8,7 +8,6 @@
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/vaultcompasshq/conductor.git"
10
10
  },
11
- "packageManager": "pnpm@9.15.9",
12
11
  "engines": {
13
12
  "node": ">=22"
14
13
  },
@@ -19,14 +18,6 @@
19
18
  "dist",
20
19
  "schema"
21
20
  ],
22
- "scripts": {
23
- "build": "tsc -b && chmod +x dist/cli.js",
24
- "pretest": "pnpm build",
25
- "test": "NODE_OPTIONS=--experimental-vm-modules jest",
26
- "typecheck": "tsc -b && tsc --noEmit -p tsconfig.test.json",
27
- "lint": "pnpm check:public-hygiene",
28
- "check:public-hygiene": "node scripts/check-public-hygiene.mjs"
29
- },
30
21
  "dependencies": {
31
22
  "ajv": "^8.17.1",
32
23
  "commander": "^12.1.0",
@@ -39,5 +30,13 @@
39
30
  "jest": "^30.4.2",
40
31
  "ts-jest": "^29.4.12",
41
32
  "typescript": "^5.9.3"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc -b && chmod +x dist/cli.js",
36
+ "pretest": "pnpm build",
37
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest",
38
+ "typecheck": "tsc -b && tsc --noEmit -p tsconfig.test.json",
39
+ "lint": "pnpm check:public-hygiene",
40
+ "check:public-hygiene": "node scripts/check-public-hygiene.mjs"
42
41
  }
43
- }
42
+ }