@amsterdamdatalabs/adl-agent-control-darwin-arm64 0.1.47 → 0.1.51
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/bin/adl +1 -1
- package/bin/reconcile +45 -0
- package/bin/repo-search-mcp +4 -0
- package/package.json +3 -2
- package/packages/agent-hooks/src/rules/impl/adl-worktree.ts +51 -0
- package/packages/agent-hooks/src/rules/registry.ts +4 -0
- package/packages/agent-hooks/src/rules/shell/invocation.ts +38 -0
- package/packages/agent-settings/assets/mcp.json +3 -0
- package/packages/agent-settings/src/deploy/mcp-source.ts +6 -5
- package/packages/fleet/manifest.json +2 -0
- package/packages/fleet/src/install-adl-package.ts +30 -23
package/bin/adl
CHANGED
package/bin/reconcile
CHANGED
|
@@ -1043,6 +1043,26 @@ install_one_tool() {
|
|
|
1043
1043
|
echo "using installed package payload: $repo_root"
|
|
1044
1044
|
return 0
|
|
1045
1045
|
fi
|
|
1046
|
+
# repo-search-mcp ships in the same published package as adl (PBI az712), so
|
|
1047
|
+
# it follows the adl source-mode split: checkout builds the binary from the
|
|
1048
|
+
# checkout, npm uses (and links) the installed package payload.
|
|
1049
|
+
if [[ "$tool_id" == repo-search-mcp && "$source_mode" == checkout ]]; then
|
|
1050
|
+
echo "ensure repo-search-mcp from explicit checkout source: $repo_root"
|
|
1051
|
+
build_checkout_repo_search_mcp || rc=1
|
|
1052
|
+
if [[ "$mode" == apply && "$rc" -eq 0 ]]; then
|
|
1053
|
+
command -v "$executable" >/dev/null 2>&1 || { echo "ERROR checkout repo-search-mcp executable missing from PATH: $executable" >&2; rc=1; }
|
|
1054
|
+
fi
|
|
1055
|
+
return "$rc"
|
|
1056
|
+
fi
|
|
1057
|
+
if [[ "$tool_id" == repo-search-mcp && "$source_mode" == npm ]]; then
|
|
1058
|
+
if [[ "$mode" != apply ]]; then
|
|
1059
|
+
echo "would use installed package payload: $repo_root"
|
|
1060
|
+
return 0
|
|
1061
|
+
fi
|
|
1062
|
+
adl_package_owns_executable || return 1
|
|
1063
|
+
echo "using installed package payload: $repo_root"
|
|
1064
|
+
return 0
|
|
1065
|
+
fi
|
|
1046
1066
|
echo "ensure latest stable: $tool_id ($manager:$package)"
|
|
1047
1067
|
case "$manager" in
|
|
1048
1068
|
brew)
|
|
@@ -1368,6 +1388,30 @@ build_checkout_adl() {
|
|
|
1368
1388
|
return "$rc"
|
|
1369
1389
|
}
|
|
1370
1390
|
|
|
1391
|
+
# az712: the repo-search MCP server, compiled from the checkout exactly like
|
|
1392
|
+
# adl above. HEAD tree hash (not the worktree) so the gitignored dist/ build
|
|
1393
|
+
# output never perturbs the up-to-date check.
|
|
1394
|
+
build_checkout_repo_search_mcp() {
|
|
1395
|
+
local source_dir="packages/repo-search" entry="src/mcp-server.ts" target="/usr/local/bin/repo-search-mcp" source_hash hash_file rc=0
|
|
1396
|
+
source_hash="$(bun_source_hash "$source_dir")" || return 1
|
|
1397
|
+
hash_file="$(bun_source_hash_file repo-search-mcp)"
|
|
1398
|
+
if [[ -x "$target" && -f "$hash_file" && "$(cat "$hash_file")" == "$source_hash" ]]; then
|
|
1399
|
+
echo "checkout repo-search-mcp binary already up to date (source $source_hash)"
|
|
1400
|
+
return 0
|
|
1401
|
+
fi
|
|
1402
|
+
run_bun_compile repo-search-mcp "$source_hash" "$source_dir" "$entry" "$target" || rc=1
|
|
1403
|
+
if [[ "$mode" == apply && "$rc" -eq 0 ]]; then
|
|
1404
|
+
[[ -x "$target" ]] || { echo "ERROR checkout repo-search-mcp executable missing: $target" >&2; rc=1; }
|
|
1405
|
+
if [[ "$rc" -eq 0 ]]; then
|
|
1406
|
+
mkdir -p "${hash_file%/*}"
|
|
1407
|
+
printf '%s\n' "$source_hash" >"$hash_file.new"
|
|
1408
|
+
mv -f "$hash_file.new" "$hash_file"
|
|
1409
|
+
echo "built checkout repo-search-mcp binary: $target (source $source_hash)"
|
|
1410
|
+
fi
|
|
1411
|
+
fi
|
|
1412
|
+
return "$rc"
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1371
1415
|
# embedding-model installs the enact-embedding static (Model2Vec) artifact
|
|
1372
1416
|
# that adl hook's (the folded-in hook engine's) skill-match hook loads
|
|
1373
1417
|
# from the administrator's cache.
|
|
@@ -2853,6 +2897,7 @@ project_adl_package_payload() {
|
|
|
2853
2897
|
echo "would project Adl package payload from $repo_root to /usr/local/libexec/adl and /usr/local/bin/git{,-ado}"
|
|
2854
2898
|
if [[ "$source_mode" == npm ]]; then
|
|
2855
2899
|
echo "would link /usr/local/bin/adl to $repo_root/bin/adl"
|
|
2900
|
+
echo "would link /usr/local/bin/repo-search-mcp to $repo_root/bin/repo-search-mcp"
|
|
2856
2901
|
fi
|
|
2857
2902
|
return 0
|
|
2858
2903
|
fi
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amsterdamdatalabs/adl-agent-control-darwin-arm64",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.51",
|
|
4
4
|
"description": "adl CLI binary for darwin/arm64 (agent identity + Azure DevOps front door — see docs/architecture/cli-design.md)",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"os": [
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"packages/azdo"
|
|
22
22
|
],
|
|
23
23
|
"bin": {
|
|
24
|
-
"adl": "bin/adl"
|
|
24
|
+
"adl": "bin/adl",
|
|
25
|
+
"repo-search-mcp": "bin/repo-search-mcp"
|
|
25
26
|
},
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@iarna/toml": "^2.2.5",
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// PBI az711 (Tarun, 2026-10-20): agents never create/remove worktrees — see docs/operations/agent-permissions.md.
|
|
2
|
+
|
|
3
|
+
import type { Invocation } from '../shell/invocation.ts'
|
|
4
|
+
import { tokenValue } from '../shell/token.ts'
|
|
5
|
+
import type { Finding, MessageContext, RuleContext, RuleSpec } from '../spec.ts'
|
|
6
|
+
import { noParams } from '../spec.ts'
|
|
7
|
+
import { resolveFromEnvOrFile } from './adl-identity.ts'
|
|
8
|
+
import { isHelpOnlyInvocation } from './git-helpers.ts'
|
|
9
|
+
import { defaultGitMessage, detailString } from './messages.ts'
|
|
10
|
+
|
|
11
|
+
const RULE_ID = 'adl.worktree-mutation'
|
|
12
|
+
|
|
13
|
+
const ASK_USER = 'worktrees are given, not agent-created: ask Tarun for git branch and worktree operations'
|
|
14
|
+
|
|
15
|
+
type WorktreeMutation = 'add' | 'prune-apply'
|
|
16
|
+
|
|
17
|
+
export const adlWorktreeMutation: RuleSpec = {
|
|
18
|
+
id: RULE_ID,
|
|
19
|
+
category: 'git',
|
|
20
|
+
severity: 'deny',
|
|
21
|
+
enabledByDefault: true,
|
|
22
|
+
summary: 'Deny agents `adl worktree add` and `adl worktree prune --apply`; read-only worktree forms stay allowed.',
|
|
23
|
+
params: noParams,
|
|
24
|
+
match(inv: Invocation, ctx: RuleContext<Record<string, never>>): Finding | null {
|
|
25
|
+
if (inv.kind !== 'adl' || inv.subcommand !== 'worktree') return null
|
|
26
|
+
if (isHelpOnlyInvocation(inv.args)) return null
|
|
27
|
+
|
|
28
|
+
// Humans (no resolvable agent identity) are entirely outside this rule.
|
|
29
|
+
const resolution = resolveFromEnvOrFile(ctx.env)
|
|
30
|
+
if (!resolution.ok) return null
|
|
31
|
+
|
|
32
|
+
const action = inv.args.map((token) => tokenValue(token)).find((value) => !value.startsWith('-'))
|
|
33
|
+
if (action === undefined) return null
|
|
34
|
+
|
|
35
|
+
if (action === 'add') return { ruleId: RULE_ID, severity: 'deny', detail: { mutation: 'add' } }
|
|
36
|
+
if (action === 'prune' && inv.args.some((token) => tokenValue(token) === '--apply')) {
|
|
37
|
+
return { ruleId: RULE_ID, severity: 'deny', detail: { mutation: 'prune-apply' } }
|
|
38
|
+
}
|
|
39
|
+
return null
|
|
40
|
+
},
|
|
41
|
+
message(finding: Finding, ctx: MessageContext) {
|
|
42
|
+
const mutation = detailString(finding, 'mutation') as WorktreeMutation
|
|
43
|
+
const operation = mutation === 'add' ? '`adl worktree add`' : '`adl worktree prune --apply`'
|
|
44
|
+
return defaultGitMessage(`${operation} by an agent (${ASK_USER})`, ctx.snippet)
|
|
45
|
+
},
|
|
46
|
+
corpus: {
|
|
47
|
+
// Identity-dependent denies live in tests/unit/rules-adl-worktree.test.ts (shared fixture cannot supply ADL_AGENT_ID_AGENT).
|
|
48
|
+
deny: [],
|
|
49
|
+
allow: ['adl worktree list', 'adl worktree prune', 'adl worktree --help', 'adl mcp serve'],
|
|
50
|
+
},
|
|
51
|
+
}
|
|
@@ -58,6 +58,7 @@ import { adlRunRequiredForWrites } from './impl/adl-run-required.ts'
|
|
|
58
58
|
import { adlHumanAzdoBypass } from './impl/adl-human-azdo-bypass.ts'
|
|
59
59
|
import { adlGitCredentialBypass, adlSecurityKeychainAdo } from './impl/adl-git-credential-bypass.ts'
|
|
60
60
|
import { adlGitPushBranchPolicy } from './impl/adl-git-push-policy.ts'
|
|
61
|
+
import { adlWorktreeMutation } from './impl/adl-worktree.ts'
|
|
61
62
|
import { adlGitIdentity } from './impl/adl-git-identity.ts'
|
|
62
63
|
import { adlTokenMintingRole } from './impl/adl-token-minting-role.ts'
|
|
63
64
|
import { adlPrCreateUpdateRole } from './impl/adl-pr-role.ts'
|
|
@@ -148,6 +149,9 @@ export const TOOL_RULES: readonly AnyRuleSpec[] = [
|
|
|
148
149
|
adlSecurityKeychainAdo,
|
|
149
150
|
adlRunRequiredForWrites,
|
|
150
151
|
adlGitPushBranchPolicy,
|
|
152
|
+
// After the push policies: worktree add/prune --apply are git-branching
|
|
153
|
+
// work, and branching is never agent-sanctioned (PBI az711).
|
|
154
|
+
adlWorktreeMutation,
|
|
151
155
|
// After the push policies: it rewrites what they allow, and denies the
|
|
152
156
|
// identity conflicts (inline override / sudo wrapper) those rules ignore.
|
|
153
157
|
adlGitIdentity,
|
|
@@ -84,6 +84,13 @@ export type Invocation =
|
|
|
84
84
|
* ignores this field. See impl/tool-azure-devops.ts.
|
|
85
85
|
*/
|
|
86
86
|
| { readonly kind: 'azure-devops'; readonly args: readonly Token[] }
|
|
87
|
+
/**
|
|
88
|
+
* The `adl` CLI (`ClassifyConfig.adlNames`). `subcommand` is the first
|
|
89
|
+
* non-flag word (`worktree`, `mcp`, …) and `args` the tokens after it, so
|
|
90
|
+
* `adl.worktree-mutation` can deny `adl worktree add` / `prune --apply`
|
|
91
|
+
* without touching read-only forms. See impl/adl-worktree.ts.
|
|
92
|
+
*/
|
|
93
|
+
| { readonly kind: 'adl'; readonly subcommand: string; readonly args: readonly Token[] }
|
|
87
94
|
| { readonly kind: 'find' }
|
|
88
95
|
| { readonly kind: 'grep' }
|
|
89
96
|
/**
|
|
@@ -186,6 +193,7 @@ export interface ClassifyConfig {
|
|
|
186
193
|
readonly trashNames: ReadonlySet<string>
|
|
187
194
|
readonly azureDevopsNames: ReadonlySet<string>
|
|
188
195
|
readonly azureDevopsSubcommands: ReadonlySet<string>
|
|
196
|
+
readonly adlNames: ReadonlySet<string>
|
|
189
197
|
readonly cargoNames: ReadonlySet<string>
|
|
190
198
|
readonly justNames: ReadonlySet<string>
|
|
191
199
|
readonly frontendToolNames: ReadonlySet<string>
|
|
@@ -229,6 +237,7 @@ export const DEFAULT_CLASSIFY_CONFIG: ClassifyConfig = {
|
|
|
229
237
|
rmNames: new Set(['rm', 'rm.exe', 'unlink', 'unlink.exe']),
|
|
230
238
|
trashNames: new Set(['trash', 'trash.exe']),
|
|
231
239
|
azureDevopsNames: new Set(['az', 'az.exe']),
|
|
240
|
+
adlNames: new Set(['adl', 'adl.exe']),
|
|
232
241
|
azureDevopsSubcommands: new Set(['devops', 'repos', 'pipelines', 'boards', 'artifacts']),
|
|
233
242
|
cargoNames: new Set(['cargo', 'cargo.exe']),
|
|
234
243
|
justNames: new Set(['just', 'just.exe']),
|
|
@@ -244,6 +253,7 @@ function isClassifiedCommandName(token: Token, cfg: ClassifyConfig): boolean {
|
|
|
244
253
|
cfg.rmNames.has(name) ||
|
|
245
254
|
cfg.trashNames.has(name) ||
|
|
246
255
|
cfg.azureDevopsNames.has(name) ||
|
|
256
|
+
cfg.adlNames.has(name) ||
|
|
247
257
|
cfg.cargoNames.has(name) ||
|
|
248
258
|
cfg.justNames.has(name) ||
|
|
249
259
|
cfg.frontendToolNames.has(name) ||
|
|
@@ -640,7 +650,35 @@ export function skipAzGlobalFlags(args: readonly Token[]): number {
|
|
|
640
650
|
return index
|
|
641
651
|
}
|
|
642
652
|
|
|
653
|
+
function walkAdlCommand(args: readonly Token[]): readonly Invocation[] | null {
|
|
654
|
+
if (isHelpOrVersionOnly(args)) return []
|
|
655
|
+
// `adl -C <dir> worktree ...` — skip value-taking globals before the subcommand.
|
|
656
|
+
let index = 0
|
|
657
|
+
while (index < args.length) {
|
|
658
|
+
const value = tokenValue(args[index] as Token)
|
|
659
|
+
if (value === '-C') {
|
|
660
|
+
index += 2
|
|
661
|
+
continue
|
|
662
|
+
}
|
|
663
|
+
if (value.startsWith('-')) {
|
|
664
|
+
index += 1
|
|
665
|
+
continue
|
|
666
|
+
}
|
|
667
|
+
break
|
|
668
|
+
}
|
|
669
|
+
if (index >= args.length) return null
|
|
670
|
+
const subToken = args[index] as Token
|
|
671
|
+
if (dynamicToken(subToken)) return [{ kind: 'uncertain', reason: 'dynamic adl subcommand' }]
|
|
672
|
+
const subcommand = tokenValue(subToken).toLowerCase()
|
|
673
|
+
// Only `worktree` gets its own kind (adl.worktree-mutation). Every other
|
|
674
|
+
// `adl` form — `adl mcp cli …` above all — keeps its historic generic
|
|
675
|
+
// 'command' classification so the mcp-cli translation path is untouched.
|
|
676
|
+
if (subcommand !== 'worktree') return null
|
|
677
|
+
return [{ kind: 'adl', subcommand, args: args.slice(index + 1) }]
|
|
678
|
+
}
|
|
679
|
+
|
|
643
680
|
function walkToolCommand(name: string, args: readonly Token[], cfg: ClassifyConfig, walk: (tokens: readonly Token[]) => readonly Invocation[]): readonly Invocation[] | null {
|
|
681
|
+
if (cfg.adlNames.has(name)) return walkAdlCommand(args)
|
|
644
682
|
if (cfg.azureDevopsNames.has(name)) {
|
|
645
683
|
if (isHelpOrVersionOnly(args)) return []
|
|
646
684
|
const subIndex = skipAzGlobalFlags(args)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Reads assets/mcp.json — the canonical MCP server list, in Claude's own
|
|
3
|
-
* `{command, args}` wire shape
|
|
3
|
+
* `{command, args?}` wire shape (args optional, normalized to []) — into an
|
|
4
|
+
* ordered structure every renderer
|
|
4
5
|
* in mcp-render.ts starts from. Pure: parses, never mutates, and preserves
|
|
5
6
|
* the source file's own key order (the order every fresh-deploy surface
|
|
6
7
|
* file must reproduce).
|
|
@@ -16,10 +17,10 @@ export interface McpServerSpec {
|
|
|
16
17
|
|
|
17
18
|
const DEFAULT_MCP_SOURCE_PATH = fileURLToPath(new URL("../../assets/mcp.json", import.meta.url));
|
|
18
19
|
|
|
19
|
-
function isServerSpec(value: unknown): value is { command: string; args
|
|
20
|
+
function isServerSpec(value: unknown): value is { command: string; args?: readonly string[] } {
|
|
20
21
|
if (typeof value !== "object" || value === null) return false;
|
|
21
22
|
const v = value as Record<string, unknown>;
|
|
22
|
-
return typeof v.command === "string" && Array.isArray(v.args) && v.args.every((a) => typeof a === "string");
|
|
23
|
+
return typeof v.command === "string" && (v.args === undefined || (Array.isArray(v.args) && v.args.every((a) => typeof a === "string")));
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/** Loads and validates assets/mcp.json (or a fixture at another path). Throws (fails loud) on malformed JSON or an unrecognized shape. */
|
|
@@ -36,8 +37,8 @@ export function loadMcpSource(path: string = DEFAULT_MCP_SOURCE_PATH): readonly
|
|
|
36
37
|
}
|
|
37
38
|
const out: McpServerSpec[] = [];
|
|
38
39
|
for (const [name, spec] of Object.entries(servers)) {
|
|
39
|
-
if (!isServerSpec(spec)) throw new Error(`mcp source server "${name}" is not a valid {command, args} spec: ${path}`);
|
|
40
|
-
out.push({ name, command: spec.command, args: spec.args });
|
|
40
|
+
if (!isServerSpec(spec)) throw new Error(`mcp source server "${name}" is not a valid {command, args?} spec: ${path}`);
|
|
41
|
+
out.push({ name, command: spec.command, args: spec.args ?? [] });
|
|
41
42
|
}
|
|
42
43
|
return out;
|
|
43
44
|
}
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"docs-search": {"manager": "npm", "package": "@amsterdamdatalabs/enact-docs-search", "executable": "enact-docs-search", "allow_scripts": ["hnswlib-node", "onnxruntime-node", "sharp", "protobufjs"], "reason": "Separate search product that provides the search tool."},
|
|
70
70
|
"adl": {"manager": "npm", "package": "@amsterdamdatalabs/adl-agent-control", "executable": "adl"},
|
|
71
71
|
"adl-agent-id": {"manager": "npm", "package": "@amsterdamdatalabs/adl-agent-id", "executable": "adl-agent-id", "reason": "Separate Go binary with its own trust boundary."},
|
|
72
|
+
"repo-search-mcp": {"manager": "npm", "package": "@amsterdamdatalabs/adl-agent-control", "executable": "repo-search-mcp", "reason": "Second binary of the adl platform package; the repo-search MCP server ships with every adl update (PBI az712)."},
|
|
72
73
|
"fd": {"manager": "brew", "package": "fd", "executable": "fd"},
|
|
73
74
|
"git": {"manager": "brew", "package": "git", "executable": "git"},
|
|
74
75
|
"jq": {"manager": "brew", "package": "jq", "executable": "jq"},
|
|
@@ -152,6 +153,7 @@
|
|
|
152
153
|
"docs-search": {"manager": "npm", "package": "@amsterdamdatalabs/enact-docs-search", "executable": "enact-docs-search", "allow_scripts": ["hnswlib-node", "onnxruntime-node", "sharp", "protobufjs"], "reason": "Separate search product that provides the search tool."},
|
|
153
154
|
"adl": {"manager": "npm", "package": "@amsterdamdatalabs/adl-agent-control", "executable": "adl"},
|
|
154
155
|
"adl-agent-id": {"manager": "npm", "package": "@amsterdamdatalabs/adl-agent-id", "executable": "adl-agent-id", "reason": "Separate Go binary with its own trust boundary."},
|
|
156
|
+
"repo-search-mcp": {"manager": "npm", "package": "@amsterdamdatalabs/adl-agent-control", "executable": "repo-search-mcp", "reason": "Second binary of the adl platform package; the repo-search MCP server ships with every adl update (PBI az712)."},
|
|
155
157
|
"fd": {"manager": "brew", "package": "fd", "executable": "fd"},
|
|
156
158
|
"git": {"manager": "brew", "package": "git", "executable": "git"},
|
|
157
159
|
"jq": {"manager": "brew", "package": "jq", "executable": "jq"},
|
|
@@ -47,12 +47,14 @@ export interface InstallAdlPackageOptions {
|
|
|
47
47
|
packageRoot: string
|
|
48
48
|
systemRoot?: string
|
|
49
49
|
/**
|
|
50
|
-
* Package mode: link /usr/local/bin/adl
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
50
|
+
* Package mode: link /usr/local/bin/adl and /usr/local/bin/repo-search-mcp
|
|
51
|
+
* to THIS package's own bin/ binaries (az712: the repo-search MCP server is
|
|
52
|
+
* the package's second binary). Hosts install the package with bun, which
|
|
53
|
+
* links both into the owner's ~/.bun/bin only, yet bin/git-ado's
|
|
54
|
+
* `adl id token`, the MCP server commands, the managed surface hooks and
|
|
55
|
+
* GUI-launched agents all run bare commands without that shell PATH.
|
|
56
|
+
* Checkout mode (a developer build, no compiled binaries in the tree)
|
|
57
|
+
* leaves it off.
|
|
56
58
|
*/
|
|
57
59
|
linkAdl?: boolean
|
|
58
60
|
}
|
|
@@ -87,9 +89,11 @@ function assertPackageRoot(packageRoot: string, linkAdl: boolean): string {
|
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
if (linkAdl) {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
for (const binName of ['adl', 'repo-search-mcp']) {
|
|
93
|
+
const bin = join(root, 'bin', binName)
|
|
94
|
+
if (!existsSync(bin) || !lstatSync(bin).isFile() || (statSync(bin).mode & 0o111) === 0) {
|
|
95
|
+
throw new Error(`package ${binName} must be an executable file: bin/${binName}`)
|
|
96
|
+
}
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
99
|
return root
|
|
@@ -159,31 +163,31 @@ function replaceManagedScript(source: string, target: string): void {
|
|
|
159
163
|
}
|
|
160
164
|
|
|
161
165
|
// A link this function made points into some install's platform package. Anything else at the
|
|
162
|
-
// path is someone else's
|
|
163
|
-
const
|
|
166
|
+
// path is someone else's binary and is never replaced silently.
|
|
167
|
+
const managedPackageBinLinkTarget = /\/adl-agent-control-[a-z0-9]+-[a-z0-9]+\/bin\/(adl|repo-search-mcp)$/
|
|
164
168
|
|
|
165
|
-
function
|
|
169
|
+
function packageBinLinkStatus(link: string, source: string, binName: string): 'current' | 'replace' | 'create' {
|
|
166
170
|
if (!lstatExists(link)) return 'create'
|
|
167
171
|
if (!lstatSync(link).isSymbolicLink()) {
|
|
168
172
|
const date = new Date().toISOString().slice(0, 10).replaceAll('-', '')
|
|
169
173
|
throw new Error(
|
|
170
|
-
`refusing to replace ${link}: a different
|
|
174
|
+
`refusing to replace ${link}: a different ${binName} (a legacy compiled one from before the package existed) shadows this package. Move it aside, never delete it, then run this again: sudo mv ${link} ${link}.legacy-${date}`,
|
|
171
175
|
)
|
|
172
176
|
}
|
|
173
177
|
const current = readlinkTarget(link)
|
|
174
178
|
if (current === source) return 'current'
|
|
175
|
-
if (!
|
|
179
|
+
if (!managedPackageBinLinkTarget.test(current)) throw new Error(`refusing to replace unmanaged symlink: ${link} -> ${current}`)
|
|
176
180
|
return 'replace'
|
|
177
181
|
}
|
|
178
182
|
|
|
179
|
-
function
|
|
183
|
+
function linkPackageBinToPackage(packageRoot: string, systemRoot: string, binName: string, status: 'current' | 'replace' | 'create'): void {
|
|
180
184
|
if (status === 'current') return
|
|
181
|
-
const link = join(systemRoot, 'usr/local/bin
|
|
185
|
+
const link = join(systemRoot, 'usr/local/bin', binName)
|
|
182
186
|
mkdirSync(dirname(link), { recursive: true })
|
|
183
187
|
const tempDirectory = mkdtempSync(join(dirname(link), '.adl-package-link-'))
|
|
184
|
-
const temp = join(tempDirectory,
|
|
188
|
+
const temp = join(tempDirectory, binName)
|
|
185
189
|
try {
|
|
186
|
-
symlinkSync(join(packageRoot, 'bin
|
|
190
|
+
symlinkSync(join(packageRoot, 'bin', binName), temp)
|
|
187
191
|
renameSync(temp, link)
|
|
188
192
|
} finally {
|
|
189
193
|
rmSync(tempDirectory, { recursive: true, force: true })
|
|
@@ -193,10 +197,13 @@ function linkAdlToPackage(packageRoot: string, systemRoot: string, status: 'curr
|
|
|
193
197
|
export function installAdlPackage(options: InstallAdlPackageOptions): void {
|
|
194
198
|
const packageRoot = assertPackageRoot(options.packageRoot, options.linkAdl === true)
|
|
195
199
|
const systemRoot = resolve(options.systemRoot ?? '/')
|
|
196
|
-
// Refusals come before any replacement, so a shadowing legacy
|
|
197
|
-
const
|
|
198
|
-
?
|
|
199
|
-
|
|
200
|
+
// Refusals come before any replacement, so a shadowing legacy binary leaves the host untouched.
|
|
201
|
+
const packageBinLinks = options.linkAdl
|
|
202
|
+
? (['adl', 'repo-search-mcp'] as const).map((binName) => ({
|
|
203
|
+
binName,
|
|
204
|
+
status: packageBinLinkStatus(join(systemRoot, 'usr/local/bin', binName), join(packageRoot, 'bin', binName), binName),
|
|
205
|
+
}))
|
|
206
|
+
: []
|
|
200
207
|
for (const relative of payloadDirectories) {
|
|
201
208
|
replacePayloadSymlink(
|
|
202
209
|
join(packageRoot, relative),
|
|
@@ -210,7 +217,7 @@ export function installAdlPackage(options: InstallAdlPackageOptions): void {
|
|
|
210
217
|
join(systemRoot, 'usr/local/bin', relative.split('/').at(-1)!),
|
|
211
218
|
)
|
|
212
219
|
}
|
|
213
|
-
|
|
220
|
+
for (const { binName, status } of packageBinLinks) linkPackageBinToPackage(packageRoot, systemRoot, binName, status)
|
|
214
221
|
}
|
|
215
222
|
|
|
216
223
|
if (import.meta.main) {
|