docks-kit 0.20.6 → 0.20.9

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.
Files changed (73) hide show
  1. package/AGENTS.md +19 -17
  2. package/README.md +17 -6
  3. package/cli/docs/command-guards.md +275 -0
  4. package/cli/docs/install.md +23 -12
  5. package/cli/docs/models.md +3 -2
  6. package/cli/docs/modifiers.md +4 -3
  7. package/cli/docs/omp-context.md +9 -2
  8. package/cli/docs/omp-models.md +43 -19
  9. package/cli/docs/plugins.md +12 -7
  10. package/cli/docs/sync-layers.md +28 -9
  11. package/cli/docs/toolchain.md +7 -4
  12. package/cli/src/argv.ts +2 -0
  13. package/cli/src/argvSurface.ts +23 -0
  14. package/cli/src/argvValidate.ts +3 -3
  15. package/cli/src/commands/docs.ts +6 -1
  16. package/cli/src/commands/harnesses.ts +15 -4
  17. package/cli/src/commands/omp.ts +92 -41
  18. package/cli/src/commands/status.ts +15 -0
  19. package/cli/src/commands/sync.ts +6 -6
  20. package/cli/src/commands/toolchain.ts +8 -2
  21. package/cli/src/commands/update.ts +51 -10
  22. package/cli/src/engine-native/DESIGN.md +56 -35
  23. package/cli/src/engine-native/atomicWrite.ts +64 -0
  24. package/cli/src/engine-native/claudeLsp.ts +9 -2
  25. package/cli/src/engine-native/claudeOptionalPlugins.ts +19 -6
  26. package/cli/src/engine-native/claudePluginPasses.ts +77 -21
  27. package/cli/src/engine-native/claudeRemovals.ts +245 -57
  28. package/cli/src/engine-native/claudeRetired.ts +1 -1
  29. package/cli/src/engine-native/claudeSettings.ts +46 -19
  30. package/cli/src/engine-native/claudeSettingsModifiers.ts +3 -3
  31. package/cli/src/engine-native/claudeSync.ts +18 -16
  32. package/cli/src/engine-native/codexConfig.ts +72 -12
  33. package/cli/src/engine-native/codexHooks.ts +3 -3
  34. package/cli/src/engine-native/codexPaths.ts +14 -0
  35. package/cli/src/engine-native/codexPlugins.ts +48 -23
  36. package/cli/src/engine-native/codexStatus.ts +2 -1
  37. package/cli/src/engine-native/codexSync.ts +33 -7
  38. package/cli/src/engine-native/codexToml.ts +161 -35
  39. package/cli/src/engine-native/deps.ts +4 -9
  40. package/cli/src/engine-native/engineCtx.ts +42 -14
  41. package/cli/src/engine-native/exec.ts +28 -1
  42. package/cli/src/engine-native/harnesses.ts +32 -8
  43. package/cli/src/engine-native/index.ts +6 -1
  44. package/cli/src/engine-native/kitDb.ts +12 -6
  45. package/cli/src/engine-native/liveModels.ts +2 -1
  46. package/cli/src/engine-native/models.ts +6 -3
  47. package/cli/src/engine-native/modes.ts +15 -10
  48. package/cli/src/engine-native/ompFileDeploy.ts +3 -4
  49. package/cli/src/engine-native/ompMarketplace.ts +9 -7
  50. package/cli/src/engine-native/ompOverlay.ts +37 -13
  51. package/cli/src/engine-native/ompPaths.ts +20 -9
  52. package/cli/src/engine-native/ompPlugins.ts +16 -15
  53. package/cli/src/engine-native/ompRemovals.ts +125 -30
  54. package/cli/src/engine-native/ompSync.ts +11 -6
  55. package/cli/src/engine-native/ompYaml.ts +96 -6
  56. package/cli/src/engine-native/os/darwin.ts +2 -0
  57. package/cli/src/engine-native/os/linux.ts +1 -0
  58. package/cli/src/engine-native/os/posix.ts +17 -5
  59. package/cli/src/engine-native/os/types.ts +2 -2
  60. package/cli/src/engine-native/os/windows.ts +24 -16
  61. package/cli/src/engine-native/skillsInstall.ts +10 -5
  62. package/cli/src/engine-native/skillsLinks.ts +14 -1
  63. package/cli/src/engine-native/skillsManifest.ts +20 -0
  64. package/cli/src/engine-native/skillsPrune.ts +33 -26
  65. package/cli/src/engine-native/skillsSync.ts +6 -3
  66. package/cli/src/engine-native/syncDispatch.ts +32 -18
  67. package/cli/src/engine.ts +29 -3
  68. package/cli/src/generated/sotPayload.ts +14 -14
  69. package/cli/src/main.ts +10 -3
  70. package/cli/src/manifests.ts +29 -11
  71. package/docks-kit +6 -3
  72. package/docks-kit.ps1 +22 -11
  73. package/package.json +1 -1
@@ -6,6 +6,7 @@ import { p } from "./exec";
6
6
  import { readFileSync } from "node:fs";
7
7
  import { payloadText } from "../payload";
8
8
 
9
+ import { codexHome } from "./codexPaths";
9
10
  import { syncClaudeModel } from "./claudeSettingsModifiers";
10
11
  import { syncCodexModel } from "./codexToml";
11
12
  import type { Ctx } from "./index";
@@ -14,7 +15,7 @@ import { printModels, validateClaudeModel, validateCodexModel } from "./models";
14
15
  import { defaultLiveInputs, resolveCatalog } from "./liveModels";
15
16
  import { bunBootstrap } from "./bun";
16
17
  import { upgradeLspServers } from "./claudeLsp";
17
- import { installedVersion, outdatedReport, present, report } from "./toolchain";
18
+ import { belowFloor, field, installedVersion, outdatedReport, present, report } from "./toolchain";
18
19
  import { topLevelTomlString } from "../manifests";
19
20
 
20
21
  export async function modeModel(ctx: Ctx, args: ReadonlyArray<string>): Promise<number> {
@@ -51,14 +52,14 @@ export async function modeModel(ctx: Ctx, args: ReadonlyArray<string>): Promise<
51
52
  echo(`deployed: ${jsonModelText(result.data)}`);
52
53
  echo(`SoT: ${jsonModelText(payloadText("SoT/.claude/settings.json"))}`);
53
54
  } else {
54
- const deployed = p(ctx.home, ".codex", "config.toml");
55
+ const deployed = p(codexHome(ctx.home), "config.toml");
55
56
  const result = readConfig(deployed);
56
57
  if (result.kind === "missing") {
57
- warn("~/.codex/config.toml missing");
58
+ warn(`${deployed} missing`);
58
59
  return 0;
59
60
  }
60
61
  if (result.kind === "read-error") {
61
- err(`Failed to read ~/.codex/config.toml: ${String(result.error)}`);
62
+ err(`Failed to read ${deployed}: ${String(result.error)}`);
62
63
  return 1;
63
64
  }
64
65
  echo(`deployed: ${topLevelTomlString(result.data, "model") ?? ""}`);
@@ -115,10 +116,10 @@ function jsonModelText(text: string): string {
115
116
  }
116
117
 
117
118
  const TOOLCHAIN_USAGE =
118
- "Usage: toolchain [check|ensure <tool>|outdated [--refresh]|upgrade [--dry-run]]";
119
+ "Usage: toolchain [check|ensure <tool> [--dry-run]|outdated [--refresh]|upgrade [--dry-run]]";
119
120
 
120
121
  export async function modeToolchain(ctx: Ctx, args: ReadonlyArray<string>): Promise<number> {
121
- const { echo, err, verbose } = ctx.services.logger;
122
+ const { echo, err, verbose, warn } = ctx.services.logger;
122
123
  const words = args.filter((arg) => !arg.startsWith("--"));
123
124
  const op = words[0] ?? "check";
124
125
  const tool = words[1] ?? "";
@@ -158,11 +159,15 @@ export async function modeToolchain(ctx: Ctx, args: ReadonlyArray<string>): Prom
158
159
  if (alreadyInstalled) {
159
160
  // A present tool whose --version cannot be read reports `unknown` in the
160
161
  // doctor table; keep the same vocabulary rather than an empty pair of
161
- // parentheses.
162
+ // parentheses. `ensure` never upgrades (policy `present`), but a Bun
163
+ // below the kit floor is a real problem, so it warns on every run.
162
164
  const probed = await installedVersion(ctx, "bun");
163
- const installed = probed === "" ? "version unknown" : probed;
164
- if (ctx.dryRun) echo(`[dry-run] bun up to date (${installed})`);
165
- else verbose(`bun up to date (${installed})`);
165
+ const floor = field("bun", "floor");
166
+ const label = probed === "" ? "version unknown" : probed;
167
+ if (belowFloor(probed, floor)) {
168
+ warn(`bun ${probed} is below the kit floor ${floor}; run bun upgrade`);
169
+ } else if (ctx.dryRun) echo(`[dry-run] bun present (${label})`);
170
+ else verbose(`bun present (${label})`);
166
171
  }
167
172
  return 0;
168
173
  }
@@ -9,12 +9,12 @@ import {
9
9
  existsSync,
10
10
  mkdirSync,
11
11
  readFileSync,
12
- renameSync,
13
12
  writeFileSync,
14
13
  } from "node:fs";
15
14
  import { basename } from "node:path";
16
15
 
17
16
  import { payloadDisplayPath, payloadText, type PayloadPath } from "../payload";
17
+ import { replaceFile } from "./atomicWrite";
18
18
  import type { Ctx } from "./index";
19
19
 
20
20
  export type OmpTextPayloadPath = Extract<PayloadPath, `SoT/.omp/${string}`>;
@@ -103,9 +103,8 @@ export function syncMergedYaml(
103
103
  }
104
104
 
105
105
  backupPrivateFile(target);
106
- writePrivateFile(`${target}.tmp`, merged);
107
- renameSync(`${target}.tmp`, target);
108
- chmodSync(target, 0o600);
106
+ // replaceFile writes through a symlinked config.yml or models.yml, so the link stays.
107
+ replaceFile(target, merged, { mode: 0o600 });
109
108
  change(`omp ${name} merged (backup at ${name}.bak)`);
110
109
  ctx.nextStepTriggers.ompRestart = true;
111
110
  }
@@ -54,6 +54,15 @@ export async function syncMarketplace(
54
54
  const adoptable =
55
55
  !registered && legacyRegistryFile !== undefined && registryHasDocks(legacyRegistryFile);
56
56
 
57
+ // syncPlugins owns the single skip message for both missing CLIs, and it runs
58
+ // right after this pass. Without omp no marketplace command can run at all,
59
+ // and without git a marketplace clone cannot resolve, so both are deliberate
60
+ // skips: return silently instead of spawning and recording a failure. The
61
+ // probes run before the dry-run branch, so a dry run previews only the
62
+ // commands that a real run on this host would run.
63
+ if (ctx.services.deps.probe("omp").state === "missing") return;
64
+ if (ctx.services.deps.probe("git").state === "missing") return;
65
+
57
66
  if (ctx.dryRun) {
58
67
  if (adoptable) {
59
68
  echo(
@@ -66,13 +75,6 @@ export async function syncMarketplace(
66
75
  return;
67
76
  }
68
77
 
69
- // syncPlugins owns the single skip message for both missing CLIs, and it runs
70
- // right after this pass. Without omp no marketplace command can run at all,
71
- // and without git a marketplace clone cannot resolve, so both are deliberate
72
- // skips: return silently instead of spawning and recording a failure.
73
- if (ctx.services.deps.probe("omp").state === "missing") return;
74
- if (ctx.services.deps.probe("git").state === "missing") return;
75
-
76
78
  if (!registered && !adoptable) {
77
79
  progress("Registering omp docks marketplace...");
78
80
  const result = await spawnProcess("omp", ["plugin", "marketplace", "add", MARKETPLACE_SOURCE], {
@@ -1,7 +1,13 @@
1
1
  /**
2
2
  * Run overlay for `docks-kit omp`. The overlay merges over the deployed omp
3
- * config for one run only, so every key that can cause paid spend is set here
4
- * and every other key falls through to the deployed paid config.
3
+ * config for one run only. It sets the 16 roles in ROLE_ORDER to the free
4
+ * model and empties the 13 retry chains in FALLBACK_ORDER. omp merges the
5
+ * overlay key by key, so each deployed retry chain that is not in
6
+ * FALLBACK_ORDER stays as deployed. The `web` role and its retry chain are
7
+ * not in the overlay, so the deployed web-search provider order applies, and
8
+ * that order can include a paid chat model. A deployed `plan`, `slow`, or
9
+ * `designer` chain also stays and can name a paid model. Every other key
10
+ * falls through to the deployed config.
5
11
  */
6
12
  import { createHash } from "node:crypto";
7
13
  import type { OmpSessionModel } from "./harnesses";
@@ -24,20 +30,26 @@ export const THINKING_LADDER: ReadonlyArray<string> = [
24
30
  ];
25
31
 
26
32
  /**
27
- * One overlay file per model, so a second launcher on another model cannot
28
- * rewrite the file a running session still reads. A selector carries a slash
29
- * and may carry other characters a host rejects in a file name, so unsafe
30
- * characters become hyphens. That mapping alone is not injective, because
31
- * `a/b` and `a-b` both fold to `a-b`, so a digest of the exact selector keeps
32
- * two distinct models on two distinct files.
33
+ * One overlay file per distinct model and level combination, so a second
34
+ * launcher cannot rewrite the file a running session still reads. omp
35
+ * reloads a changed overlay mid-session, so the digest covers the exact
36
+ * rendered overlay: the selector, both levels, and every rendered key. A
37
+ * selector carries a slash and may carry other characters a host rejects in
38
+ * a file name, so unsafe characters in the readable prefix become hyphens.
33
39
  */
34
- export function overlayFileName(selector: string): string {
35
- const safe = selector.replace(/[^A-Za-z0-9._-]/g, "-");
36
- const digest = createHash("sha256").update(selector).digest("hex").slice(0, 8);
40
+ export function overlayFileName(model: OmpSessionModel): string {
41
+ const safe = model.selector.replace(/[^A-Za-z0-9._-]/g, "-");
42
+ const digest = createHash("sha256").update(renderFreeOverlay(model)).digest("hex").slice(0, 8);
37
43
  return `omp-free-${safe}-${digest}.yml`;
38
44
  }
39
45
 
40
- /** Role keys in the order used by SoT/.omp/config.yml for readable diffs. */
46
+ /**
47
+ * Role keys in the order used by SoT/.omp/config.yml for readable diffs. The
48
+ * SoT does not set `memory` and `judge`, so they come last. An unset role
49
+ * falls back to the omp built-in priority chain, which can name a paid model.
50
+ * The `web` role is left out on purpose, so the deployed web-search provider
51
+ * order applies.
52
+ */
41
53
  const ROLE_ORDER: ReadonlyArray<string> = [
42
54
  "smol",
43
55
  "advisor",
@@ -53,9 +65,15 @@ const ROLE_ORDER: ReadonlyArray<string> = [
53
65
  "switch_fable",
54
66
  "astra",
55
67
  "reviewer",
68
+ "memory",
69
+ "judge",
56
70
  ];
57
71
 
58
- /** Retry chain keys in the order used by SoT/.omp/config.yml. */
72
+ /**
73
+ * Retry chain keys in the order used by SoT/.omp/config.yml, then `memory` and
74
+ * `judge`. An explicit empty chain stops omp from using its built-in priority
75
+ * chain. The `web` chain is left out, so the deployed chain applies.
76
+ */
59
77
  const FALLBACK_ORDER: ReadonlyArray<string> = [
60
78
  "default",
61
79
  "advisor",
@@ -68,6 +86,8 @@ const FALLBACK_ORDER: ReadonlyArray<string> = [
68
86
  "fable",
69
87
  "astra",
70
88
  "reviewer",
89
+ "memory",
90
+ "judge",
71
91
  ];
72
92
 
73
93
  /**
@@ -91,6 +111,10 @@ export function parseFreeModels(catalogJson: unknown): ReadonlyArray<CatalogMode
91
111
  if (typeof cost !== "object" || cost === null || Array.isArray(cost)) continue;
92
112
  const charges = cost as Record<string, unknown>;
93
113
  if (charges["input"] !== 0 || charges["output"] !== 0) continue;
114
+ // omp prices a usage-billed or plan-included model at zero, so a zero
115
+ // cost is not proof of a free model. Older omp output has no status.
116
+ const status = record["pricingStatus"];
117
+ if (typeof status === "string" && status !== "free" && status !== "unknown") continue;
94
118
  const rawName = record["name"];
95
119
  const name = typeof rawName === "string" && rawName.length > 0 ? rawName : selector;
96
120
  const rawLevels = record["thinking"];
@@ -8,7 +8,7 @@
8
8
  * dry run stays free of omp subcommands.
9
9
  */
10
10
  import { existsSync } from "node:fs";
11
- import { isAbsolute, resolve } from "node:path";
11
+ import { resolve } from "node:path";
12
12
 
13
13
  import { p } from "./exec";
14
14
 
@@ -51,11 +51,6 @@ function normalizeProfile(value: string | undefined): string | undefined {
51
51
  return name;
52
52
  }
53
53
 
54
- /** Upstream applies `path.resolve` to PI_CODING_AGENT_DIR, so cwd anchors a relative value. */
55
- function resolveAgentOverride(value: string): string {
56
- return isAbsolute(value) ? value : resolve(process.cwd(), value);
57
- }
58
-
59
54
  export function ompPaths({ home, env, platform }: OmpPathInputs): OmpPaths {
60
55
  // OMP_PROFILE wins whenever it is defined, including when explicitly empty;
61
56
  // PI_PROFILE is only the legacy fallback.
@@ -72,12 +67,28 @@ export function ompPaths({ home, env, platform }: OmpPathInputs): OmpPaths {
72
67
  const configRoot = profile === undefined ? baseRoot : p(baseRoot, "profiles", profile);
73
68
 
74
69
  // A named profile derives its own agent directory and ignores the override.
70
+ // The default profile also ignores an override that equals the agent
71
+ // directory of the PI_PROFILE profile, because omp exports that value in a
72
+ // profile session. Upstream compares the raw string here.
73
+ // Upstream applies `path.resolve` to a used override. The call anchors a
74
+ // relative value at cwd and normalizes an absolute value.
75
75
  const agentOverride = env["PI_CODING_AGENT_DIR"];
76
76
  const defaultAgentDir = p(configRoot, "agent");
77
+ const legacyProfile = normalizeProfile(env["PI_PROFILE"]);
78
+ const overrideIgnored =
79
+ profile === undefined &&
80
+ legacyProfile !== undefined &&
81
+ agentOverride === p(baseRoot, "profiles", legacyProfile, "agent");
82
+ const resolvedOverride =
83
+ profile === undefined && !overrideIgnored && agentOverride !== undefined && agentOverride !== ""
84
+ ? resolve(agentOverride)
85
+ : undefined;
86
+ // resolve() rewrites separators on Windows, so an override that names the
87
+ // default directory is compared in resolved form and keeps the default path.
77
88
  const agentDir =
78
- profile === undefined && agentOverride !== undefined && agentOverride !== ""
79
- ? resolveAgentOverride(agentOverride)
80
- : defaultAgentDir;
89
+ resolvedOverride === undefined || resolvedOverride === resolve(defaultAgentDir)
90
+ ? defaultAgentDir
91
+ : resolvedOverride;
81
92
 
82
93
  return {
83
94
  profile,
@@ -76,21 +76,6 @@ async function runPluginCommand(
76
76
  export async function syncPlugins(ctx: Ctx): Promise<number> {
77
77
  const { change, clearProgress, echo, progress, verbose, warn } = ctx.services.logger;
78
78
 
79
- if (ctx.dryRun) {
80
- const piIntercomPin = field("pi-intercom", "verified");
81
- for (const pluginId of MARKETPLACE_PLUGIN_IDS) {
82
- echo(`[dry-run] omp plugin install --scope user ${pluginId}`);
83
- }
84
- if (piIntercomPin === "") {
85
- warn(
86
- "pi-intercom install skipped because SoT/toolchain.json has no verified pi-intercom pin",
87
- );
88
- } else {
89
- echo(`[dry-run] omp install pi-intercom@${piIntercomPin}`);
90
- }
91
- return 0;
92
- }
93
-
94
79
  if (ctx.services.deps.probe("omp").state === "missing") {
95
80
  ctx.services.deps.warnMissing(
96
81
  "omp",
@@ -107,6 +92,22 @@ export async function syncPlugins(ctx: Ctx): Promise<number> {
107
92
  );
108
93
  return 0;
109
94
  }
95
+
96
+ if (ctx.dryRun) {
97
+ const piIntercomPin = field("pi-intercom", "verified");
98
+ for (const pluginId of MARKETPLACE_PLUGIN_IDS) {
99
+ echo(`[dry-run] omp plugin install --scope user ${pluginId}`);
100
+ }
101
+ if (piIntercomPin === "") {
102
+ warn(
103
+ "pi-intercom install skipped because SoT/toolchain.json has no verified pi-intercom pin",
104
+ );
105
+ } else {
106
+ echo(`[dry-run] omp install pi-intercom@${piIntercomPin}`);
107
+ }
108
+ return 0;
109
+ }
110
+
110
111
  const piIntercomPin = field("pi-intercom", "verified");
111
112
 
112
113
  progress("Checking installed omp plugins...");
@@ -1,16 +1,19 @@
1
1
  /**
2
- * EngineNative `sync omp` retired-key pruning. `ompYaml.ts mergeOmpConfig` and
2
+ * EngineNative `sync omp` retired-entry pruning. `ompYaml.ts mergeOmpConfig` and
3
3
  * `mergeOmpModels` are additive: their `mergeMappings, deployed-key retention
4
- * loop` returns every deployed key absent from the SoT to the merged result.
5
- * Removing a key from `SoT/.omp/config.yml` or `SoT/.omp/models.yml` therefore
6
- * never removes it from the deployed file. This pass force-prunes an inventory
7
- * of retired kit-owned keys on every sync, without `--reconcile`. Message
8
- * strings and prune semantics are part of the contract.
4
+ * loop` returns every deployed key absent from the SoT to the merged result,
5
+ * and `mergeBashPatterns` keeps a deployed rule the SoT stops shipping as a user
6
+ * rule. Removing a key or rule from `SoT/.omp/config.yml` or
7
+ * `SoT/.omp/models.yml` therefore never removes it from the deployed file. This
8
+ * pass force-prunes an inventory of retired kit-owned keys and rules on every
9
+ * sync, without `--reconcile`. Message strings and prune semantics are part of
10
+ * the contract.
9
11
  */
10
12
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
11
13
  import { isDeepStrictEqual } from "node:util";
12
- import { isMap, isScalar, parseDocument, type YAMLMap } from "yaml";
14
+ import { isMap, isScalar, isSeq, parseDocument, type YAMLMap } from "yaml";
13
15
  import type { Ctx } from "./index";
16
+ import { bashPatternKey, bashRuleKey } from "./ompYaml";
14
17
 
15
18
  type RetiredScalar = string | number | boolean;
16
19
 
@@ -79,8 +82,74 @@ const OMP_RETIRED_MODEL_BLOCKS: ReadonlyArray<readonly [string, unknown]> = [
79
82
  ],
80
83
  ];
81
84
 
85
+ /**
86
+ * `bash.patterns` rules the kit used to deploy, each with the exact match and
87
+ * approval it deployed. A deployed rule is pruned only while it equals one of
88
+ * these under the merge's rule normalization, so a user rule with another match
89
+ * or approval survives.
90
+ *
91
+ * The kit prompted before every file removal: rm and its wrappers, find
92
+ * -delete, git rm, git worktree remove, and gio trash. The three `-- *` allows
93
+ * existed only to skip those prompts.
94
+ */
95
+ const OMP_RETIRED_BASH_RULES: ReadonlyArray<{
96
+ readonly match: string;
97
+ readonly approval: "allow" | "prompt";
98
+ }> = [
99
+ { match: "git rm -- *", approval: "allow" },
100
+ { match: "git worktree remove -- *", approval: "allow" },
101
+ { match: "gio trash -- *", approval: "allow" },
102
+ { match: "rm", approval: "prompt" },
103
+ { match: "rm *", approval: "prompt" },
104
+ { match: "*/rm", approval: "prompt" },
105
+ { match: "*/rm *", approval: "prompt" },
106
+ { match: "xargs rm", approval: "prompt" },
107
+ { match: "xargs rm *", approval: "prompt" },
108
+ { match: "xargs * rm", approval: "prompt" },
109
+ { match: "xargs * rm *", approval: "prompt" },
110
+ { match: "env * rm", approval: "prompt" },
111
+ { match: "env * rm *", approval: "prompt" },
112
+ { match: "command rm", approval: "prompt" },
113
+ { match: "command rm *", approval: "prompt" },
114
+ { match: "exec rm", approval: "prompt" },
115
+ { match: "exec rm *", approval: "prompt" },
116
+ { match: "nohup rm", approval: "prompt" },
117
+ { match: "nohup rm *", approval: "prompt" },
118
+ { match: "nice rm", approval: "prompt" },
119
+ { match: "nice rm *", approval: "prompt" },
120
+ { match: "nice * rm", approval: "prompt" },
121
+ { match: "nice * rm *", approval: "prompt" },
122
+ { match: "time rm", approval: "prompt" },
123
+ { match: "time rm *", approval: "prompt" },
124
+ { match: "timeout * rm", approval: "prompt" },
125
+ { match: "timeout * rm *", approval: "prompt" },
126
+ { match: "stdbuf * rm", approval: "prompt" },
127
+ { match: "stdbuf * rm *", approval: "prompt" },
128
+ { match: "find -delete*", approval: "prompt" },
129
+ { match: "find * -delete*", approval: "prompt" },
130
+ { match: "find -exec*rm *", approval: "prompt" },
131
+ { match: "find * -exec*rm *", approval: "prompt" },
132
+ { match: "git rm", approval: "prompt" },
133
+ { match: "git rm *", approval: "prompt" },
134
+ { match: "git worktree remove", approval: "prompt" },
135
+ { match: "git worktree remove *", approval: "prompt" },
136
+ { match: "gio trash", approval: "prompt" },
137
+ { match: "gio trash *", approval: "prompt" },
138
+ ];
139
+
140
+ /** Normalized rule key to the name a prune message reports. */
141
+ const OMP_RETIRED_BASH_KEYS: ReadonlyMap<string, string> = new Map(
142
+ OMP_RETIRED_BASH_RULES.map(({ match, approval }) => [
143
+ bashRuleKey(match, approval),
144
+ `bash.patterns "${match}" (${approval})`,
145
+ ]),
146
+ );
147
+
82
148
  type RetiredEntry = readonly [string, (node: unknown) => boolean];
83
149
 
150
+ /** Removes retired content from a deployed root mapping and names each removal. */
151
+ type Pruner = (root: YAMLMap) => Array<string>;
152
+
84
153
  function indexOfKey(mapping: YAMLMap, key: string): number {
85
154
  return mapping.items.findIndex((pair) => {
86
155
  const name: unknown = pair.key;
@@ -154,12 +223,39 @@ function deletePath(
154
223
  return true;
155
224
  }
156
225
 
157
- /** Prunes each matching retired entry from one deployed omp YAML file. */
226
+ /** Pruner that deletes each matching retired key path. */
227
+ function retiredKeys(entries: ReadonlyArray<RetiredEntry>): Pruner {
228
+ return (root) => {
229
+ const pruned: Array<string> = [];
230
+ for (const [path, matches] of entries) {
231
+ if (deletePath(root, path.split("."), matches)) pruned.push(path);
232
+ }
233
+ return pruned;
234
+ };
235
+ }
236
+
237
+ /** Deletes each retired kit rule from the deployed `bash.patterns` sequence. */
238
+ const retiredBashRules: Pruner = (root) => {
239
+ const bash: unknown = root.get("bash");
240
+ const patterns: unknown = isMap(bash) ? bash.get("patterns") : undefined;
241
+ if (!isSeq(patterns)) return [];
242
+ const pruned: Array<string> = [];
243
+ patterns.items = patterns.items.filter((item) => {
244
+ const key = bashPatternKey(item);
245
+ const name = key === undefined ? undefined : OMP_RETIRED_BASH_KEYS.get(key);
246
+ if (name === undefined) return true;
247
+ pruned.push(name);
248
+ return false;
249
+ });
250
+ return pruned;
251
+ };
252
+
253
+ /** Applies each pruner to one deployed omp YAML file. */
158
254
  function pruneRetired(
159
255
  ctx: Ctx,
160
256
  file: string,
161
257
  label: string,
162
- entries: ReadonlyArray<RetiredEntry>,
258
+ pruners: ReadonlyArray<Pruner>,
163
259
  ): number {
164
260
  const { change, echo, verbose, warn } = ctx.services.logger;
165
261
  if (!existsSync(file)) return 0;
@@ -167,19 +263,16 @@ function pruneRetired(
167
263
  const doc = parseDocument(readFileSync(file, "utf8"));
168
264
  const parseError = doc.errors[0];
169
265
  if (parseError !== undefined) {
170
- warn(`omp ${label} unreadable, retired keys not pruned: ${parseError.message}`);
266
+ warn(`omp ${label} unreadable, retired entries not pruned: ${parseError.message}`);
171
267
  return 0;
172
268
  }
173
269
  const contents = doc.contents;
174
270
  if (!isMap(contents)) return 0;
175
271
 
176
- const pruned: Array<string> = [];
177
- for (const [path, matches] of entries) {
178
- if (deletePath(contents, path.split("."), matches)) pruned.push(path);
179
- }
272
+ const pruned = pruners.flatMap((prune) => prune(contents));
180
273
 
181
274
  if (pruned.length === 0) {
182
- verbose(`omp ${label} carries no retired keys`);
275
+ verbose(`omp ${label} carries no retired entries`);
183
276
  return 0;
184
277
  }
185
278
  if (ctx.dryRun) {
@@ -187,30 +280,32 @@ function pruneRetired(
187
280
  return pruned.length;
188
281
  }
189
282
  writeFileSync(file, String(doc));
190
- change(`omp ${label} pruned ${pruned.length} retired key(s): ${pruned.join(", ")}`);
283
+ change(`omp ${label} pruned ${pruned.length} retired entr(ies): ${pruned.join(", ")}`);
191
284
  return pruned.length;
192
285
  }
193
286
 
194
- /** Prunes retired kit-owned keys from a deployed omp config.yml. */
287
+ /** Prunes retired kit-owned keys and bash rules from a deployed omp config.yml. */
195
288
  export function syncOmpRemovals(ctx: Ctx, configFile: string): number {
196
289
  return pruneRetired(ctx, configFile, "config.yml", [
197
- ...OMP_RETIRED_VALUES.map(([path, value]): RetiredEntry => [
198
- path,
199
- (node) => isScalar(node) && node.value === value,
290
+ retiredKeys([
291
+ ...OMP_RETIRED_VALUES.map(([path, value]): RetiredEntry => [
292
+ path,
293
+ (node) => isScalar(node) && node.value === value,
294
+ ]),
295
+ ...OMP_RETIRED_KEYS.map((path): RetiredEntry => [path, () => true]),
200
296
  ]),
201
- ...OMP_RETIRED_KEYS.map((path): RetiredEntry => [path, () => true]),
297
+ retiredBashRules,
202
298
  ]);
203
299
  }
204
300
 
205
301
  /** Prunes retired kit-owned blocks from a deployed omp models.yml. */
206
302
  export function syncOmpModelRemovals(ctx: Ctx, modelsFile: string): number {
207
- return pruneRetired(
208
- ctx,
209
- modelsFile,
210
- "models.yml",
211
- OMP_RETIRED_MODEL_BLOCKS.map(([path, block]): RetiredEntry => [
212
- path,
213
- (node) => isMap(node) && isDeepStrictEqual(node.toJSON(), block),
214
- ]),
215
- );
303
+ return pruneRetired(ctx, modelsFile, "models.yml", [
304
+ retiredKeys(
305
+ OMP_RETIRED_MODEL_BLOCKS.map(([path, block]): RetiredEntry => [
306
+ path,
307
+ (node) => isMap(node) && isDeepStrictEqual(node.toJSON(), block),
308
+ ]),
309
+ ),
310
+ ]);
216
311
  }
@@ -58,13 +58,18 @@ export async function ompSync(ctx: Ctx): Promise<OmpState> {
58
58
  syncMergedYaml(ctx, "SoT/.omp/models.yml", p(agentDir, "models.yml"), mergeOmpModels);
59
59
  syncOmpModelRemovals(ctx, p(agentDir, "models.yml"));
60
60
 
61
- const intercomRootSetting = process.env["PI_CODING_AGENT_DIR"];
61
+ // omp exports PI_CODING_AGENT_DIR as the agent directory of a named profile,
62
+ // and pi-intercom reads the trimmed value. Without a profile, the kit uses
63
+ // the PI_CODING_AGENT_DIR value when it is set, else ~/.pi/agent.
64
+ const intercomRootSetting = process.env["PI_CODING_AGENT_DIR"]?.trim();
62
65
  const intercomRoot =
63
- intercomRootSetting !== undefined && intercomRootSetting !== ""
64
- ? isAbsolute(intercomRootSetting)
65
- ? intercomRootSetting
66
- : resolve(process.cwd(), intercomRootSetting)
67
- : p(ctx.home, ".pi", "agent");
66
+ paths.profile !== undefined
67
+ ? paths.agentDir
68
+ : intercomRootSetting !== undefined && intercomRootSetting !== ""
69
+ ? isAbsolute(intercomRootSetting)
70
+ ? intercomRootSetting
71
+ : resolve(process.cwd(), intercomRootSetting)
72
+ : p(ctx.home, ".pi", "agent");
68
73
  const intercomDir = p(intercomRoot, "intercom");
69
74
  if (!ctx.dryRun) ensureDirectory(intercomDir);
70
75
  syncWholeFile(