repo-harness 0.35.0 → 0.35.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
@@ -331,6 +331,6 @@ None of these are bundled dependencies; see
331
331
 
332
332
  ## Release & license
333
333
 
334
- - npm: `repo-harness@0.35.0` · workflow stamp `repo-harness@0.35.0+template@0.35.0`
334
+ - npm: `repo-harness@0.35.1` · workflow stamp `repo-harness@0.35.1+template@0.35.1`
335
335
  - History: [`docs/CHANGELOG.md`](docs/CHANGELOG.md)
336
336
  - License: MIT — see [`LICENSE`](LICENSE)
@@ -99,7 +99,8 @@
99
99
  "v0.33.0",
100
100
  "v0.33.1",
101
101
  "v0.33.2",
102
- "v0.34.0"
102
+ "v0.34.0",
103
+ "v0.35.0"
103
104
  ],
104
105
  "packageScripts": {
105
106
  "check:architecture-sync": [
@@ -2315,6 +2316,7 @@
2315
2316
  "sha256:542332264af0204a934af7c5c4001738f21c14e2206b5f893478984885fc29a0",
2316
2317
  "sha256:7edc472a487ed8c2aa12193336bfcc6394c44b2fe4bdf8bac0754779713fbe4e",
2317
2318
  "sha256:7f2c692a1a6be999c9e6bf1e55dd7868174bbc23893cb25b65e04e16e658be8d",
2319
+ "sha256:83a5ab81faf34de117284042b375d67c08a6a9816d7cf94bbcbbfc7af990ec28",
2318
2320
  "sha256:9c788d8ab025ff2bdd7f6f915e4c99b39a09670bf5cf02ab9d7a86466ae5ebb0"
2319
2321
  ],
2320
2322
  "## Sub-agent Delegation": [
@@ -2330,7 +2332,8 @@
2330
2332
  "sha256:6f1c27796bb280cde59f09645b0c7aa0842d9962a6503497647d2a28d6582dfa"
2331
2333
  ],
2332
2334
  "## Test Budget": [
2333
- "sha256:b2a452142e34f036c6323777bd6ec1c3e879d1f7ee3d3ea4d80e4253cde01532"
2335
+ "sha256:b2a452142e34f036c6323777bd6ec1c3e879d1f7ee3d3ea4d80e4253cde01532",
2336
+ "sha256:f95b20ea8d6ccbf4e548482dc8cc625e766f77438a9ef0c765281e248c51338b"
2334
2337
  ]
2335
2338
  }
2336
2339
  },
@@ -1,6 +1,6 @@
1
1
  {
2
- "version": "0.35.0",
3
- "templateVersion": "0.35.0",
2
+ "version": "0.35.1",
3
+ "templateVersion": "0.35.1",
4
4
  "skillName": "repo-harness",
5
5
  "contractId": "tasks-first-harness-v1",
6
6
  "compatibility": {
@@ -2960,14 +2960,15 @@ function isRecord2(value) {
2960
2960
  // src/effects/repo-harness-home.ts
2961
2961
  import { isAbsolute as isAbsolute10, join as join12, resolve as resolve9 } from "path";
2962
2962
  function requireHome(env = process.env) {
2963
- if (!env.HOME || !isAbsolute10(env.HOME))
2963
+ const home = env.HOME || env.USERPROFILE;
2964
+ if (!home || !isAbsolute10(home))
2964
2965
  throw new Error("HOME is required and must be an absolute path");
2965
- return env.HOME;
2966
+ return home;
2966
2967
  }
2967
2968
  var init_repo_harness_home = () => {};
2968
2969
 
2969
2970
  // package.json
2970
- var version = "0.35.0", dependencies;
2971
+ var version = "0.35.1", dependencies;
2971
2972
  var init_package = __esm(() => {
2972
2973
  dependencies = {
2973
2974
  "@botiverse/oar": "0.104.0",
@@ -12814,6 +12815,9 @@ function installSelectionCommand(selection) {
12814
12815
  return selection.length === 0 ? "rh install --no-plugins" : `rh install --plugins ${selection.join(",")}`;
12815
12816
  }
12816
12817
 
12818
+ // src/cli/installer/architecture-selection.ts
12819
+ init_repo_harness_home();
12820
+
12817
12821
  // src/cli/installer/install-state.ts
12818
12822
  init_file_syntax();
12819
12823
  init_repo_harness_home();
@@ -12952,6 +12956,11 @@ function readRecordedInstallState(env = process.env) {
12952
12956
 
12953
12957
  // src/cli/installer/architecture-selection.ts
12954
12958
  function readRecordedSelection(env = process.env) {
12959
+ try {
12960
+ requireHome(env);
12961
+ } catch (error) {
12962
+ return { status: "unreadable", error: new InstallStateError("install_state_home_missing", "", error.message) };
12963
+ }
12955
12964
  try {
12956
12965
  const state = readRecordedInstallState(env);
12957
12966
  return state === null ? { status: "none" } : { status: "recorded", selection: state.selection, plugins: enabledPlugins(state) };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repo-harness",
3
- "version": "0.35.0",
3
+ "version": "0.35.1",
4
4
  "description": "Installs, migrates, audits, and repairs repo-local agentic development harnesses",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -274,6 +274,22 @@ if [[ "$VERSION" != "$PACKAGE_VERSION" ]]; then
274
274
  exit 1
275
275
  fi
276
276
 
277
+ # The published-package readback runs with PATH only, and a plain Windows
278
+ # shell has no HOME: both entries must start without an account home.
279
+ ENV_ONLY_PATH="$(dirname "$(command -v bun)"):/usr/bin:/bin"
280
+ ENV_ONLY_VERSION="$(env -i PATH="$ENV_ONLY_PATH" "$CLI" --version)"
281
+ if [[ "$ENV_ONLY_VERSION" != "$PACKAGE_VERSION" ]]; then
282
+ echo "[tarball-smoke] ERROR: rh --version without HOME returned $ENV_ONLY_VERSION, expected $PACKAGE_VERSION" >&2
283
+ exit 1
284
+ fi
285
+ HOOK_ENV_ONLY_STATUS=0
286
+ env -i PATH="$ENV_ONLY_PATH" "$HOOK" </dev/null >/dev/null 2>"$TMP_DIR/hook-env-only.err" || HOOK_ENV_ONLY_STATUS=$?
287
+ if [[ "$HOOK_ENV_ONLY_STATUS" -ne 2 ]] || ! grep -q '^repo-harness-hook: usage:' "$TMP_DIR/hook-env-only.err"; then
288
+ echo "[tarball-smoke] ERROR: repo-harness-hook without HOME did not reach its usage check (exit $HOOK_ENV_ONLY_STATUS)" >&2
289
+ cat "$TMP_DIR/hook-env-only.err" >&2
290
+ exit 1
291
+ fi
292
+
277
293
  if ! "$CLI" operator serve --help >/dev/null; then
278
294
  echo "[tarball-smoke] ERROR: packaged operator command is unavailable" >&2
279
295
  exit 1
@@ -1,5 +1,6 @@
1
1
  import { declareArchitectureAbsent, registerArchitecturePorts, type ArchitecturePorts } from '../../core/architecture/contracts';
2
2
  import { installSelectionCommand, PLUGIN_IDS, UPDATE_COMMAND, type PluginId, type PluginSelection } from '../../core/skill-surface/plugin-manifest';
3
+ import { requireHome } from '../../effects/repo-harness-home';
3
4
  import { enabledPlugins, installProfileStatePath, InstallStateError, readRecordedInstallState } from './install-state';
4
5
 
5
6
  /**
@@ -18,6 +19,12 @@ export type RecordedSelection =
18
19
  * commands (install, update, doctor, status), not in a hook or command root.
19
20
  */
20
21
  export function readRecordedSelection(env: NodeJS.ProcessEnv = process.env): RecordedSelection {
22
+ // A root without an account home still starts (`--version`, `--help`); a command that needs the selection fails closed with this error.
23
+ try {
24
+ requireHome(env);
25
+ } catch (error) {
26
+ return { status: 'unreadable', error: new InstallStateError('install_state_home_missing', '', (error as Error).message) };
27
+ }
21
28
  try {
22
29
  const state = readRecordedInstallState(env);
23
30
  return state === null ? { status: 'none' } : { status: 'recorded', selection: state.selection, plugins: enabledPlugins(state) };
@@ -543,11 +543,27 @@ export function installProfileTransactionPaths(env: NodeJS.ProcessEnv = process.
543
543
  ];
544
544
  }
545
545
 
546
- /** The script receives only absent paths and current paths of the selected owner. */
547
- export function planSkillSync(plugins: readonly PluginId[], env: NodeJS.ProcessEnv = process.env, catalog = loadSkillSurfaceCatalog()) {
546
+ /**
547
+ * The script receives only absent paths, current paths of the selected owner,
548
+ * and unrecorded links that already name the exact source that the script
549
+ * links there. 0.34.0 linked some facades into every root but recorded one.
550
+ * `sourceRoot` is the exact root string that the writer gets: the targets are
551
+ * built as the writer builds them (`$SOURCE_ROOT/$source`).
552
+ */
553
+ export function planSkillSync(plugins: readonly PluginId[], env: NodeJS.ProcessEnv = process.env, catalog = loadSkillSurfaceCatalog(), sourceRoot?: string) {
548
554
  const { repoHarnessSkills } = catalogMutationPathSkillNames(catalog);
549
555
  const prior = readPathRecords(env);
550
- const declared = new Map<string, { path: string; owner: SurfaceOwner }>();
556
+ const selected = new Set(facadesForSelection(catalog, plugins));
557
+ const linkSources = new Map<string, string>();
558
+ if (sourceRoot !== undefined) {
559
+ linkSources.set('repo-harness', sourceRoot);
560
+ for (const pkg of catalog.packages) {
561
+ if (pkg.kind !== 'facade' || pkg.source === null || !selected.has(pkg.name)) continue;
562
+ const target = `${sourceRoot}/${pkg.source}`;
563
+ if (existsSync(`${target}/SKILL.md`)) linkSources.set(pkg.name, target);
564
+ }
565
+ }
566
+ const declared = new Map<string, { path: string; owner: SurfaceOwner; adopt?: string }>();
551
567
  for (const root of effectiveSkillRoots(plugins, env)) {
552
568
  const names = new Set(repoHarnessSkills);
553
569
  if (statSync(root, { throwIfNoEntry: false })?.isDirectory()) {
@@ -562,12 +578,17 @@ export function planSkillSync(plugins: readonly PluginId[], env: NodeJS.ProcessE
562
578
  const record = prior[key];
563
579
  const owner = ownerForInstallPath(path, env, catalog) ?? (record && isSurfaceOwner(record.owner) ? record.owner : null);
564
580
  if (owner === null || (!ownerEnabled(owner, plugins) && !record)) continue;
565
- if (lstatSync(path, { throwIfNoEntry: false }) && (!record || record.kind === 'user_managed'
581
+ const entry = lstatSync(path, { throwIfNoEntry: false });
582
+ const adopt = linkSources.get(name);
583
+ if (entry && !record && adopt !== undefined && entry.isSymbolicLink() && readlinkSync(path) === adopt) {
584
+ declared.set(key, { path, owner, adopt });
585
+ continue;
586
+ }
587
+ if (entry && (!record || record.kind === 'user_managed'
566
588
  || record.owner !== owner || !pathRecordIsCurrent(key, record))) continue;
567
589
  declared.set(key, { path, owner });
568
590
  }
569
591
  }
570
- const selected = new Set(facadesForSelection(catalog, plugins));
571
592
  const providers = hostSkillPlacements(catalog);
572
593
  const integrations = new Set(catalog.packages.filter(pkg => pkg.kind === 'integration').map(pkg => pkg.name));
573
594
  const roots = syncSkillRoots(env, requireHome(env), plugins);
@@ -40,6 +40,7 @@ export type RecordedInstallSnapshot = Omit<RecordedInstallState, 'previous'>;
40
40
 
41
41
  export type InstallStateErrorCode =
42
42
  | 'install_state_missing'
43
+ | 'install_state_home_missing'
43
44
  | 'install_state_protocol_retired'
44
45
  | 'install_state_invalid'
45
46
  | 'install_state_invalid_ownership'
@@ -1,5 +1,5 @@
1
1
  import { cpSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
2
- import { dirname, join } from 'node:path';
2
+ import { dirname, join, resolve } from 'node:path';
3
3
  import { hashManagedTree, installedCopyTreeOptions, managedTreeEntries, OWNER_MARKER } from '../../effects/managed-tree';
4
4
  import { parseSkillSurfaceCatalog } from '../../core/skill-surface/catalog';
5
5
  import { parsePluginList, PLUGIN_IDS } from '../../core/skill-surface/plugin-manifest';
@@ -27,12 +27,14 @@ export function stageInstalledSkillCopy(source: string, surface: 'canonical-skil
27
27
  export function syncInstalledSkillCopies(sourceRoot: string, env: NodeJS.ProcessEnv, transaction?: string,
28
28
  script = join(sourceRoot, 'scripts', 'sync-codex-installed-copies.sh')) {
29
29
  requireHome(env);
30
+ // The planner and the shell writer build link targets from this one root string; an adopted link must be the link that the writer writes.
31
+ const packageRoot = resolve(sourceRoot);
30
32
  const selection = env.REPO_HARNESS_INSTALL_PLUGINS;
31
33
  const plugins = selection === undefined ? PLUGIN_IDS : selection === '' ? [] : parsePluginList(selection);
32
- const manifest = join(sourceRoot, 'assets/skill-commands/manifest.json');
34
+ const manifest = join(packageRoot, 'assets/skill-commands/manifest.json');
33
35
  const catalog = parseSkillSurfaceCatalog(readFileSync(manifest, 'utf8'), { declared: true });
34
36
  if (catalog.status !== 'valid') throw new Error('invalid skill-surface catalog: ' + manifest);
35
- const { declared, retired } = planSkillSync(plugins, env, catalog.catalog);
37
+ const { declared, retired } = planSkillSync(plugins, env, catalog.catalog, packageRoot);
36
38
  return withHostConfigTransaction(env, transaction, root => {
37
39
  let result: ReturnType<typeof runProcess> | undefined;
38
40
  openHostConfigGate({ env }).delegate(declared, () => {
@@ -42,8 +44,8 @@ export function syncInstalledSkillCopies(sourceRoot: string, env: NodeJS.Process
42
44
  const retiredFile = join(plan, 'retired-paths');
43
45
  atomicWriteFileSync(declaredFile, declared.map(entry => entry.path).join('\n') + '\n', { mode: 0o600 });
44
46
  atomicWriteFileSync(retiredFile, retired.join('\n') + '\n', { mode: 0o600 });
45
- result = runProcess(env.REPO_HARNESS_SYNC_SHELL ?? 'bash', [script], { cwd: sourceRoot, env: { ...env,
46
- BUN_RUNTIME_TRANSPILER_CACHE_PATH: '0', REPO_HARNESS_SOURCE_ROOT: sourceRoot, REPO_HARNESS_SYNC_DECLARED_PATHS_FILE: declaredFile,
47
+ result = runProcess(env.REPO_HARNESS_SYNC_SHELL ?? 'bash', [script], { cwd: packageRoot, env: { ...env,
48
+ BUN_RUNTIME_TRANSPILER_CACHE_PATH: '0', REPO_HARNESS_SOURCE_ROOT: packageRoot, REPO_HARNESS_SYNC_DECLARED_PATHS_FILE: declaredFile,
47
49
  REPO_HARNESS_SYNC_RETIRED_PATHS_FILE: retiredFile } });
48
50
  if (!result.ok) throw new Error(result.stderr || result.error || 'skill sync failed');
49
51
  }, { transaction: root });
@@ -98,6 +98,11 @@ export interface HostConfigPathDeclaration {
98
98
  readonly owner: string;
99
99
  /** As in `HostConfigPathWrite`: the writer may replace a file that rh does not own. */
100
100
  readonly replace?: boolean;
101
+ /**
102
+ * The exact link target that makes an unrecorded link rh's: the gate adopts
103
+ * the path only while no record names it and the link still holds this target.
104
+ */
105
+ readonly adopt?: string;
101
106
  }
102
107
 
103
108
  export interface HostConfigPathOptions {
@@ -171,7 +176,8 @@ export interface HostConfigGate {
171
176
  * Only for out-of-process writers: `run` gets the path-record keys (parent
172
177
  * links followed, leaf kept) and may write them. The gate keeps the files
173
178
  * that `replace` lets the writer replace in the vault before `run`, and
174
- * records each entry that the writer changed after it. A changed path that
179
+ * records each entry that the writer changed after it, and each adopted link
180
+ * also when the writer left it unchanged. A changed path that
175
181
  * rh did not own and that `replace` did not allow is reported and not
176
182
  * recorded.
177
183
  */
@@ -505,11 +511,12 @@ function writeWholePaths(env: NodeJS.ProcessEnv, paths: HostConfigPaths, writes:
505
511
 
506
512
  /**
507
513
  * The out-of-process form of `writeWholePaths`. Every destination is checked
508
- * before `run`: an existing entry must be rh's, or a file under `replace`,
509
- * which goes to the vault first; any other destination stops the call before
510
- * the writer runs. Records follow the writer: a path that it did not change
511
- * keeps the record that the ledger then holds, so the writer's own record
512
- * changes (a `user_managed` claim) stay.
514
+ * before `run`: an existing entry must be rh's, an unrecorded link that holds
515
+ * the declaration's `adopt` target, or a file under `replace`, which goes to
516
+ * the vault first; any other destination stops the call before the writer
517
+ * runs. Records follow the writer: a path that it did not change keeps the
518
+ * record that the ledger then holds, so the writer's own record changes (a
519
+ * `user_managed` claim) stay; an adopted link with no record then is recorded.
513
520
  */
514
521
  function delegateWholePaths(env: NodeJS.ProcessEnv, paths: HostConfigPaths, declared: readonly HostConfigPathDeclaration[],
515
522
  run: (destinations: readonly string[]) => void, options: HostConfigPathOptions): HostConfigDelegateResult {
@@ -519,12 +526,15 @@ function delegateWholePaths(env: NodeJS.ProcessEnv, paths: HostConfigPaths, decl
519
526
  const checked = admitted.map(({ declaration, key, host }) => {
520
527
  const previous = ledger.paths[key];
521
528
  const observed = observePathEntry(key);
522
- const owned = observed === null || ownsEntry(previous, declaration.owner, key);
529
+ // Adoption needs the transaction's preimage: a failure must put the link back.
530
+ const adopted = previous === undefined && options.transaction !== undefined && observed?.type === 'symlink'
531
+ && declaration.adopt !== undefined && observed.target === declaration.adopt;
532
+ const owned = observed === null || adopted || ownsEntry(previous, declaration.owner, key);
523
533
  if (!owned && !(declaration.replace && observed.type === 'file')) {
524
534
  throw observed.type === 'file' || !declaration.replace ? refusal(declaration.path, previous, declaration.owner)
525
535
  : new HostConfigError('host_config_invalid_state', `only a file can be replaced on the user's word: ${declaration.path}`);
526
536
  }
527
- return { declaration, key, host, previous, observed, owned };
537
+ return { declaration, key, host, previous, observed, owned, adopted };
528
538
  });
529
539
  const before = checked.map((entry) => {
530
540
  const backup = entry.owned ? undefined : putVault(paths, readFileSync(entry.key));
@@ -538,9 +548,14 @@ function delegateWholePaths(env: NodeJS.ProcessEnv, paths: HostConfigPaths, decl
538
548
  const records = { ...after.paths };
539
549
  const changed: string[] = [];
540
550
  const invalid: string[] = [];
541
- for (const { declaration, key, host, previous, observed, owned, backup } of before) {
551
+ for (const { declaration, key, host, previous, observed, owned, adopted, backup } of before) {
542
552
  const now = observePathEntry(key);
543
- if (sameCommitted(now, observed)) continue;
553
+ if (adopted && failure !== null) {
554
+ // No record names the link, so the transaction rollback does not see it: a failed writer leaves it as rh found it.
555
+ if (!sameCommitted(now, observed)) restorePreimage(options.transaction!, key);
556
+ continue;
557
+ }
558
+ if (sameCommitted(now, observed) && !(adopted && records[key] === undefined)) continue;
544
559
  // A failed replacement must keep the vault reference, also when the writer removed the entry.
545
560
  if ((backup !== undefined || previous?.kind === 'replaced') && now?.type !== 'file') {
546
561
  records[key] = backup !== undefined
@@ -1000,7 +1015,8 @@ function rollbackWholePaths(paths: HostConfigPaths, before: HostConfigLedger, no
1000
1015
  if (current.kind === 'replaced' && current.backup !== old?.backup) {
1001
1016
  const committed = current.committed as Extract<PathCommitted, { type: 'file' }>;
1002
1017
  replaceTarget(at as HostPath, readVault(paths, current.backup!), { existed: true, sha256: committed.sha256 });
1003
- } else if (!old) removePathEntry(at);
1018
+ } else if (!old && !hasPreimage(transaction, at)) removePathEntry(at);
1019
+ // A link that this transaction adopted has a preimage of itself, so it comes back; a created entry has an absent preimage.
1004
1020
  else if (hasPreimage(transaction, at)) restorePreimage(transaction, at);
1005
1021
  else { records[key] = current; unresolved.push(key); }
1006
1022
  }
@@ -1,10 +1,16 @@
1
1
  // No project imports: `herdr notify install` loads this module through a chain that plain Node also runs.
2
2
  import { isAbsolute, join, resolve } from "node:path";
3
3
 
4
- /** An explicit HOME is required before resolving an account write path. */
4
+ /**
5
+ * An explicit account home is required before resolving an account write path:
6
+ * HOME, or USERPROFILE when HOME is absent (a plain Windows shell sets only
7
+ * USERPROFILE). Never `os.homedir()`: a process without either variable must
8
+ * not reach the real home.
9
+ */
5
10
  export function requireHome(env: NodeJS.ProcessEnv = process.env): string {
6
- if (!env.HOME || !isAbsolute(env.HOME)) throw new Error('HOME is required and must be an absolute path');
7
- return env.HOME;
11
+ const home = env.HOME || env.USERPROFILE;
12
+ if (!home || !isAbsolute(home)) throw new Error('HOME is required and must be an absolute path');
13
+ return home;
8
14
  }
9
15
 
10
16
  /** The single account-level harness home; every host-owned authority store roots here. */