@tangle-network/cli-agent-registry 0.0.0-stage → 0.14.0

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/dist/index.mjs ADDED
@@ -0,0 +1,146 @@
1
+ import { a as HARNESSES, i as configDirHomeEnv, n as HARNESS_SESSION_UNSUPPORTED, r as NATIVE_SESSION_CONTRACTS, t as HARNESS_CONFORMANCE_PENDING } from "./native-session-contracts-DWFzgoye.mjs";
2
+ import { HarnessSessionContractError, SESSION_FORMAT_IDS, assertArgvHonoursSessionContract, assertFlagsHonourSessionContract, assertStoreLocationHonoursSessionContract, compileSessionStoreGlob, forbiddenArgViolations, normalizePosixPath, sessionContractProblems, sessionStoreForPath, substituteNativeSessionId } from "./session-contract.mjs";
3
+ import { a as parseBackendType, i as isBackendType, n as BACKEND_TYPE, r as backendTypeSchema, t as ALL_BACKEND_TYPES } from "./backend-types-CREj4iOY.mjs";
4
+ import { a as agentProfileSchema, c as cliAgentHostPassthroughEnvVarNames, d as canonicalModelSlug, f as cliAgentClaimEnvVarNames, g as SYNTHETIC_ROUTER_MODEL, h as harnessModelWire, i as MANAGED_MODEL_KEY_NAME_ENV_VAR, l as getSpec, m as harnessModelSupportFor, n as CLI_AGENT_SPECS, o as claimDeliverableEnvVarNames, p as cliAgentEnvRoleName, r as MANAGED_MODEL_KEY_ENV_VAR, s as cliAgentEnvVarNamesByRole, t as AGENT_BACKEND_ENV_VAR, u as messageStorageDirOf } from "./specs-Bbiay_8K.mjs";
5
+ import { materializeCliAuthBundle } from "./cli-auth-bundle.mjs";
6
+ import { resolveDefaultBackend } from "./default-backend.mjs";
7
+ import { describeLocalCliAuthExpectation, discoverLocalCliAuthFiles } from "./local-cli-auth.mjs";
8
+ import { MANAGED_MODEL_LADDER, bareModelId, isServableManagedModel, managedModelChain } from "./servable-models.mjs";
9
+ import { z } from "zod";
10
+ //#region src/adapter-bindings.ts
11
+ /**
12
+ * A composition-owned factory map. Wiring requirements come from this selected
13
+ * catalog, not every harness known elsewhere. No provider implementation is
14
+ * imported here, and separate registries cannot overwrite each other's bindings.
15
+ *
16
+ * Registration itself does not authorize execution. As with the existing API,
17
+ * factories may be staged before catalog admission; callers must still resolve
18
+ * a selected spec and enforce its capabilities before dispatching a request.
19
+ * Unregistering a required factory is not retirement: select a new composition
20
+ * after draining its sessions rather than weakening the wiring invariant.
21
+ */
22
+ function createAdapterRegistry(specs) {
23
+ const selected = /* @__PURE__ */ new Map();
24
+ for (const spec of specs) {
25
+ if (selected.has(spec.name)) throw new Error(`cli-agent-registry: duplicate spec "${spec.name}"`);
26
+ selected.set(spec.name, {
27
+ sessions: spec.capabilities.sessions,
28
+ nativeSession: spec.nativeSession != null
29
+ });
30
+ }
31
+ const factories = /* @__PURE__ */ new Map();
32
+ function assertSessionContractDeclared(name) {
33
+ const spec = selected.get(name);
34
+ if (!spec?.sessions || spec.nativeSession) return;
35
+ if (Object.hasOwn(HARNESS_SESSION_UNSUPPORTED, name)) return;
36
+ throw new HarnessSessionContractError("harness_session_contract_missing", `${name} runs sessions but declares no nativeSession contract`);
37
+ }
38
+ return {
39
+ registerAdapterFactory(name, factory, options) {
40
+ assertSessionContractDeclared(name);
41
+ if (factories.has(name) && !options?.force) throw new Error(`cli-agent-registry: adapter factory for "${name}" already registered. Pass { force: true } to override (test stubs only) or call unregisterAdapterFactory() first.`);
42
+ factories.set(name, factory);
43
+ },
44
+ unregisterAdapterFactory(name) {
45
+ return factories.delete(name);
46
+ },
47
+ getAdapterFactory(name) {
48
+ return factories.get(name);
49
+ },
50
+ listRegisteredAdapters() {
51
+ return Array.from(factories.keys());
52
+ },
53
+ assertAdaptersWired() {
54
+ const missing = [];
55
+ for (const [name, spec] of selected) {
56
+ assertSessionContractDeclared(name);
57
+ if (spec.sessions && !factories.has(name)) missing.push(name);
58
+ }
59
+ if (missing.length > 0) throw new Error(`cli-agent-registry: executable backend specs without an adapter factory registered: ${missing.join(", ")}. Register each selected adapter in the composition root before startup.`);
60
+ }
61
+ };
62
+ }
63
+ const defaultRegistry = createAdapterRegistry(CLI_AGENT_SPECS);
64
+ function registerAdapterFactory(name, factory, options) {
65
+ defaultRegistry.registerAdapterFactory(name, factory, options);
66
+ }
67
+ function unregisterAdapterFactory(name) {
68
+ return defaultRegistry.unregisterAdapterFactory(name);
69
+ }
70
+ function getAdapterFactory(name) {
71
+ return defaultRegistry.getAdapterFactory(name);
72
+ }
73
+ function listRegisteredAdapters() {
74
+ return defaultRegistry.listRegisteredAdapters();
75
+ }
76
+ function assertAdaptersWired() {
77
+ defaultRegistry.assertAdaptersWired();
78
+ }
79
+ //#endregion
80
+ //#region src/agent-run-request.ts
81
+ /** A backend carries an inline profile, a profile digest, or neither. */
82
+ function agentRunBackendVariants(base) {
83
+ return z.union([
84
+ z.object({
85
+ ...base,
86
+ profile: agentProfileSchema
87
+ }).strict(),
88
+ z.object({
89
+ ...base,
90
+ profileSha256: z.string().regex(/^[a-f0-9]{64}$/, "profileSha256 must be a lowercase SHA-256")
91
+ }).strict(),
92
+ z.object(base).strict()
93
+ ]);
94
+ }
95
+ const agentRunWorkspaceSchema = z.object({
96
+ rootPath: z.string().optional(),
97
+ debugDirectory: z.string().optional(),
98
+ skipInitialization: z.boolean().optional(),
99
+ cleanupOnShutdown: z.boolean().optional()
100
+ });
101
+ /** The shared request fields, in wire order around each end's workspace and backend. */
102
+ function agentRunRequestSharedShape(workspace, backend) {
103
+ return {
104
+ sessionId: z.string().optional(),
105
+ displayName: z.string().optional(),
106
+ description: z.string().optional(),
107
+ domains: z.array(z.string()).optional(),
108
+ workspace,
109
+ backend,
110
+ expectedPublicProfileRequestDigest: z.string().regex(/^sha256:[a-f0-9]{64}$/).optional(),
111
+ expectedSecretProfileReceipt: z.string().regex(/^hmac-sha256:[a-f0-9]{64}$/).optional(),
112
+ githubToken: z.string().optional(),
113
+ metadata: z.record(z.string(), z.unknown()).optional()
114
+ };
115
+ }
116
+ //#endregion
117
+ //#region src/cli-dir-layout.ts
118
+ /** What every CLI's directory is read with; a spec adds its own entries. */
119
+ const DEFAULT_CLI_DIR_LAYOUT = {
120
+ sessionData: ["messages/**", "history.jsonl"],
121
+ configAllow: [
122
+ "config.toml",
123
+ "settings.json",
124
+ "settings.local.json",
125
+ "opencode.jsonc",
126
+ "package.json",
127
+ "package-lock.json",
128
+ "models_cache.json",
129
+ "installation_id",
130
+ "version.json",
131
+ ".personality_migration"
132
+ ],
133
+ credential: []
134
+ };
135
+ /** The default layout with a spec's additions. */
136
+ function mergeCliDirLayout(additions) {
137
+ return {
138
+ sessionData: [...DEFAULT_CLI_DIR_LAYOUT.sessionData, ...additions?.sessionData ?? []],
139
+ configAllow: [...DEFAULT_CLI_DIR_LAYOUT.configAllow, ...additions?.configAllow ?? []],
140
+ credential: [...DEFAULT_CLI_DIR_LAYOUT.credential, ...additions?.credential ?? []]
141
+ };
142
+ }
143
+ //#endregion
144
+ export { AGENT_BACKEND_ENV_VAR, ALL_BACKEND_TYPES, BACKEND_TYPE, CLI_AGENT_SPECS, DEFAULT_CLI_DIR_LAYOUT, HARNESSES, HARNESS_CONFORMANCE_PENDING, HARNESS_SESSION_UNSUPPORTED, HarnessSessionContractError, MANAGED_MODEL_KEY_ENV_VAR, MANAGED_MODEL_KEY_NAME_ENV_VAR, MANAGED_MODEL_LADDER, NATIVE_SESSION_CONTRACTS, SESSION_FORMAT_IDS, SYNTHETIC_ROUTER_MODEL, agentProfileSchema, agentRunBackendVariants, agentRunRequestSharedShape, agentRunWorkspaceSchema, assertAdaptersWired, assertArgvHonoursSessionContract, assertFlagsHonourSessionContract, assertStoreLocationHonoursSessionContract, backendTypeSchema, bareModelId, canonicalModelSlug, claimDeliverableEnvVarNames, cliAgentClaimEnvVarNames, cliAgentEnvRoleName, cliAgentEnvVarNamesByRole, cliAgentHostPassthroughEnvVarNames, compileSessionStoreGlob, configDirHomeEnv, createAdapterRegistry, describeLocalCliAuthExpectation, discoverLocalCliAuthFiles, forbiddenArgViolations, getAdapterFactory, getSpec, harnessModelSupportFor, harnessModelWire, isBackendType, isServableManagedModel, listRegisteredAdapters, managedModelChain, materializeCliAuthBundle, mergeCliDirLayout, messageStorageDirOf, normalizePosixPath, parseBackendType, registerAdapterFactory, resolveDefaultBackend, sessionContractProblems, sessionStoreForPath, substituteNativeSessionId, unregisterAdapterFactory };
145
+
146
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,14 @@
1
+ import { LocalCliAuthFile } from "./cli-auth-bundle.mjs";
2
+
3
+ //#region src/local-cli-auth.d.ts
4
+ type LocalCliAuthBackend = "codex" | "claude-code";
5
+ type DiscoverOptions = {
6
+ homeDir?: string;
7
+ env?: Readonly<Record<string, string | undefined>>;
8
+ credentialOnly?: boolean;
9
+ };
10
+ declare function discoverLocalCliAuthFiles(backendType: LocalCliAuthBackend, options?: DiscoverOptions): LocalCliAuthFile[] | undefined;
11
+ declare function describeLocalCliAuthExpectation(backendType: LocalCliAuthBackend): string;
12
+ //#endregion
13
+ export { type LocalCliAuthFile, describeLocalCliAuthExpectation, discoverLocalCliAuthFiles };
14
+ //# sourceMappingURL=local-cli-auth.d.mts.map
@@ -0,0 +1,31 @@
1
+ import { AUTH_BUNDLE_PATHS } from "./cli-auth-bundle.mjs";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { basename, dirname, join } from "node:path";
5
+ //#region src/local-cli-auth.ts
6
+ const DEFAULT_MODE = 384;
7
+ function readAuthFile(sourcePath, targetPath) {
8
+ if (!existsSync(sourcePath)) return null;
9
+ return {
10
+ path: targetPath,
11
+ content: readFileSync(sourcePath, "utf-8"),
12
+ mode: DEFAULT_MODE
13
+ };
14
+ }
15
+ function discoverLocalCliAuthFiles(backendType, options = {}) {
16
+ const env = options.env ?? (options.homeDir === void 0 ? process.env : {});
17
+ const homeDir = options.homeDir ?? (env.HOME || homedir());
18
+ const authPath = AUTH_BUNDLE_PATHS[backendType];
19
+ const configDir = env[backendType === "codex" ? "CODEX_HOME" : "CLAUDE_CONFIG_DIR"] || join(homeDir, dirname(authPath));
20
+ const credentialDir = backendType === "claude-code" ? env.CLAUDE_SECURESTORAGE_CONFIG_DIR || configDir : configDir;
21
+ const authFiles = [authPath, ...backendType === "claude-code" && !options.credentialOnly ? [".claude/settings.json", ".claude/settings.local.json"] : []].map((path) => readAuthFile(join(path === authPath ? credentialDir : configDir, basename(path)), path)).filter((entry) => entry !== null);
22
+ return authFiles.length > 0 ? authFiles : void 0;
23
+ }
24
+ function describeLocalCliAuthExpectation(backendType) {
25
+ if (backendType === "codex") return "auth.json in CODEX_HOME, or ~/.codex when CODEX_HOME is unset";
26
+ return "Claude credential files in CLAUDE_SECURESTORAGE_CONFIG_DIR or CLAUDE_CONFIG_DIR (default ~/.claude)";
27
+ }
28
+ //#endregion
29
+ export { describeLocalCliAuthExpectation, discoverLocalCliAuthFiles };
30
+
31
+ //# sourceMappingURL=local-cli-auth.mjs.map