@atomic-chat/core 0.20.7 → 0.21.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/cli/launch.d.ts +23 -3
- package/dist/cli/launch.js +59 -8
- package/dist/cli/launch.js.map +1 -1
- package/dist/cli/main.d.ts +1 -1
- package/dist/contracts/events.d.ts +8 -0
- package/dist/contracts/settings.d.ts +5 -0
- package/dist/contracts/settings.js.map +1 -1
- package/dist/core/atomic-core.d.ts +3 -1
- package/dist/core/atomic-core.js +4 -1
- package/dist/core/atomic-core.js.map +1 -1
- package/dist/core/create.js +4 -1
- package/dist/core/create.js.map +1 -1
- package/dist/core/sessions.js +1 -0
- package/dist/core/sessions.js.map +1 -1
- package/dist/integrations/catalog.d.ts +25 -8
- package/dist/integrations/catalog.js +105 -38
- package/dist/integrations/catalog.js.map +1 -1
- package/dist/integrations/configure/atomic-agent.d.ts +9 -1
- package/dist/integrations/configure/atomic-agent.js +42 -3
- package/dist/integrations/configure/atomic-agent.js.map +1 -1
- package/dist/integrations/configure/backup.d.ts +21 -0
- package/dist/integrations/configure/backup.js +52 -0
- package/dist/integrations/configure/backup.js.map +1 -0
- package/dist/integrations/configure/claude-code.d.ts +11 -4
- package/dist/integrations/configure/claude-code.js +73 -24
- package/dist/integrations/configure/claude-code.js.map +1 -1
- package/dist/integrations/configure/cline.d.ts +14 -4
- package/dist/integrations/configure/cline.js +78 -6
- package/dist/integrations/configure/cline.js.map +1 -1
- package/dist/integrations/configure/codex.d.ts +5 -3
- package/dist/integrations/configure/codex.js +12 -5
- package/dist/integrations/configure/codex.js.map +1 -1
- package/dist/integrations/configure/copilot.d.ts +28 -5
- package/dist/integrations/configure/copilot.js +124 -8
- package/dist/integrations/configure/copilot.js.map +1 -1
- package/dist/integrations/configure/droid.d.ts +13 -7
- package/dist/integrations/configure/droid.js +48 -17
- package/dist/integrations/configure/droid.js.map +1 -1
- package/dist/integrations/configure/dsh.d.ts +36 -20
- package/dist/integrations/configure/dsh.js +250 -48
- package/dist/integrations/configure/dsh.js.map +1 -1
- package/dist/integrations/configure/goose.d.ts +21 -7
- package/dist/integrations/configure/goose.js +141 -10
- package/dist/integrations/configure/goose.js.map +1 -1
- package/dist/integrations/configure/hermes.d.ts +63 -10
- package/dist/integrations/configure/hermes.js +360 -75
- package/dist/integrations/configure/hermes.js.map +1 -1
- package/dist/integrations/configure/json-backup.d.ts +73 -0
- package/dist/integrations/configure/json-backup.js +292 -0
- package/dist/integrations/configure/json-backup.js.map +1 -0
- package/dist/integrations/configure/json-key-backup.d.ts +43 -0
- package/dist/integrations/configure/json-key-backup.js +113 -0
- package/dist/integrations/configure/json-key-backup.js.map +1 -0
- package/dist/integrations/configure/kilo.d.ts +4 -4
- package/dist/integrations/configure/kilo.js +6 -9
- package/dist/integrations/configure/kilo.js.map +1 -1
- package/dist/integrations/configure/legacy-env-block.d.ts +18 -0
- package/dist/integrations/configure/legacy-env-block.js +47 -0
- package/dist/integrations/configure/legacy-env-block.js.map +1 -0
- package/dist/integrations/configure/mimo.d.ts +3 -2
- package/dist/integrations/configure/mimo.js +8 -9
- package/dist/integrations/configure/mimo.js.map +1 -1
- package/dist/integrations/configure/muse.d.ts +3 -3
- package/dist/integrations/configure/muse.js +5 -6
- package/dist/integrations/configure/muse.js.map +1 -1
- package/dist/integrations/configure/openclaude.d.ts +22 -7
- package/dist/integrations/configure/openclaude.js +132 -39
- package/dist/integrations/configure/openclaude.js.map +1 -1
- package/dist/integrations/configure/openclaw.d.ts +19 -5
- package/dist/integrations/configure/openclaw.js +79 -23
- package/dist/integrations/configure/openclaw.js.map +1 -1
- package/dist/integrations/configure/opencode-style.d.ts +53 -11
- package/dist/integrations/configure/opencode-style.js +218 -23
- package/dist/integrations/configure/opencode-style.js.map +1 -1
- package/dist/integrations/configure/opencode.d.ts +5 -4
- package/dist/integrations/configure/opencode.js +8 -10
- package/dist/integrations/configure/opencode.js.map +1 -1
- package/dist/integrations/configure/openhands.d.ts +5 -4
- package/dist/integrations/configure/openhands.js +7 -7
- package/dist/integrations/configure/openhands.js.map +1 -1
- package/dist/integrations/configure/pi.d.ts +6 -5
- package/dist/integrations/configure/pi.js +79 -30
- package/dist/integrations/configure/pi.js.map +1 -1
- package/dist/integrations/configure/poolside.d.ts +5 -4
- package/dist/integrations/configure/poolside.js +7 -7
- package/dist/integrations/configure/poolside.js.map +1 -1
- package/dist/integrations/configure/registry.d.ts +6 -0
- package/dist/integrations/configure/registry.js +1 -0
- package/dist/integrations/configure/registry.js.map +1 -1
- package/dist/integrations/configure/zcode.d.ts +6 -7
- package/dist/integrations/configure/zcode.js +26 -11
- package/dist/integrations/configure/zcode.js.map +1 -1
- package/dist/integrations/configure/zed.d.ts +16 -4
- package/dist/integrations/configure/zed.js +61 -13
- package/dist/integrations/configure/zed.js.map +1 -1
- package/dist/models/gguf/kv-cache.d.ts +20 -1
- package/dist/models/gguf/kv-cache.js +97 -7
- package/dist/models/gguf/kv-cache.js.map +1 -1
- package/dist/models/gguf/reader.d.ts +5 -3
- package/dist/models/gguf/reader.js +10 -6
- package/dist/models/gguf/reader.js.map +1 -1
- package/dist/runtime/llamacpp/args.d.ts +14 -0
- package/dist/runtime/llamacpp/args.js +48 -4
- package/dist/runtime/llamacpp/args.js.map +1 -1
- package/dist/runtime/llamacpp/ctx-ladder.d.ts +6 -3
- package/dist/runtime/llamacpp/ctx-ladder.js +6 -3
- package/dist/runtime/llamacpp/ctx-ladder.js.map +1 -1
- package/dist/runtime/llamacpp/fit-margin.d.ts +24 -0
- package/dist/runtime/llamacpp/fit-margin.js +31 -0
- package/dist/runtime/llamacpp/fit-margin.js.map +1 -1
- package/dist/runtime/llamacpp/generation-limits.d.ts +45 -0
- package/dist/runtime/llamacpp/generation-limits.js +61 -0
- package/dist/runtime/llamacpp/generation-limits.js.map +1 -0
- package/dist/runtime/llamacpp/load-plan.d.ts +14 -2
- package/dist/runtime/llamacpp/load-plan.js +64 -13
- package/dist/runtime/llamacpp/load-plan.js.map +1 -1
- package/dist/runtime/llamacpp/runtime.d.ts +1 -0
- package/dist/runtime/llamacpp/runtime.js +2 -0
- package/dist/runtime/llamacpp/runtime.js.map +1 -1
- package/dist/runtime/managed-engines/runtime.js +13 -2
- package/dist/runtime/managed-engines/runtime.js.map +1 -1
- package/dist/runtime/managed-engines/spec.d.ts +6 -0
- package/dist/runtime/managed-engines/spec.js.map +1 -1
- package/dist/runtime/managed-models/auto-limits.d.ts +47 -0
- package/dist/runtime/managed-models/auto-limits.js +60 -0
- package/dist/runtime/managed-models/auto-limits.js.map +1 -0
- package/dist/runtime/managed-models/index.d.ts +1 -0
- package/dist/runtime/managed-models/index.js +1 -0
- package/dist/runtime/managed-models/index.js.map +1 -1
- package/dist/runtime/mlx/config.d.ts +9 -5
- package/dist/runtime/mlx/config.js +12 -6
- package/dist/runtime/mlx/config.js.map +1 -1
- package/dist/runtime/mlx/model-files.d.ts +9 -0
- package/dist/runtime/mlx/model-files.js +26 -0
- package/dist/runtime/mlx/model-files.js.map +1 -1
- package/dist/runtime/mlx/runtime.d.ts +7 -0
- package/dist/runtime/mlx/runtime.js +24 -2
- package/dist/runtime/mlx/runtime.js.map +1 -1
- package/dist/runtime/sglang/adapter.d.ts +4 -0
- package/dist/runtime/sglang/adapter.js +9 -6
- package/dist/runtime/sglang/adapter.js.map +1 -1
- package/dist/runtime/sglang/engine.js +2 -1
- package/dist/runtime/sglang/engine.js.map +1 -1
- package/dist/runtime/sglang/memory.d.ts +11 -1
- package/dist/runtime/sglang/memory.js +34 -3
- package/dist/runtime/sglang/memory.js.map +1 -1
- package/dist/runtime/sglang/settings.d.ts +2 -1
- package/dist/runtime/sglang/settings.js +11 -7
- package/dist/runtime/sglang/settings.js.map +1 -1
- package/dist/runtime/vllm/adapter.d.ts +4 -0
- package/dist/runtime/vllm/adapter.js +9 -6
- package/dist/runtime/vllm/adapter.js.map +1 -1
- package/dist/runtime/vllm/engine.js +1 -0
- package/dist/runtime/vllm/engine.js.map +1 -1
- package/dist/runtime/vllm/memory.d.ts +12 -1
- package/dist/runtime/vllm/memory.js +44 -2
- package/dist/runtime/vllm/memory.js.map +1 -1
- package/dist/runtime/vllm/settings.d.ts +2 -1
- package/dist/runtime/vllm/settings.js +12 -7
- package/dist/runtime/vllm/settings.js.map +1 -1
- package/dist/server/public/context-window.d.ts +29 -0
- package/dist/server/public/context-window.js +77 -0
- package/dist/server/public/context-window.js.map +1 -0
- package/dist/server/public/decision-preview.js +1 -0
- package/dist/server/public/decision-preview.js.map +1 -1
- package/dist/server/public/errors.d.ts +15 -4
- package/dist/server/public/errors.js +53 -7
- package/dist/server/public/errors.js.map +1 -1
- package/dist/server/public/forward.js +65 -5
- package/dist/server/public/forward.js.map +1 -1
- package/dist/server/public/index.d.ts +1 -0
- package/dist/server/public/index.js +1 -0
- package/dist/server/public/index.js.map +1 -1
- package/dist/server/public/listing.d.ts +9 -2
- package/dist/server/public/listing.js +30 -9
- package/dist/server/public/listing.js.map +1 -1
- package/dist/server/public/responses.js +9 -5
- package/dist/server/public/responses.js.map +1 -1
- package/dist/server/public/system-messages.d.ts +39 -0
- package/dist/server/public/system-messages.js +166 -0
- package/dist/server/public/system-messages.js.map +1 -0
- package/dist/server/public/telemetry.d.ts +9 -0
- package/dist/server/public/telemetry.js +42 -6
- package/dist/server/public/telemetry.js.map +1 -1
- package/dist/server/public/thinking.d.ts +26 -0
- package/dist/server/public/thinking.js +62 -0
- package/dist/server/public/thinking.js.map +1 -0
- package/dist/server/public/trace.d.ts +8 -0
- package/dist/server/public/trace.js +17 -0
- package/dist/server/public/trace.js.map +1 -1
- package/dist/server/public/types.d.ts +8 -0
- package/dist/server/shims/index.d.ts +1 -0
- package/dist/server/shims/index.js +1 -0
- package/dist/server/shims/index.js.map +1 -1
- package/dist/server/shims/reminders.d.ts +8 -0
- package/dist/server/shims/reminders.js +14 -0
- package/dist/server/shims/reminders.js.map +1 -0
- package/dist/server/shims/responses.d.ts +33 -9
- package/dist/server/shims/responses.js +160 -36
- package/dist/server/shims/responses.js.map +1 -1
- package/dist/settings/default-migrations.d.ts +34 -0
- package/dist/settings/default-migrations.js +47 -0
- package/dist/settings/default-migrations.js.map +1 -0
- package/dist/settings/schema/atomic-prism.json +23 -9
- package/dist/settings/schema/llamacpp-upstream.json +23 -9
- package/dist/settings/schema/llamacpp.json +23 -9
- package/dist/settings/schema/sglang.json +8 -8
- package/dist/settings/schema/vllm.json +8 -8
- package/dist/settings/schema.js +1 -0
- package/dist/settings/schema.js.map +1 -1
- package/dist/settings/store.d.ts +6 -0
- package/dist/settings/store.js +18 -1
- package/dist/settings/store.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -14,6 +14,12 @@
|
|
|
14
14
|
* - `activeEmbeddingProvider` is repaired only when it is missing or dangling, and always to
|
|
15
15
|
* `local-llama`. Repairing it to US would quietly hand memory recall to Atomic Chat, which is not
|
|
16
16
|
* what Run asked for.
|
|
17
|
+
*
|
|
18
|
+
* With no `llm.fallback` block the agent appends `local-llama` to every chain, so a failure of ours
|
|
19
|
+
* (a 404 included) is retried on :8080 and reported as "The local model isn't running": Connect
|
|
20
|
+
* writes `appendLocal: false` there. What the `llm` keys held before is recorded in
|
|
21
|
+
* `config.json.atomic-chat-backup.json` for the app's Disconnect. Mirrors `configure_atomic_agent_at`
|
|
22
|
+
* in the app's `core/system/commands.rs`, byte for byte.
|
|
17
23
|
*/
|
|
18
24
|
import type { JsonValue } from '../config-io.js';
|
|
19
25
|
import type { JsonObject } from './json-tree.js';
|
|
@@ -29,5 +35,7 @@ export declare function atomicAgentEmbeddingBaseUrl(root: JsonObject, chatUrl: s
|
|
|
29
35
|
/** The `llama-server` entry Atomic Agent would synthesise for itself, from the same inputs. */
|
|
30
36
|
export declare function atomicAgentLocalLlamaEntry(root: JsonObject): JsonObject;
|
|
31
37
|
/** The whole merge, with no I/O, so the rules above are testable without a state directory. */
|
|
32
|
-
export declare function atomicAgentPatchConfig(parsed: JsonValue, apiUrl: string, model: string, apiKey: string): JsonObject;
|
|
38
|
+
export declare function atomicAgentPatchConfig(parsed: JsonValue, apiUrl: string, model: string, apiKey: string, contextLength?: number): JsonObject;
|
|
39
|
+
/** The `llm` keys Connect may overwrite besides our provider entry. */
|
|
40
|
+
export declare const ATOMIC_AGENT_TRACKED_PATHS: string[][];
|
|
33
41
|
export declare const configureAtomicAgent: ConfigureWriter;
|
|
@@ -14,9 +14,16 @@
|
|
|
14
14
|
* - `activeEmbeddingProvider` is repaired only when it is missing or dangling, and always to
|
|
15
15
|
* `local-llama`. Repairing it to US would quietly hand memory recall to Atomic Chat, which is not
|
|
16
16
|
* what Run asked for.
|
|
17
|
+
*
|
|
18
|
+
* With no `llm.fallback` block the agent appends `local-llama` to every chain, so a failure of ours
|
|
19
|
+
* (a 404 included) is retried on :8080 and reported as "The local model isn't running": Connect
|
|
20
|
+
* writes `appendLocal: false` there. What the `llm` keys held before is recorded in
|
|
21
|
+
* `config.json.atomic-chat-backup.json` for the app's Disconnect. Mirrors `configure_atomic_agent_at`
|
|
22
|
+
* in the app's `core/system/commands.rs`, byte for byte.
|
|
17
23
|
*/
|
|
18
24
|
import { AtomicCoreError } from '../../contracts/index.js';
|
|
19
25
|
import { canonicalJson, parseJsonStrict } from '../config-io.js';
|
|
26
|
+
import { getAt, readBackup, renderBackup, trackKeys, writeBackupText } from './json-key-backup.js';
|
|
20
27
|
import { asJsonArray, asJsonObject } from './json-tree.js';
|
|
21
28
|
import { registerWriter } from './registry.js';
|
|
22
29
|
const PROVIDER_ID = 'atomic-chat';
|
|
@@ -68,7 +75,7 @@ function lists(providers, id) {
|
|
|
68
75
|
return providers.some((p) => asJsonObject(p)?.['id'] === id);
|
|
69
76
|
}
|
|
70
77
|
/** The whole merge, with no I/O, so the rules above are testable without a state directory. */
|
|
71
|
-
export function atomicAgentPatchConfig(parsed, apiUrl, model, apiKey) {
|
|
78
|
+
export function atomicAgentPatchConfig(parsed, apiUrl, model, apiKey, contextLength) {
|
|
72
79
|
// The agent's `parseOptionalString` rejects `""` outright rather than treating it as absent, so an
|
|
73
80
|
// empty model would take the whole file down at its next start. Fail before touching anything.
|
|
74
81
|
if (model.trim() === '') {
|
|
@@ -102,6 +109,11 @@ export function atomicAgentPatchConfig(parsed, apiUrl, model, apiKey) {
|
|
|
102
109
|
supportsTools: true,
|
|
103
110
|
requestTimeoutMs: timeout,
|
|
104
111
|
};
|
|
112
|
+
// `userModels` outranks the bundled catalog in the agent's `resolveModel`; without it a local model
|
|
113
|
+
// is assumed to hold 128K and is never compacted before the server refuses.
|
|
114
|
+
if (contextLength !== undefined) {
|
|
115
|
+
entry['userModels'] = [{ id: model.trim(), kind: 'chat', contextWindow: contextLength }];
|
|
116
|
+
}
|
|
105
117
|
if (existing >= 0)
|
|
106
118
|
providers[existing] = entry;
|
|
107
119
|
else
|
|
@@ -114,14 +126,41 @@ export function atomicAgentPatchConfig(parsed, apiUrl, model, apiKey) {
|
|
|
114
126
|
llm['activeTextProvider'] = PROVIDER_ID;
|
|
115
127
|
if (repair)
|
|
116
128
|
llm['activeEmbeddingProvider'] = LOCAL_PROVIDER_ID;
|
|
129
|
+
// A chain the user configured is theirs.
|
|
130
|
+
if (llm['fallback'] === undefined || llm['fallback'] === null)
|
|
131
|
+
llm['fallback'] = { appendLocal: false };
|
|
117
132
|
return root;
|
|
118
133
|
}
|
|
119
|
-
|
|
134
|
+
/** The `llm` keys Connect may overwrite besides our provider entry. */
|
|
135
|
+
export const ATOMIC_AGENT_TRACKED_PATHS = [
|
|
136
|
+
['llm', 'activeTextProvider'],
|
|
137
|
+
['llm', 'activeEmbeddingProvider'],
|
|
138
|
+
['llm', 'fallback'],
|
|
139
|
+
];
|
|
140
|
+
export const configureAtomicAgent = async ({ apiUrl, model, apiKey, fs, env, contextLength, }) => {
|
|
120
141
|
const override = env['ATOMIC_AGENT_STATE_DIR']?.trim();
|
|
121
142
|
const path = `${override && override !== '' ? override : '.atomic-agent'}/config.json`;
|
|
122
143
|
const text = await fs.read(path);
|
|
123
144
|
const parsed = text === undefined ? {} : parseJsonStrict(text, fs.absolute(path));
|
|
124
|
-
|
|
145
|
+
const before = JSON.parse(JSON.stringify(parsed));
|
|
146
|
+
const patched = atomicAgentPatchConfig(parsed, apiUrl, model, apiKey, contextLength);
|
|
147
|
+
// The `local-llama` entry this Connect added, or an earlier one did: Disconnect drops it when
|
|
148
|
+
// nothing else is left.
|
|
149
|
+
const previous = await readBackup(fs, path);
|
|
150
|
+
const listed = (value) => asJsonArray(getAt(value, ['llm', 'providers'])) ?? [];
|
|
151
|
+
const same = (a, b) => canonicalJson(a) === canonicalJson(b);
|
|
152
|
+
const seeded = [...(previous?.seeded ?? [])];
|
|
153
|
+
const original = listed(before);
|
|
154
|
+
for (const entry of listed(patched)) {
|
|
155
|
+
if (asJsonObject(entry)?.['id'] === LOCAL_PROVIDER_ID &&
|
|
156
|
+
!original.some((e) => same(e, entry)) &&
|
|
157
|
+
!seeded.some((e) => same(e, entry))) {
|
|
158
|
+
seeded.push(entry);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const keys = trackKeys(before, patched, ATOMIC_AGENT_TRACKED_PATHS, previous?.keys ?? []);
|
|
162
|
+
await fs.write(path, canonicalJson(patched));
|
|
163
|
+
await writeBackupText(fs, path, renderBackup({ keys, seeded }));
|
|
125
164
|
};
|
|
126
165
|
registerWriter('atomic-agent', configureAtomicAgent);
|
|
127
166
|
//# sourceMappingURL=atomic-agent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atomic-agent.js","sourceRoot":"","sources":["../../../src/integrations/configure/atomic-agent.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"atomic-agent.js","sourceRoot":"","sources":["../../../src/integrations/configure/atomic-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,aA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EAAE,CAAY,EAAE,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,CAAA;IAClF,MAAM,MAAM,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC,CAAA;IAC5C,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;IAC/B,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QACpC,IACE,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,iBAAiB;YACjD,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YACrC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EACnC,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACpB,CAAC;IACH,CAAC;IACD,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,CAAA;IACzF,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC,CAAA;IAC5C,MAAM,eAAe,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;AACjE,CAAC,CAAA;AAED,cAAc,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The backup sidecar the desktop's Disconnect reads — twin of `agent_files.rs` in the app.
|
|
3
|
+
*
|
|
4
|
+
* `<config file>.atomic-chat-backup.json` records what the keys a writer overwrites held before the
|
|
5
|
+
* first Connect (`previous`) and what the writer put there (`written`). Disconnect restores
|
|
6
|
+
* `previous` only while the file still holds `written`, so a later choice of the user's stands. A
|
|
7
|
+
* `launch` from this CLI writes the same sidecar as the desktop, so either side can undo the other.
|
|
8
|
+
*/
|
|
9
|
+
import type { ConfigFs, JsonValue } from '../config-io.js';
|
|
10
|
+
import type { JsonObject } from './json-tree.js';
|
|
11
|
+
export declare function sidecarPath(path: string): string;
|
|
12
|
+
/** The sidecar of `path`, when there is one; one that does not parse only narrows what is restored. */
|
|
13
|
+
export declare function readSidecar(fs: ConfigFs, path: string): Promise<JsonObject | undefined>;
|
|
14
|
+
/** Owner-only off Windows: the previous values can include another provider's key. */
|
|
15
|
+
export declare function writeSidecar(fs: ConfigFs, path: string, backup: JsonValue, platform: NodeJS.Platform): Promise<void>;
|
|
16
|
+
/** The window to write, or `undefined` when it is not known. */
|
|
17
|
+
export declare function knownWindow(contextLength: number | undefined): number | undefined;
|
|
18
|
+
/** The reply cap written beside a known window: a quarter of it, and never more than 8192. */
|
|
19
|
+
export declare function outputCap(contextLength: number): number;
|
|
20
|
+
/** Deep equality of two JSON values, key order aside. */
|
|
21
|
+
export declare function sameJson(a: JsonValue | undefined, b: JsonValue | undefined): boolean;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The backup sidecar the desktop's Disconnect reads — twin of `agent_files.rs` in the app.
|
|
3
|
+
*
|
|
4
|
+
* `<config file>.atomic-chat-backup.json` records what the keys a writer overwrites held before the
|
|
5
|
+
* first Connect (`previous`) and what the writer put there (`written`). Disconnect restores
|
|
6
|
+
* `previous` only while the file still holds `written`, so a later choice of the user's stands. A
|
|
7
|
+
* `launch` from this CLI writes the same sidecar as the desktop, so either side can undo the other.
|
|
8
|
+
*/
|
|
9
|
+
import { canonicalJson } from '../config-io.js';
|
|
10
|
+
import { asJsonObject } from './json-tree.js';
|
|
11
|
+
export function sidecarPath(path) {
|
|
12
|
+
return `${path}.atomic-chat-backup.json`;
|
|
13
|
+
}
|
|
14
|
+
/** The sidecar of `path`, when there is one; one that does not parse only narrows what is restored. */
|
|
15
|
+
export async function readSidecar(fs, path) {
|
|
16
|
+
const text = await fs.read(sidecarPath(path));
|
|
17
|
+
if (text === undefined)
|
|
18
|
+
return undefined;
|
|
19
|
+
try {
|
|
20
|
+
return asJsonObject(JSON.parse(text));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Owner-only off Windows: the previous values can include another provider's key. */
|
|
27
|
+
export async function writeSidecar(fs, path, backup, platform) {
|
|
28
|
+
await fs.write(sidecarPath(path), canonicalJson(backup), platform === 'win32' ? {} : { mode: 0o600 });
|
|
29
|
+
}
|
|
30
|
+
/** The window to write, or `undefined` when it is not known. */
|
|
31
|
+
export function knownWindow(contextLength) {
|
|
32
|
+
return contextLength !== undefined && contextLength > 0 ? contextLength : undefined;
|
|
33
|
+
}
|
|
34
|
+
/** The reply cap written beside a known window: a quarter of it, and never more than 8192. */
|
|
35
|
+
export function outputCap(contextLength) {
|
|
36
|
+
return Math.min(8192, Math.floor(contextLength / 4));
|
|
37
|
+
}
|
|
38
|
+
/** Deep equality of two JSON values, key order aside. */
|
|
39
|
+
export function sameJson(a, b) {
|
|
40
|
+
if (a === b)
|
|
41
|
+
return true;
|
|
42
|
+
if (a === undefined || b === undefined || a === null || b === null)
|
|
43
|
+
return false;
|
|
44
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
45
|
+
return (Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((v, i) => sameJson(v, b[i])));
|
|
46
|
+
}
|
|
47
|
+
if (typeof a !== 'object' || typeof b !== 'object')
|
|
48
|
+
return false;
|
|
49
|
+
const keys = Object.keys(a);
|
|
50
|
+
return (keys.length === Object.keys(b).length && keys.every((k) => Object.hasOwn(b, k) && sameJson(a[k], b[k])));
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingUR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,CAAA;AACH,CAAC"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Claude Code — `~/.claude
|
|
2
|
+
* Claude Code — `settings.json` in its config directory (`$CLAUDE_CONFIG_DIR`, else `~/.claude`).
|
|
3
3
|
*
|
|
4
|
-
* Port of `configure_claude_code` in `src-tauri/src/core/system/
|
|
5
|
-
* endpoint from environment variables that its settings
|
|
6
|
-
*
|
|
4
|
+
* Port of `configure_claude_code` / `connect_claude_code` in the app (`src-tauri/src/core/system/
|
|
5
|
+
* claude_config.rs`). Claude Code takes its endpoint from environment variables that its settings
|
|
6
|
+
* file can carry, and that `env` wins over the shell's, so pointing it at a local model is an upsert
|
|
7
|
+
* into that map plus the top-level `model` setting. Alongside the endpoint go empty values for the
|
|
8
|
+
* Bedrock / Vertex / Foundry switches (Claude Code's documented way to unset a shell's), the tab
|
|
9
|
+
* title off (it costs a side request to the model) and, when the served window is known, that window
|
|
10
|
+
* and an output cap so Claude Code compacts before the server refuses. What every key held before is
|
|
11
|
+
* kept in the sidecar `json-backup.ts` describes, for the app's Disconnect.
|
|
7
12
|
*
|
|
8
13
|
* Claude Code appends its own `/v1`, so `apiUrl` here is the bare `host:port` (the catalog marks
|
|
9
14
|
* this agent `endpointWithPrefix: false`).
|
|
@@ -13,4 +18,6 @@
|
|
|
13
18
|
* ones an earlier run left behind, so a rerun without a model keeps pointing at the last one.
|
|
14
19
|
*/
|
|
15
20
|
import type { ConfigureInput } from './registry.js';
|
|
21
|
+
/** `settings.json` in `$CLAUDE_CONFIG_DIR` (absolute or `~`-relative), else `.claude/settings.json`. */
|
|
22
|
+
export declare function claudeSettingsPath(input: Pick<ConfigureInput, 'env' | 'fs'>): string;
|
|
16
23
|
export declare function configureClaudeCode(input: ConfigureInput): Promise<void>;
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Claude Code — `~/.claude
|
|
2
|
+
* Claude Code — `settings.json` in its config directory (`$CLAUDE_CONFIG_DIR`, else `~/.claude`).
|
|
3
3
|
*
|
|
4
|
-
* Port of `configure_claude_code` in `src-tauri/src/core/system/
|
|
5
|
-
* endpoint from environment variables that its settings
|
|
6
|
-
*
|
|
4
|
+
* Port of `configure_claude_code` / `connect_claude_code` in the app (`src-tauri/src/core/system/
|
|
5
|
+
* claude_config.rs`). Claude Code takes its endpoint from environment variables that its settings
|
|
6
|
+
* file can carry, and that `env` wins over the shell's, so pointing it at a local model is an upsert
|
|
7
|
+
* into that map plus the top-level `model` setting. Alongside the endpoint go empty values for the
|
|
8
|
+
* Bedrock / Vertex / Foundry switches (Claude Code's documented way to unset a shell's), the tab
|
|
9
|
+
* title off (it costs a side request to the model) and, when the served window is known, that window
|
|
10
|
+
* and an output cap so Claude Code compacts before the server refuses. What every key held before is
|
|
11
|
+
* kept in the sidecar `json-backup.ts` describes, for the app's Disconnect.
|
|
7
12
|
*
|
|
8
13
|
* Claude Code appends its own `/v1`, so `apiUrl` here is the bare `host:port` (the catalog marks
|
|
9
14
|
* this agent `endpointWithPrefix: false`).
|
|
@@ -12,34 +17,78 @@
|
|
|
12
17
|
* this agent, and the writer then leaves every model key alone — it neither writes them nor removes
|
|
13
18
|
* ones an earlier run left behind, so a rerun without a model keeps pointing at the last one.
|
|
14
19
|
*/
|
|
20
|
+
import { join } from 'node:path';
|
|
15
21
|
import { AtomicCoreError } from '../../contracts/index.js';
|
|
16
22
|
import { canonicalJson, keyOr, parseJsonStrict } from '../config-io.js';
|
|
23
|
+
import { configDirFrom, getAt, isOurServerUrl, ourServerFromUrl, outputCap, readBackup, redo, writeBackup, writeConfigFile, } from './json-backup.js';
|
|
17
24
|
import { asJsonObject } from './json-tree.js';
|
|
18
25
|
import { registerWriter } from './registry.js';
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
const MODEL_KEYS = [
|
|
27
|
+
'ANTHROPIC_MODEL',
|
|
28
|
+
'ANTHROPIC_DEFAULT_OPUS_MODEL',
|
|
29
|
+
'ANTHROPIC_DEFAULT_SONNET_MODEL',
|
|
30
|
+
'ANTHROPIC_DEFAULT_HAIKU_MODEL',
|
|
31
|
+
];
|
|
32
|
+
/** Provider switches a shell can export that Claude Code would follow instead of our endpoint. */
|
|
33
|
+
const PROVIDER_SWITCHES = [
|
|
34
|
+
'CLAUDE_CODE_USE_BEDROCK',
|
|
35
|
+
'CLAUDE_CODE_USE_VERTEX',
|
|
36
|
+
'CLAUDE_CODE_USE_FOUNDRY',
|
|
37
|
+
];
|
|
38
|
+
const env = (key) => ['env', key];
|
|
39
|
+
const MODEL_PATHS = [...MODEL_KEYS.map(env), ['model']];
|
|
40
|
+
/** `settings.json` in `$CLAUDE_CONFIG_DIR` (absolute or `~`-relative), else `.claude/settings.json`. */
|
|
41
|
+
export function claudeSettingsPath(input) {
|
|
42
|
+
const dir = configDirFrom(input.env['CLAUDE_CONFIG_DIR'], input.fs.home);
|
|
43
|
+
return dir === undefined ? '.claude/settings.json' : join(dir, 'settings.json');
|
|
44
|
+
}
|
|
45
|
+
function writesFor(input) {
|
|
46
|
+
const { apiUrl, model, apiKey, contextLength } = input;
|
|
47
|
+
const writes = [
|
|
48
|
+
[env('ANTHROPIC_BASE_URL'), apiUrl],
|
|
49
|
+
[env('ANTHROPIC_AUTH_TOKEN'), keyOr(apiKey, 'atomic')],
|
|
50
|
+
];
|
|
51
|
+
for (const name of PROVIDER_SWITCHES)
|
|
52
|
+
writes.push([env(name), '']);
|
|
53
|
+
writes.push([env('CLAUDE_CODE_DISABLE_TERMINAL_TITLE'), '1']);
|
|
54
|
+
if (contextLength !== undefined && contextLength > 0) {
|
|
55
|
+
writes.push([env('CLAUDE_CODE_MAX_CONTEXT_TOKENS'), String(contextLength)]);
|
|
56
|
+
writes.push([env('CLAUDE_CODE_MAX_OUTPUT_TOKENS'), String(outputCap(contextLength))]);
|
|
57
|
+
}
|
|
33
58
|
if (model !== '') {
|
|
34
59
|
// ANTHROPIC_MODEL overrides the `model` setting; the tier aliases make every Opus/Sonnet/Haiku
|
|
35
60
|
// request route to the single local model too.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
env['ANTHROPIC_DEFAULT_HAIKU_MODEL'] = model;
|
|
40
|
-
root['model'] = model;
|
|
61
|
+
for (const key of MODEL_KEYS)
|
|
62
|
+
writes.push([env(key), model]);
|
|
63
|
+
writes.push([['model'], model]);
|
|
41
64
|
}
|
|
42
|
-
|
|
65
|
+
return writes;
|
|
66
|
+
}
|
|
67
|
+
/** Settings an earlier release wrote without a backup: the endpoint is this server. */
|
|
68
|
+
function forgetLegacy(root, server) {
|
|
69
|
+
const base = getAt(root, env('ANTHROPIC_BASE_URL'));
|
|
70
|
+
if (typeof base !== 'string' || !isOurServerUrl(server, base))
|
|
71
|
+
return;
|
|
72
|
+
const envObject = asJsonObject(root['env']);
|
|
73
|
+
const model = envObject['ANTHROPIC_MODEL'];
|
|
74
|
+
for (const key of ['ANTHROPIC_BASE_URL', 'ANTHROPIC_AUTH_TOKEN', ...MODEL_KEYS])
|
|
75
|
+
delete envObject[key];
|
|
76
|
+
if (model !== undefined && root['model'] === model)
|
|
77
|
+
delete root['model'];
|
|
78
|
+
}
|
|
79
|
+
export async function configureClaudeCode(input) {
|
|
80
|
+
const { fs, apiUrl } = input;
|
|
81
|
+
const path = claudeSettingsPath(input);
|
|
82
|
+
const text = await fs.read(path);
|
|
83
|
+
const parsed = text === undefined ? {} : parseJsonStrict(text, fs.absolute(path));
|
|
84
|
+
const root = asJsonObject(parsed);
|
|
85
|
+
if (!root)
|
|
86
|
+
throw new AtomicCoreError('IO_ERROR', 'settings.json is not a JSON object');
|
|
87
|
+
const server = ourServerFromUrl(apiUrl);
|
|
88
|
+
const backup = redo(root, await readBackup(fs, path), text !== undefined, writesFor(input), MODEL_PATHS, (r) => forgetLegacy(r, server));
|
|
89
|
+
// Sidecar first: a crash between the two leaves a backup whose values simply do not match yet.
|
|
90
|
+
await writeBackup(fs, path, backup);
|
|
91
|
+
await writeConfigFile(fs, path, canonicalJson(root));
|
|
43
92
|
}
|
|
44
93
|
registerWriter('claude-code', configureClaudeCode);
|
|
45
94
|
//# sourceMappingURL=claude-code.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-code.js","sourceRoot":"","sources":["../../../src/integrations/configure/claude-code.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"claude-code.js","sourceRoot":"","sources":["../../../src/integrations/configure/claude-code.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEvE,OAAO,EACL,aAAa,EACb,KAAK,EACL,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,IAAI,EACJ,WAAW,EACX,eAAe,GAChB,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,UAAU,GAAG;IACjB,iBAAiB;IACjB,8BAA8B;IAC9B,gCAAgC;IAChC,+BAA+B;CACvB,CAAA;AACV,kGAAkG;AAClG,MAAM,iBAAiB,GAAG;IACxB,yBAAyB;IACzB,wBAAwB;IACxB,yBAAyB;CACjB,CAAA;AAEV,MAAM,GAAG,GAAG,CAAC,GAAW,EAAY,EAAE,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;AACnD,MAAM,WAAW,GAAe,CAAC,GAAG,UAAU,CAAC,GAAG,CAA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C,CAAC,CAAC,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAA;IACjF,MAAM,IAAI,GAAG,YAAY,CAAC,MAAM,CAAC,CAAA;IACjC,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,eAAe,CAAC,UAAU,EAAE,oCAAoC,CAAC,CAAA;IAEtF,MAAM,MAAM,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAA;IACvC,MAAM,MAAM,GAAG,IAAI,CACjB,IAAI,EACJ,MAAM,UAAU,CAAC,EAAE,EAAE,IAAI,CAAC,EAC1B,IAAI,KAAK,SAAS,EAClB,SAAS,CAAC,KAAK,CAAC,EAChB,WAAW,EACX,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,CAC/B,CAAA;IACD,+FAA+F;IAC/F,MAAM,WAAW,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IACnC,MAAM,eAAe,CAAC,EAAE,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAA;AACtD,CAAC;AAED,cAAc,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAA"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Cline —
|
|
2
|
+
* Cline — configured by its own `cline auth` subcommand.
|
|
3
3
|
*
|
|
4
|
-
* Port of `configure_cline` in `src-tauri/src/core/system/commands.rs
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Port of `configure_cline` in `src-tauri/src/core/system/commands.rs` and `cline_config.rs`. The
|
|
5
|
+
* supported way in is `cline auth --provider openai-compatible …`, which saves the provider into
|
|
6
|
+
* Cline's `providers.json` (`<CLINE_DIR>/data/settings/providers.json`) and makes it
|
|
7
|
+
* `lastUsedProvider`, so configuring it means running a process and reporting what it said. It has
|
|
8
|
+
* no flag for the context window, which Cline 3.x reads from the entry's `contextWindow` (and the
|
|
9
|
+
* reply cap from `maxTokens`): both are set on the saved entry afterwards, and removed when the
|
|
10
|
+
* window is unknown. The entry and `lastUsedProvider` from before are kept in the backup sidecar for
|
|
11
|
+
* the desktop's Disconnect, read before `cline auth` rewrites them.
|
|
7
12
|
*
|
|
8
13
|
* On Windows the npm-installed `cline` is a batch shim (`cline.cmd`), which `CreateProcessW` refuses
|
|
9
14
|
* to execute directly, so the call is routed through `cmd /C`.
|
|
@@ -25,4 +30,9 @@ export declare function clineAuthCommand(apiUrl: string, model: string, apiKey:
|
|
|
25
30
|
* outcomes Cline's caller has to report differently.
|
|
26
31
|
*/
|
|
27
32
|
export declare function spawnProcess(program: string, args: string[]): Promise<SpawnResult>;
|
|
33
|
+
/**
|
|
34
|
+
* `providers.json` where Cline resolves it: `$CLINE_PROVIDER_SETTINGS_PATH`, else
|
|
35
|
+
* `$CLINE_DATA_DIR/settings`, else `$CLINE_DIR/data/settings`, else `~/.cline/data/settings`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function clineProvidersPath(env: NodeJS.ProcessEnv, home: string): string;
|
|
28
38
|
export declare function configureCline(input: ConfigureInput): Promise<void>;
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Cline —
|
|
2
|
+
* Cline — configured by its own `cline auth` subcommand.
|
|
3
3
|
*
|
|
4
|
-
* Port of `configure_cline` in `src-tauri/src/core/system/commands.rs
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Port of `configure_cline` in `src-tauri/src/core/system/commands.rs` and `cline_config.rs`. The
|
|
5
|
+
* supported way in is `cline auth --provider openai-compatible …`, which saves the provider into
|
|
6
|
+
* Cline's `providers.json` (`<CLINE_DIR>/data/settings/providers.json`) and makes it
|
|
7
|
+
* `lastUsedProvider`, so configuring it means running a process and reporting what it said. It has
|
|
8
|
+
* no flag for the context window, which Cline 3.x reads from the entry's `contextWindow` (and the
|
|
9
|
+
* reply cap from `maxTokens`): both are set on the saved entry afterwards, and removed when the
|
|
10
|
+
* window is unknown. The entry and `lastUsedProvider` from before are kept in the backup sidecar for
|
|
11
|
+
* the desktop's Disconnect, read before `cline auth` rewrites them.
|
|
7
12
|
*
|
|
8
13
|
* On Windows the npm-installed `cline` is a batch shim (`cline.cmd`), which `CreateProcessW` refuses
|
|
9
14
|
* to execute directly, so the call is routed through `cmd /C`.
|
|
10
15
|
*/
|
|
11
16
|
import { execFile } from 'node:child_process';
|
|
12
17
|
import { AtomicCoreError } from '../../contracts/index.js';
|
|
13
|
-
import { keyOr } from '../config-io.js';
|
|
18
|
+
import { canonicalJson, expandTilde, keyOr, parseJsonStrict } from '../config-io.js';
|
|
19
|
+
import { knownWindow, outputCap, readSidecar, sameJson, writeSidecar } from './backup.js';
|
|
20
|
+
import { asJsonObject } from './json-tree.js';
|
|
14
21
|
import { registerWriter } from './registry.js';
|
|
22
|
+
const PROVIDER = 'openai-compatible';
|
|
15
23
|
/** Argv for `cline auth`, split out so both the writer and its tests can name the exact command. */
|
|
16
24
|
export function clineAuthCommand(apiUrl, model, apiKey, platform) {
|
|
17
25
|
// Cline rejects an empty `--apikey` (and an empty `--modelid`), so a keyless local server gets a
|
|
@@ -19,7 +27,7 @@ export function clineAuthCommand(apiUrl, model, apiKey, platform) {
|
|
|
19
27
|
const args = [
|
|
20
28
|
'auth',
|
|
21
29
|
'--provider',
|
|
22
|
-
|
|
30
|
+
PROVIDER,
|
|
23
31
|
'--apikey',
|
|
24
32
|
keyOr(apiKey, 'local'),
|
|
25
33
|
'--modelid',
|
|
@@ -49,9 +57,52 @@ export function spawnProcess(program, args) {
|
|
|
49
57
|
});
|
|
50
58
|
});
|
|
51
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* `providers.json` where Cline resolves it: `$CLINE_PROVIDER_SETTINGS_PATH`, else
|
|
62
|
+
* `$CLINE_DATA_DIR/settings`, else `$CLINE_DIR/data/settings`, else `~/.cline/data/settings`.
|
|
63
|
+
*/
|
|
64
|
+
export function clineProvidersPath(env, home) {
|
|
65
|
+
const value = (name) => {
|
|
66
|
+
const raw = env[name]?.trim();
|
|
67
|
+
return raw ? expandTilde(raw, home) : undefined;
|
|
68
|
+
};
|
|
69
|
+
const file = value('CLINE_PROVIDER_SETTINGS_PATH');
|
|
70
|
+
if (file !== undefined)
|
|
71
|
+
return file;
|
|
72
|
+
const data = value('CLINE_DATA_DIR') ?? `${value('CLINE_DIR') ?? '.cline'}/data`;
|
|
73
|
+
return `${data}/settings/providers.json`;
|
|
74
|
+
}
|
|
75
|
+
async function readProviders(fs, path) {
|
|
76
|
+
const text = await fs.read(path);
|
|
77
|
+
const parsed = text === undefined ? {} : parseJsonStrict(text, fs.absolute(path));
|
|
78
|
+
const root = asJsonObject(parsed);
|
|
79
|
+
if (!root)
|
|
80
|
+
throw new AtomicCoreError('IO_ERROR', `${fs.absolute(path)} is not a JSON object`);
|
|
81
|
+
return root;
|
|
82
|
+
}
|
|
83
|
+
const entrySettings = (root) => asJsonObject(asJsonObject(asJsonObject(root['providers'])?.[PROVIDER])?.['settings']);
|
|
84
|
+
/** Whether the entry still points where we pointed it. */
|
|
85
|
+
function holdsOurs(root, written) {
|
|
86
|
+
const settings = entrySettings(root);
|
|
87
|
+
const ours = asJsonObject(written);
|
|
88
|
+
return (settings !== undefined &&
|
|
89
|
+
ours !== undefined &&
|
|
90
|
+
sameJson(settings['baseUrl'], ours['baseUrl']) &&
|
|
91
|
+
sameJson(settings['model'], ours['model']));
|
|
92
|
+
}
|
|
52
93
|
export async function configureCline(input) {
|
|
53
94
|
const { program, args } = clineAuthCommand(input.apiUrl, input.model, input.apiKey, input.platform);
|
|
54
95
|
const spawn = input.spawn ?? spawnProcess;
|
|
96
|
+
// What the desktop's Disconnect restores, read before `cline auth` rewrites it — and kept as it
|
|
97
|
+
// is across reconnects while the file still holds ours.
|
|
98
|
+
const path = clineProvidersPath(input.env, input.fs.home);
|
|
99
|
+
const before = await readProviders(input.fs, path);
|
|
100
|
+
const backup = await readSidecar(input.fs, path);
|
|
101
|
+
const kept = backup !== undefined && holdsOurs(before, backup['written']) ? backup['previous'] : undefined;
|
|
102
|
+
const previous = kept ?? {
|
|
103
|
+
lastUsedProvider: before['lastUsedProvider'] ?? null,
|
|
104
|
+
entry: asJsonObject(before['providers'])?.[PROVIDER] ?? null,
|
|
105
|
+
};
|
|
55
106
|
let result;
|
|
56
107
|
try {
|
|
57
108
|
result = await spawn(program, args);
|
|
@@ -65,6 +116,27 @@ export async function configureCline(input) {
|
|
|
65
116
|
const detail = stderr === '' ? result.stdout.trim() : stderr;
|
|
66
117
|
throw new AtomicCoreError('INTERNAL_ERROR', `\`cline auth\` failed: ${detail}`);
|
|
67
118
|
}
|
|
119
|
+
// `cline auth` has no flag for the window; set it on the entry it saved, or clear what the entry
|
|
120
|
+
// carried for the endpoint it pointed at before.
|
|
121
|
+
const after = await readProviders(input.fs, path);
|
|
122
|
+
const settings = entrySettings(after);
|
|
123
|
+
if (settings !== undefined) {
|
|
124
|
+
const was = canonicalJson(settings);
|
|
125
|
+
const window = knownWindow(input.contextLength);
|
|
126
|
+
if (window !== undefined) {
|
|
127
|
+
settings['contextWindow'] = window;
|
|
128
|
+
settings['maxTokens'] = outputCap(window);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
delete settings['contextWindow'];
|
|
132
|
+
delete settings['maxTokens'];
|
|
133
|
+
}
|
|
134
|
+
// Cline keeps the file owner-only: it holds every provider's key.
|
|
135
|
+
if (canonicalJson(settings) !== was) {
|
|
136
|
+
await input.fs.write(path, canonicalJson(after), input.platform === 'win32' ? {} : { mode: 0o600 });
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
await writeSidecar(input.fs, path, { previous, written: { baseUrl: input.apiUrl, model: input.model } }, input.platform);
|
|
68
140
|
}
|
|
69
141
|
registerWriter('cline', configureCline);
|
|
70
142
|
//# sourceMappingURL=cline.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cline.js","sourceRoot":"","sources":["../../../src/integrations/configure/cline.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"cline.js","sourceRoot":"","sources":["../../../src/integrations/configure/cline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACpF,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAEzF,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,QAAQ,GAAG,mBAAmB,CAAA;AAQpC,oGAAoG;AACpG,MAAM,UAAU,gBAAgB,CAC9B,MAAc,EACd,KAAa,EACb,MAAc,EACd,QAAyB;IAEzB,iGAAiG;IACjG,gGAAgG;IAChG,MAAM,IAAI,GAAG;QACX,MAAM;QACN,YAAY;QACZ,QAAQ;QACR,UAAU;QACV,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC;QACtB,WAAW;QACX,KAAK;QACL,WAAW;QACX,MAAM;KACP,CAAA;IACD,OAAO,QAAQ,KAAK,OAAO;QACzB,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,EAAE;QACpD,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe,EAAE,IAAc;IAC1D,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,QAAQ,CAAC,OAA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CAAA;AACH,CAAC;AAED,cAAc,CAAC,OAAO,EAAE,cAAc,CAAC,CAAA"}
|
|
@@ -41,9 +41,11 @@ export declare function codexHome(env: NodeJS.ProcessEnv, home: string): string;
|
|
|
41
41
|
export declare function codexProfilePath(dir: string): string;
|
|
42
42
|
/**
|
|
43
43
|
* The profile's exact bytes. Codex reads the key from the variable `env_key` names, never inline, so
|
|
44
|
-
* a keyless server gets no `env_key` line at all and `launch` sets the variable on the child.
|
|
44
|
+
* a keyless server gets no `env_key` line at all and `launch` sets the variable on the child. A known
|
|
45
|
+
* served window is written as `model_context_window` (Codex otherwise assumes 272K for a model it
|
|
46
|
+
* does not know) with compaction at three quarters of it; an unknown one writes neither line.
|
|
45
47
|
*/
|
|
46
|
-
export declare function renderCodexProfile(apiUrl: string, model: string, apiKey: string): string;
|
|
48
|
+
export declare function renderCodexProfile(apiUrl: string, model: string, apiKey: string, contextLength?: number): string;
|
|
47
49
|
/** `codex --version` prints `codex-cli 0.146.0`: the first `x.y.z` in the output. */
|
|
48
50
|
export declare function parseCodexVersion(output: string): CodexVersion | undefined;
|
|
49
51
|
export declare function isCodexTooOld([major, minor, patch]: CodexVersion): boolean;
|
|
@@ -51,5 +53,5 @@ export declare function isCodexTooOld([major, minor, patch]: CodexVersion): bool
|
|
|
51
53
|
* Write the profile, refusing to replace a file of that name Atomic Chat did not write. Returns its
|
|
52
54
|
* path. A profile that cannot be read is an error, never "absent"; a symbolic link is written through.
|
|
53
55
|
*/
|
|
54
|
-
export declare function writeCodexProfile(fs: ConfigFs, dir: string, apiUrl: string, model: string, apiKey: string): Promise<string>;
|
|
56
|
+
export declare function writeCodexProfile(fs: ConfigFs, dir: string, apiUrl: string, model: string, apiKey: string, contextLength?: number): Promise<string>;
|
|
55
57
|
export declare function configureCodex(input: ConfigureInput): Promise<void>;
|
|
@@ -49,13 +49,20 @@ export function codexProfilePath(dir) {
|
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* The profile's exact bytes. Codex reads the key from the variable `env_key` names, never inline, so
|
|
52
|
-
* a keyless server gets no `env_key` line at all and `launch` sets the variable on the child.
|
|
52
|
+
* a keyless server gets no `env_key` line at all and `launch` sets the variable on the child. A known
|
|
53
|
+
* served window is written as `model_context_window` (Codex otherwise assumes 272K for a model it
|
|
54
|
+
* does not know) with compaction at three quarters of it; an unknown one writes neither line.
|
|
53
55
|
*/
|
|
54
|
-
export function renderCodexProfile(apiUrl, model, apiKey) {
|
|
56
|
+
export function renderCodexProfile(apiUrl, model, apiKey, contextLength) {
|
|
57
|
+
const window = contextLength !== undefined && contextLength > 0
|
|
58
|
+
? `model_context_window = ${contextLength}\n` +
|
|
59
|
+
`model_auto_compact_token_limit = ${Math.floor((contextLength * 3) / 4)}\n`
|
|
60
|
+
: '';
|
|
55
61
|
return (`${CODEX_PROFILE_OWNER_PREFIX}: \`codex --profile ${CODEX_PROFILE}\` runs Codex on your local models.\n` +
|
|
56
62
|
'# Atomic Chat rewrites this file when Codex is connected again and deletes it on disconnect.\n' +
|
|
57
63
|
`model = "${tomlBasicStringEscape(model)}"\n` +
|
|
58
64
|
`model_provider = "${CODEX_PROFILE}"\n` +
|
|
65
|
+
window +
|
|
59
66
|
'\n' +
|
|
60
67
|
`[model_providers.${CODEX_PROFILE}]\n` +
|
|
61
68
|
'name = "Atomic Chat"\n' +
|
|
@@ -79,9 +86,9 @@ export function isCodexTooOld([major, minor, patch]) {
|
|
|
79
86
|
* Write the profile, refusing to replace a file of that name Atomic Chat did not write. Returns its
|
|
80
87
|
* path. A profile that cannot be read is an error, never "absent"; a symbolic link is written through.
|
|
81
88
|
*/
|
|
82
|
-
export async function writeCodexProfile(fs, dir, apiUrl, model, apiKey) {
|
|
89
|
+
export async function writeCodexProfile(fs, dir, apiUrl, model, apiKey, contextLength) {
|
|
83
90
|
const path = codexProfilePath(dir);
|
|
84
|
-
const contents = renderCodexProfile(apiUrl, model, apiKey);
|
|
91
|
+
const contents = renderCodexProfile(apiUrl, model, apiKey, contextLength);
|
|
85
92
|
// Cannot fail with the escaping above; it keeps a future edit of the template from shipping a file
|
|
86
93
|
// Codex would reject.
|
|
87
94
|
parseToml(contents);
|
|
@@ -131,7 +138,7 @@ export async function configureCodex(input) {
|
|
|
131
138
|
const repair = await repairLegacyCodexConfig(input.fs, dir, input.platform);
|
|
132
139
|
if (repair.kind === 'conflict')
|
|
133
140
|
throw new AtomicCoreError('IO_ERROR', repair.reason);
|
|
134
|
-
await writeCodexProfile(input.fs, dir, input.apiUrl, input.model, input.apiKey);
|
|
141
|
+
await writeCodexProfile(input.fs, dir, input.apiUrl, input.model, input.apiKey, input.contextLength);
|
|
135
142
|
}
|
|
136
143
|
registerWriter('codex', configureCodex);
|
|
137
144
|
//# sourceMappingURL=codex.js.map
|