@openagents-org/agent-launcher 0.2.211 → 0.2.213
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/package.json +1 -1
- package/registry.json +4 -4
- package/src/adapters/deepseek-runtime.js +31 -5
- package/src/adapters/deepseek-workspace-api.js +150 -0
- package/src/adapters/deepseek.js +30 -3
- package/src/adapters/kimi-stream.js +66 -0
- package/src/adapters/kimi.js +142 -6
- package/src/adapters/workspace-prompt.js +41 -4
- package/src/cli.js +23 -11
package/package.json
CHANGED
package/registry.json
CHANGED
|
@@ -1807,12 +1807,12 @@
|
|
|
1807
1807
|
"requires": [
|
|
1808
1808
|
"nodejs"
|
|
1809
1809
|
],
|
|
1810
|
-
"supported_version": "0.2.1-rc.
|
|
1810
|
+
"supported_version": "0.2.1-rc.5",
|
|
1811
1811
|
"verify": "dsh -V >/dev/null 2>&1",
|
|
1812
1812
|
"verify_win": "dsh -V >nul 2>nul",
|
|
1813
|
-
"macos": "npm install -g @deepseek-ai/dsh@0.2.1-rc.
|
|
1814
|
-
"linux": "npm install -g @deepseek-ai/dsh@0.2.1-rc.
|
|
1815
|
-
"windows": "npm install -g @deepseek-ai/dsh@0.2.1-rc.
|
|
1813
|
+
"macos": "npm install -g @deepseek-ai/dsh@0.2.1-rc.5",
|
|
1814
|
+
"linux": "npm install -g @deepseek-ai/dsh@0.2.1-rc.5",
|
|
1815
|
+
"windows": "npm install -g @deepseek-ai/dsh@0.2.1-rc.5"
|
|
1816
1816
|
},
|
|
1817
1817
|
"uninstall": {
|
|
1818
1818
|
"macos": "npm uninstall -g @deepseek-ai/dsh",
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* so the adapter itself stays a thin subprocess driver. The split mirrors
|
|
6
6
|
* cline-stream.js / pi-stream.js.
|
|
7
7
|
*
|
|
8
|
-
* Verified against @deepseek-ai/dsh 0.2.1-rc.
|
|
8
|
+
* Verified against @deepseek-ai/dsh 0.2.1-rc.5 (bin `dsh` -> lib/bin.js, ESM).
|
|
9
9
|
*
|
|
10
10
|
* Three things here exist because dsh is unlike every other CLI in this repo:
|
|
11
11
|
*
|
|
12
|
-
* 1. It is a PREVIEW release (`0.2.1-rc.
|
|
12
|
+
* 1. It is a PREVIEW release (`0.2.1-rc.5`) and upstream says compatibility may
|
|
13
13
|
* break between previews, so the gate is exact equality — not a floor. The
|
|
14
14
|
* two version comparators already in this repo (installer.js's
|
|
15
15
|
* `compareVersions`, pi-stream.js's `parseVersion`) both DROP the `-rc.N`
|
|
@@ -45,7 +45,7 @@ const path = require('path');
|
|
|
45
45
|
* from there and only falls back here when the registry entry cannot be read at
|
|
46
46
|
* all. Mirrors pi-stream.js's MIN_PI_VERSION rationale.
|
|
47
47
|
*/
|
|
48
|
-
const SUPPORTED_DSH_VERSION = '0.2.1-rc.
|
|
48
|
+
const SUPPORTED_DSH_VERSION = '0.2.1-rc.5';
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* dsh's Node requirement, from the upstream repository's root package.json:
|
|
@@ -66,11 +66,20 @@ const NODE_MIN_22 = [22, 19, 0];
|
|
|
66
66
|
const ROW = {
|
|
67
67
|
AGENT_DEFAULT_MODEL: 'agent-default-model',
|
|
68
68
|
APPROVAL: 'approval',
|
|
69
|
+
LLM_DEEPSEEK: 'llm-deepseek',
|
|
69
70
|
LLM_PI_AI: 'llm-pi-ai',
|
|
70
71
|
PERMISSION: 'permission',
|
|
71
72
|
USER_QUESTIONS: 'user-questions',
|
|
72
73
|
};
|
|
73
74
|
|
|
75
|
+
/**
|
|
76
|
+
* The models dsh's own DeepSeek catalog ships (`DEFAULT_MODELS` in
|
|
77
|
+
* @deepseek-ai/dsh-llm-deepseek). From rc.5, while that catalog is untouched,
|
|
78
|
+
* dsh follows the official `/models` listing and refuses any listed model not
|
|
79
|
+
* in it — `deepseek-v4-flash`, the id OpenAgents offers, among them.
|
|
80
|
+
*/
|
|
81
|
+
const DSH_BUILTIN_MODELS = ['deepseek-flash', 'deepseek-v4-pro'];
|
|
82
|
+
|
|
74
83
|
/** The pi-ai route an OpenAI-compatible gateway is served through. */
|
|
75
84
|
const GATEWAY_PROVIDER = 'openai-gateway';
|
|
76
85
|
|
|
@@ -397,7 +406,7 @@ function yamlScalar(value) {
|
|
|
397
406
|
* A patch REPLACES the targeted row's whole `config`, so each row below is
|
|
398
407
|
* written out complete rather than as a partial merge.
|
|
399
408
|
*/
|
|
400
|
-
function buildPrivatePatch({ model, provider, permissionMode, gatewayBaseUrl } = {}) {
|
|
409
|
+
function buildPrivatePatch({ model, provider, permissionMode, gatewayBaseUrl, officialEndpoint = false } = {}) {
|
|
401
410
|
const mode = normalizePermissionMode(permissionMode) || 'workspace-write';
|
|
402
411
|
const sandboxFor = (m) => (m === 'read-only' ? 'read-only' : m === 'danger-full-access' ? 'danger-full-access' : 'workspace-write');
|
|
403
412
|
|
|
@@ -446,6 +455,17 @@ function buildPrivatePatch({ model, provider, permissionMode, gatewayBaseUrl } =
|
|
|
446
455
|
lines.push(` provider: ${GATEWAY_PROVIDER}`);
|
|
447
456
|
lines.push(` model: ${yamlScalar(gatewayModel)}`);
|
|
448
457
|
} else if (model || provider) {
|
|
458
|
+
if (officialEndpoint && model && !DSH_BUILTIN_MODELS.includes(model)) {
|
|
459
|
+
// Declaring the model in the route's catalog is what keeps rc.5 from
|
|
460
|
+
// following the `/models` listing and refusing it before any request
|
|
461
|
+
// ("is not supported by DeepSeek Harness"). The API itself still decides
|
|
462
|
+
// whether the model exists, and says so in an error the user can act on.
|
|
463
|
+
lines.push('');
|
|
464
|
+
lines.push(`- id: ${ROW.LLM_DEEPSEEK}`);
|
|
465
|
+
lines.push(' config:');
|
|
466
|
+
lines.push(' models:');
|
|
467
|
+
lines.push(` - id: ${yamlScalar(model)}`);
|
|
468
|
+
}
|
|
449
469
|
lines.push('');
|
|
450
470
|
lines.push(`- id: ${ROW.AGENT_DEFAULT_MODEL}`);
|
|
451
471
|
lines.push(' config:');
|
|
@@ -604,7 +624,12 @@ const FAILURE = {
|
|
|
604
624
|
|
|
605
625
|
const FAILURE_PATTERNS = [
|
|
606
626
|
[FAILURE.AUTH, /\b(401|403|unauthor|forbidden|invalid[_\s-]?api[_\s-]?key|authentication|no api key|missing api key|credential)/i],
|
|
607
|
-
|
|
627
|
+
// dsh 0.2.1-rc.5 refuses a model the official `/models` listing names but its
|
|
628
|
+
// own catalog does not ship ("… is not supported by DeepSeek Harness",
|
|
629
|
+
// MODEL_UNSUPPORTED), and one that needs a newer harness
|
|
630
|
+
// (CLIENT_UPGRADE_REQUIRED) — both before any request is sent.
|
|
631
|
+
[FAILURE.VERSION, /\b(requires DeepSeek Harness \S+ or later|client[_\s-]?upgrade[_\s-]?required)/i],
|
|
632
|
+
[FAILURE.MODEL, /\b(model[_\s-]?not[_\s-]?found|unknown model|unsupported model|model[_\s-]?unsupported|not supported by DeepSeek Harness|no such model|context[_\s-]?length|token limit|quota|rate[_\s-]?limit|429)/i],
|
|
608
633
|
[FAILURE.NETWORK, /\b(econnrefused|enotfound|etimedout|econnreset|socket hang up|network|dns|proxy|certificate|tls|ssl|502|503|504)/i],
|
|
609
634
|
[FAILURE.PERMISSION, /\b(eacces|eperm|erofs|permission denied|read[_\s-]?only file system|operation not permitted)/i],
|
|
610
635
|
[FAILURE.VERSION, /\b(unsupported node|engine|requires node|syntaxerror.*unexpected token|err_require_esm|cannot use import statement)/i],
|
|
@@ -682,6 +707,7 @@ function selectSessionsForGc(entries, { now, keepCount = SESSION_KEEP_COUNT, kee
|
|
|
682
707
|
|
|
683
708
|
module.exports = {
|
|
684
709
|
SUPPORTED_DSH_VERSION,
|
|
710
|
+
DSH_BUILTIN_MODELS,
|
|
685
711
|
NODE_MIN_22,
|
|
686
712
|
ROW,
|
|
687
713
|
PERMISSION_MODES,
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Workspace API client for DeepSeek Harness runs on Windows.
|
|
4
|
+
*
|
|
5
|
+
* dsh's Windows sandbox (`workspace-write`, the default) runs shell commands
|
|
6
|
+
* under a restricted token that has no Schannel credentials, so `curl.exe` and
|
|
7
|
+
* `Invoke-WebRequest` both fail every HTTPS request with SEC_E_NO_CREDENTIALS
|
|
8
|
+
* — on dsh 0.2.1-rc.2 and rc.5 alike. Node's own TLS stack is unaffected, so the
|
|
9
|
+
* task file points the agent at this script instead of the curl recipes every
|
|
10
|
+
* other adapter uses.
|
|
11
|
+
*
|
|
12
|
+
* Standalone on purpose: it runs inside the sandbox as `node <this file>`, so it
|
|
13
|
+
* requires nothing but Node built-ins. The token, endpoint, workspace and agent
|
|
14
|
+
* name come from the child environment (see DeepSeekAdapter._buildSubprocessEnv);
|
|
15
|
+
* none of them is ever passed on the command line.
|
|
16
|
+
*
|
|
17
|
+
* node deepseek-workspace-api.js GET "/v1/files?network=<id>"
|
|
18
|
+
* '<json>' | node deepseek-workspace-api.js POST /v1/events
|
|
19
|
+
* node deepseek-workspace-api.js POST /v1/events --body-file body.json
|
|
20
|
+
* node deepseek-workspace-api.js upload <file> --channel <name> [--type <mime>]
|
|
21
|
+
* node deepseek-workspace-api.js download <file-id> <out-path>
|
|
22
|
+
*
|
|
23
|
+
* The body of POST/PUT/PATCH is read from --body-file or stdin. Piping a
|
|
24
|
+
* single-quoted PowerShell string keeps its double quotes intact, which passing
|
|
25
|
+
* JSON as an argument to a native program on Windows PowerShell 5.1 does not.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
'use strict';
|
|
29
|
+
|
|
30
|
+
const fs = require('fs');
|
|
31
|
+
const path = require('path');
|
|
32
|
+
|
|
33
|
+
const ENV = {
|
|
34
|
+
token: 'OPENAGENTS_WORKSPACE_AUTH',
|
|
35
|
+
endpoint: 'OPENAGENTS_WORKSPACE_ENDPOINT',
|
|
36
|
+
workspace: 'OPENAGENTS_WORKSPACE_ID',
|
|
37
|
+
agent: 'OPENAGENTS_AGENT_NAME',
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const MIME = {
|
|
41
|
+
'.md': 'text/markdown', '.txt': 'text/plain', '.html': 'text/html', '.htm': 'text/html',
|
|
42
|
+
'.json': 'application/json', '.csv': 'text/csv', '.pdf': 'application/pdf',
|
|
43
|
+
'.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif',
|
|
44
|
+
'.svg': 'image/svg+xml', '.webp': 'image/webp', '.zip': 'application/zip',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function fail(message) {
|
|
48
|
+
process.stderr.write(`workspace-api: ${message}\n`);
|
|
49
|
+
process.exit(2);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function takeFlag(args, name) {
|
|
53
|
+
const i = args.indexOf(name);
|
|
54
|
+
if (i === -1) return undefined;
|
|
55
|
+
const value = args[i + 1];
|
|
56
|
+
if (value === undefined) fail(`${name} needs a value`);
|
|
57
|
+
args.splice(i, 2);
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function readStdin() {
|
|
62
|
+
if (process.stdin.isTTY) return Promise.resolve('');
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
const chunks = [];
|
|
65
|
+
process.stdin.on('data', (c) => chunks.push(c));
|
|
66
|
+
process.stdin.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')));
|
|
67
|
+
process.stdin.on('error', reject);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function call(method, route, body) {
|
|
72
|
+
const endpoint = (process.env[ENV.endpoint] || '').replace(/\/+$/, '');
|
|
73
|
+
const token = process.env[ENV.token];
|
|
74
|
+
if (!endpoint) fail(`${ENV.endpoint} is not set`);
|
|
75
|
+
if (!token) fail(`${ENV.token} is not set`);
|
|
76
|
+
if (!route.startsWith('/')) fail(`the path must start with "/" (got ${route})`);
|
|
77
|
+
|
|
78
|
+
const headers = { 'X-Workspace-Token': token };
|
|
79
|
+
if (body !== undefined) headers['Content-Type'] = 'application/json';
|
|
80
|
+
const res = await fetch(endpoint + route, { method, headers, body });
|
|
81
|
+
return res;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function printResponse(res) {
|
|
85
|
+
const text = await res.text();
|
|
86
|
+
process.stdout.write(text.endsWith('\n') ? text : text + '\n');
|
|
87
|
+
if (!res.ok) {
|
|
88
|
+
process.stderr.write(`workspace-api: HTTP ${res.status}\n`);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function upload(args) {
|
|
94
|
+
const channel = takeFlag(args, '--channel');
|
|
95
|
+
const type = takeFlag(args, '--type');
|
|
96
|
+
const file = args[0];
|
|
97
|
+
if (!file) fail('usage: upload <file> --channel <name> [--type <mime>]');
|
|
98
|
+
if (!channel) fail('upload needs --channel <name>');
|
|
99
|
+
const workspace = process.env[ENV.workspace];
|
|
100
|
+
if (!workspace) fail(`${ENV.workspace} is not set`);
|
|
101
|
+
|
|
102
|
+
let data;
|
|
103
|
+
try { data = fs.readFileSync(file); } catch (e) { fail(`cannot read ${file}: ${e.message}`); }
|
|
104
|
+
const agent = process.env[ENV.agent];
|
|
105
|
+
const body = JSON.stringify({
|
|
106
|
+
filename: path.basename(file),
|
|
107
|
+
content_base64: data.toString('base64'),
|
|
108
|
+
content_type: type || MIME[path.extname(file).toLowerCase()] || 'application/octet-stream',
|
|
109
|
+
network: workspace,
|
|
110
|
+
channel_name: channel,
|
|
111
|
+
...(agent ? { source: `openagents:${agent}` } : {}),
|
|
112
|
+
});
|
|
113
|
+
await printResponse(await call('POST', '/v1/files/base64', body));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function download(args) {
|
|
117
|
+
const [id, out] = args;
|
|
118
|
+
if (!id || !out) fail('usage: download <file-id> <out-path>');
|
|
119
|
+
const workspace = process.env[ENV.workspace] || '';
|
|
120
|
+
const res = await call('GET', `/v1/files/${encodeURIComponent(id)}?network=${encodeURIComponent(workspace)}`);
|
|
121
|
+
if (!res.ok) return printResponse(res);
|
|
122
|
+
fs.writeFileSync(out, Buffer.from(await res.arrayBuffer()));
|
|
123
|
+
process.stdout.write(`saved ${out}\n`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function main() {
|
|
127
|
+
const args = process.argv.slice(2);
|
|
128
|
+
const verb = (args.shift() || '').toLowerCase();
|
|
129
|
+
if (verb === 'upload') return upload(args);
|
|
130
|
+
if (verb === 'download') return download(args);
|
|
131
|
+
|
|
132
|
+
const method = verb.toUpperCase();
|
|
133
|
+
if (!['GET', 'POST', 'PUT', 'PATCH', 'DELETE'].includes(method)) {
|
|
134
|
+
fail('usage: <GET|POST|PUT|PATCH|DELETE> <path> | upload <file> --channel <name> | download <file-id> <out-path>');
|
|
135
|
+
}
|
|
136
|
+
const bodyFile = takeFlag(args, '--body-file');
|
|
137
|
+
const route = args[0];
|
|
138
|
+
if (!route) fail(`usage: ${method} <path>`);
|
|
139
|
+
|
|
140
|
+
let body;
|
|
141
|
+
if (method !== 'GET' && method !== 'DELETE') {
|
|
142
|
+
body = bodyFile ? fs.readFileSync(bodyFile, 'utf-8') : (await readStdin());
|
|
143
|
+
body = body.replace(/^/, '').trim();
|
|
144
|
+
if (!body) fail(`${method} needs a JSON body on stdin or --body-file`);
|
|
145
|
+
try { JSON.parse(body); } catch (e) { fail(`the body is not valid JSON: ${e.message}`); }
|
|
146
|
+
}
|
|
147
|
+
await printResponse(await call(method, route, body));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
main().catch((e) => fail(e && e.message ? e.message : String(e)));
|
package/src/adapters/deepseek.js
CHANGED
|
@@ -121,8 +121,25 @@ const BOOTSTRAP_KEY = '\u0000bootstrap';
|
|
|
121
121
|
const RECAP_HEAD = 30;
|
|
122
122
|
const RECAP_TAIL = 60;
|
|
123
123
|
|
|
124
|
-
/**
|
|
125
|
-
|
|
124
|
+
/**
|
|
125
|
+
* The environment variable the task file tells the agent to read.
|
|
126
|
+
*
|
|
127
|
+
* Deliberately NOT `OPENAGENTS_WORKSPACE_TOKEN`: dsh strips every variable whose
|
|
128
|
+
* name matches /KEY|PASSWORD|SECRET|TOKEN/i from the commands it runs
|
|
129
|
+
* (`SENSITIVE_ENV_PATTERN` in @deepseek-ai/dsh-subprocess, rc.2 and rc.5 alike),
|
|
130
|
+
* and has no setting to let one through. Under that name the agent's shell never
|
|
131
|
+
* saw the token, so agents went looking for it — one read it out of daemon.yaml
|
|
132
|
+
* and wrote it into its reasoning, which sent it to the model provider and into
|
|
133
|
+
* dsh's session log. This token is meant for the agent's shell; the scrub
|
|
134
|
+
* exists for the harness's own credentials (DEEPSEEK_API_KEY stays scrubbed).
|
|
135
|
+
*/
|
|
136
|
+
const TOKEN_ENV = 'OPENAGENTS_WORKSPACE_AUTH';
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The workspace API client Windows runs use instead of curl, which dsh's
|
|
140
|
+
* Windows sandbox leaves without TLS credentials. See deepseek-workspace-api.js.
|
|
141
|
+
*/
|
|
142
|
+
const WORKSPACE_API_HELPER = path.join(__dirname, 'deepseek-workspace-api.js');
|
|
126
143
|
|
|
127
144
|
/**
|
|
128
145
|
* The notice for a stop that could NOT be confirmed (BaseAdapter posts it when
|
|
@@ -563,7 +580,11 @@ class DeepSeekAdapter extends BaseAdapter {
|
|
|
563
580
|
* starts mid-write can never read a half-file.
|
|
564
581
|
*/
|
|
565
582
|
_writePrivatePatch() {
|
|
566
|
-
const { text } = buildPrivatePatch({
|
|
583
|
+
const { text } = buildPrivatePatch({
|
|
584
|
+
model: this._model(),
|
|
585
|
+
gatewayBaseUrl: this._gatewayBaseUrl(),
|
|
586
|
+
officialEndpoint: !this._baseUrl(),
|
|
587
|
+
});
|
|
567
588
|
const tmp = `${this._patchFile}.${process.pid}.tmp`;
|
|
568
589
|
fs.writeFileSync(tmp, text, { encoding: 'utf-8', mode: 0o600 });
|
|
569
590
|
fs.renameSync(tmp, this._patchFile);
|
|
@@ -603,6 +624,11 @@ class DeepSeekAdapter extends BaseAdapter {
|
|
|
603
624
|
|
|
604
625
|
// The task file references this by NAME; the value never appears in it.
|
|
605
626
|
env[TOKEN_ENV] = this.token;
|
|
627
|
+
// Read by deepseek-workspace-api.js, so a Windows run's commands carry no
|
|
628
|
+
// endpoint, workspace or identity of their own to get wrong.
|
|
629
|
+
env.OPENAGENTS_WORKSPACE_ENDPOINT = this.endpoint;
|
|
630
|
+
env.OPENAGENTS_WORKSPACE_ID = this.workspaceId;
|
|
631
|
+
env.OPENAGENTS_AGENT_NAME = this.agentName;
|
|
606
632
|
return env;
|
|
607
633
|
}
|
|
608
634
|
|
|
@@ -955,6 +981,7 @@ class DeepSeekAdapter extends BaseAdapter {
|
|
|
955
981
|
recap,
|
|
956
982
|
request: content,
|
|
957
983
|
attachments: attachmentText,
|
|
984
|
+
windowsApi: IS_WINDOWS ? { node: this._nodeBin, helper: WORKSPACE_API_HELPER } : null,
|
|
958
985
|
});
|
|
959
986
|
|
|
960
987
|
this._taskCounter += 1;
|
|
@@ -384,6 +384,67 @@ function classifyKimiError(info) {
|
|
|
384
384
|
return { kind: 'error', userMessage: `Kimi Code CLI ${why}.` };
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
+
// ---------------------------------------------------------------------------
|
|
388
|
+
// Workspace tools (MCP) through a private Kimi home
|
|
389
|
+
// ---------------------------------------------------------------------------
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Kimi Code has no flag for an MCP config and ignores a project-level
|
|
393
|
+
* `.kimi-code/mcp.json`; it reads MCP servers from `$KIMI_CODE_HOME/mcp.json`
|
|
394
|
+
* (2.4.1). Each agent therefore runs with its own Kimi home under
|
|
395
|
+
* ~/.openagents, so the workspace server can be added without editing the
|
|
396
|
+
* user's ~/.kimi-code. Kimi passes its whole environment to stdio MCP
|
|
397
|
+
* servers, so the file names only the command: the token, workspace and
|
|
398
|
+
* channel of each run travel in the environment (see buildKimiWorkspaceEnv).
|
|
399
|
+
*/
|
|
400
|
+
const KIMI_MCP_SERVER_NAME = 'openagents-workspace';
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Entries of the user's Kimi home a private home links back to: the
|
|
404
|
+
* `kimi login` credentials (a directory, so token refreshes land in the
|
|
405
|
+
* user's home) and config.toml (providers and default model for the
|
|
406
|
+
* no-API-key route).
|
|
407
|
+
*/
|
|
408
|
+
const KIMI_HOME_LINKS = [
|
|
409
|
+
{ name: 'credentials', dir: true },
|
|
410
|
+
{ name: 'config.toml', dir: false },
|
|
411
|
+
];
|
|
412
|
+
|
|
413
|
+
/** Directory name of an agent's private Kimi home: readable, unique per workspace+agent. */
|
|
414
|
+
function kimiHomeName(workspaceId, agentName) {
|
|
415
|
+
const raw = `${workspaceId == null ? '' : workspaceId}\u0000${agentName == null ? '' : agentName}`;
|
|
416
|
+
const hash = crypto.createHash('sha256').update(raw).digest('hex').slice(0, 8);
|
|
417
|
+
const slug = (v) => String(v == null ? '' : v).toLowerCase()
|
|
418
|
+
.replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 32) || 'agent';
|
|
419
|
+
return `${slug(workspaceId)}_${slug(agentName)}-${hash}`;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* The private home's mcp.json: the user's own MCP servers (so a private home
|
|
424
|
+
* loses nothing the user configured) plus the workspace server, which always
|
|
425
|
+
* wins its name. An unreadable user file contributes nothing.
|
|
426
|
+
*/
|
|
427
|
+
function buildKimiMcpConfig(userConfig, server) {
|
|
428
|
+
const base = userConfig && typeof userConfig === 'object' && !Array.isArray(userConfig) ? userConfig : {};
|
|
429
|
+
const servers = base.mcpServers && typeof base.mcpServers === 'object' && !Array.isArray(base.mcpServers)
|
|
430
|
+
? { ...base.mcpServers }
|
|
431
|
+
: {};
|
|
432
|
+
servers[KIMI_MCP_SERVER_NAME] = server;
|
|
433
|
+
return { ...base, mcpServers: servers };
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** What the workspace MCP server reads from its environment (cli.js `mcp-server`). */
|
|
437
|
+
function buildKimiWorkspaceEnv({ token, workspaceId, channel, agentName, endpoint }) {
|
|
438
|
+
const env = {
|
|
439
|
+
OPENAGENTS_WORKSPACE_ID: String(workspaceId || ''),
|
|
440
|
+
OPENAGENTS_CHANNEL_NAME: String(channel || 'general'),
|
|
441
|
+
OPENAGENTS_AGENT_NAME: String(agentName || 'agent'),
|
|
442
|
+
};
|
|
443
|
+
if (endpoint) env.OPENAGENTS_ENDPOINT = String(endpoint);
|
|
444
|
+
if (token) env.OA_WORKSPACE_TOKEN = String(token);
|
|
445
|
+
return env;
|
|
446
|
+
}
|
|
447
|
+
|
|
387
448
|
module.exports = {
|
|
388
449
|
parseKimiVersion,
|
|
389
450
|
classifyKimiVersion,
|
|
@@ -402,4 +463,9 @@ module.exports = {
|
|
|
402
463
|
DEFAULT_MAX_COMPLETION_TOKENS,
|
|
403
464
|
EXIT_PERMANENT,
|
|
404
465
|
EXIT_TRANSIENT,
|
|
466
|
+
KIMI_MCP_SERVER_NAME,
|
|
467
|
+
KIMI_HOME_LINKS,
|
|
468
|
+
kimiHomeName,
|
|
469
|
+
buildKimiMcpConfig,
|
|
470
|
+
buildKimiWorkspaceEnv,
|
|
405
471
|
};
|
package/src/adapters/kimi.js
CHANGED
|
@@ -19,7 +19,17 @@
|
|
|
19
19
|
* OpenAI-compatible chat completions against KIMI_BASE_URL (inherited from
|
|
20
20
|
* LlmDirectAdapter).
|
|
21
21
|
*
|
|
22
|
-
*
|
|
22
|
+
* - workspace tools: the CLI reads MCP servers only from
|
|
23
|
+
* `$KIMI_CODE_HOME/mcp.json`, so each agent runs with a private Kimi home
|
|
24
|
+
* (~/.openagents/kimi-homes/<agent>/) that adds the workspace MCP server to
|
|
25
|
+
* the user's own servers and links their `kimi login` credentials and
|
|
26
|
+
* config.toml back in. The token, workspace and channel reach the MCP
|
|
27
|
+
* server through the environment, never through a file.
|
|
28
|
+
* - no sandbox: print mode approves every tool call and the CLI has no
|
|
29
|
+
* filesystem boundary, so the agent can write outside its working
|
|
30
|
+
* directory. That is the CLI's own model, not something this adapter adds.
|
|
31
|
+
*
|
|
32
|
+
* Verified against Kimi Code CLI v0.39.1 and 2.4.1. NOTE: the legacy Python `kimi-cli`
|
|
23
33
|
* (PyPI) also installs a `kimi` binary but reports 1.x versions and has a
|
|
24
34
|
* different interface — it is detected and NOT driven.
|
|
25
35
|
*/
|
|
@@ -49,6 +59,11 @@ const {
|
|
|
49
59
|
classifyKimiVersion,
|
|
50
60
|
classifyKimiError,
|
|
51
61
|
encodeKimiWorkDirKey,
|
|
62
|
+
KIMI_MCP_SERVER_NAME,
|
|
63
|
+
KIMI_HOME_LINKS,
|
|
64
|
+
kimiHomeName,
|
|
65
|
+
buildKimiMcpConfig,
|
|
66
|
+
buildKimiWorkspaceEnv,
|
|
52
67
|
} = require('./kimi-stream');
|
|
53
68
|
|
|
54
69
|
const IS_WINDOWS = process.platform === 'win32';
|
|
@@ -255,10 +270,14 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
255
270
|
if (!proc || proc.exitCode !== null) return;
|
|
256
271
|
try {
|
|
257
272
|
if (IS_WINDOWS) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
273
|
+
// Tree first. On Windows proc.kill() is TerminateProcess whatever the
|
|
274
|
+
// signal, so "SIGINT, then taskkill /T if it is still alive" never
|
|
275
|
+
// reached taskkill — and once kimi is dead its shell commands can no
|
|
276
|
+
// longer be found through it: a Stop left them running.
|
|
277
|
+
try { execSync(`taskkill /F /T /PID ${proc.pid}`, { timeout: 5000, windowsHide: true }); } catch {}
|
|
278
|
+
if (!(await this._waitExit(proc, 1500))) {
|
|
279
|
+
try { proc.kill(); } catch {}
|
|
280
|
+
await this._waitExit(proc, 1000);
|
|
262
281
|
}
|
|
263
282
|
} else {
|
|
264
283
|
try { process.kill(-proc.pid, 'SIGINT'); } catch { try { proc.kill('SIGINT'); } catch {} }
|
|
@@ -456,6 +475,13 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
456
475
|
if (this._mode === 'plan') {
|
|
457
476
|
lines.push('You are in PLAN mode: investigate and propose a plan; do not modify files.');
|
|
458
477
|
}
|
|
478
|
+
if (this._workspaceToolsReady) {
|
|
479
|
+
lines.push(
|
|
480
|
+
`For anything in the OpenAgents workspace — chat history, files, uploads, knowledge, todos — use the ` +
|
|
481
|
+
`\`workspace_*\` tools (MCP server "${KIMI_MCP_SERVER_NAME}"). They are already signed in: never look for, ` +
|
|
482
|
+
'print or use a workspace token, and do not call the workspace HTTP API yourself.',
|
|
483
|
+
);
|
|
484
|
+
}
|
|
459
485
|
lines.push('Work in the current working directory. Reply concisely. The user request follows:');
|
|
460
486
|
return lines.join('\n');
|
|
461
487
|
}
|
|
@@ -584,6 +610,9 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
584
610
|
|
|
585
611
|
// Resuming → Kimi already has history, send the bare turn. Fresh →
|
|
586
612
|
// prepend a context header (+ recap when available).
|
|
613
|
+
// Decided before the prompt is built: the header only promises the
|
|
614
|
+
// workspace tools when this run will actually have them.
|
|
615
|
+
this._workspaceToolsReady = !!this._prepareKimiHome();
|
|
587
616
|
let prompt;
|
|
588
617
|
if (resumeId) {
|
|
589
618
|
prompt = content;
|
|
@@ -633,6 +662,92 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
633
662
|
}
|
|
634
663
|
}
|
|
635
664
|
|
|
665
|
+
// ------------------------------------------------------------------
|
|
666
|
+
// Private Kimi home (workspace MCP tools)
|
|
667
|
+
// ------------------------------------------------------------------
|
|
668
|
+
|
|
669
|
+
/** This agent's own Kimi home. See KIMI_MCP_SERVER_NAME in kimi-stream.js. */
|
|
670
|
+
_kimiHome() {
|
|
671
|
+
return path.join(os.homedir(), '.openagents', 'kimi-homes', kimiHomeName(this.workspaceId, this.agentName));
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/** The user's own Kimi home, which the private one links back to. */
|
|
675
|
+
_userKimiHome() {
|
|
676
|
+
const env = this.agentEnv || {};
|
|
677
|
+
return env.KIMI_CODE_HOME || process.env.KIMI_CODE_HOME || path.join(os.homedir(), '.kimi-code');
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* (Re)build the private home for one run and return its path, or null when
|
|
682
|
+
* it cannot be prepared — the run then goes ahead without workspace tools,
|
|
683
|
+
* exactly as before.
|
|
684
|
+
*
|
|
685
|
+
* Every run re-checks the links, so a `kimi login` done after the agent
|
|
686
|
+
* started is picked up, and rewrites mcp.json, so a change to the user's own
|
|
687
|
+
* MCP servers or to the agent's disabled modules applies at once.
|
|
688
|
+
*/
|
|
689
|
+
_prepareKimiHome() {
|
|
690
|
+
const home = this._kimiHome();
|
|
691
|
+
try {
|
|
692
|
+
fs.mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
693
|
+
const userHome = this._userKimiHome();
|
|
694
|
+
for (const { name, dir } of KIMI_HOME_LINKS) this._linkIntoKimiHome(path.join(userHome, name), path.join(home, name), dir);
|
|
695
|
+
|
|
696
|
+
const command = this._mcpServerCommand();
|
|
697
|
+
if (!command) {
|
|
698
|
+
this._log('Could not locate the OpenAgents CLI — workspace tools are unavailable this run');
|
|
699
|
+
return null;
|
|
700
|
+
}
|
|
701
|
+
let userConfig = null;
|
|
702
|
+
try { userConfig = JSON.parse(fs.readFileSync(path.join(userHome, 'mcp.json'), 'utf-8')); } catch {}
|
|
703
|
+
const config = buildKimiMcpConfig(userConfig, command);
|
|
704
|
+
const file = path.join(home, 'mcp.json');
|
|
705
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
706
|
+
fs.writeFileSync(tmp, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
707
|
+
fs.renameSync(tmp, file);
|
|
708
|
+
return home;
|
|
709
|
+
} catch (e) {
|
|
710
|
+
this._log(`Could not prepare the private Kimi home (${redactSecrets(e && e.message)}) — workspace tools are unavailable this run`);
|
|
711
|
+
return null;
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
/**
|
|
716
|
+
* Point `dest` at `target` in the user's home. A directory is linked
|
|
717
|
+
* (a junction on Windows, which needs no privilege), so writes such as a
|
|
718
|
+
* credentials refresh land in the user's home. A file is symlinked on POSIX
|
|
719
|
+
* and copied on Windows, where file symlinks need Developer Mode. Anything
|
|
720
|
+
* already at `dest` that is not ours to replace is left alone.
|
|
721
|
+
*/
|
|
722
|
+
_linkIntoKimiHome(target, dest, isDir) {
|
|
723
|
+
if (!fs.existsSync(target)) return;
|
|
724
|
+
let st = null;
|
|
725
|
+
try { st = fs.lstatSync(dest); } catch {}
|
|
726
|
+
if (st && st.isSymbolicLink()) {
|
|
727
|
+
let current = null;
|
|
728
|
+
try { current = fs.readlinkSync(dest); } catch {}
|
|
729
|
+
if (current && path.resolve(path.dirname(dest), current) === path.resolve(target)) return;
|
|
730
|
+
fs.rmSync(dest, { force: true });
|
|
731
|
+
} else if (st && !(IS_WINDOWS && !isDir && st.isFile())) {
|
|
732
|
+
return;
|
|
733
|
+
}
|
|
734
|
+
if (isDir) fs.symlinkSync(target, dest, IS_WINDOWS ? 'junction' : 'dir');
|
|
735
|
+
else if (IS_WINDOWS) fs.copyFileSync(target, dest);
|
|
736
|
+
else fs.symlinkSync(target, dest, 'file');
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/** The stdio command that runs this package's workspace MCP server. */
|
|
740
|
+
_mcpServerCommand() {
|
|
741
|
+
const bin = path.resolve(__dirname, '..', '..', 'bin', 'agent-connector.js');
|
|
742
|
+
if (!fs.existsSync(bin)) return null;
|
|
743
|
+
const args = [bin, 'mcp-server'];
|
|
744
|
+
const disabled = this.disabledModules || new Set();
|
|
745
|
+
if (disabled.has('files')) args.push('--disable-files');
|
|
746
|
+
if (disabled.has('browser')) args.push('--disable-browser');
|
|
747
|
+
if (disabled.has('knowledge')) args.push('--disable-knowledge');
|
|
748
|
+
return { command: process.execPath, args };
|
|
749
|
+
}
|
|
750
|
+
|
|
636
751
|
_dirExists(p) {
|
|
637
752
|
try { return fs.statSync(p).isDirectory(); } catch { return false; }
|
|
638
753
|
}
|
|
@@ -683,6 +798,17 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
683
798
|
// Stopped while this turn was being prepared: start nothing (no tokens).
|
|
684
799
|
if (this._stoppedBeforeStart(channel)) return Promise.resolve({ userStopped: true });
|
|
685
800
|
const { env: cleanEnv } = buildKimiEnv(this.agentEnv || process.env);
|
|
801
|
+
const kimiHome = this._prepareKimiHome();
|
|
802
|
+
if (kimiHome) {
|
|
803
|
+
cleanEnv.KIMI_CODE_HOME = kimiHome;
|
|
804
|
+
Object.assign(cleanEnv, buildKimiWorkspaceEnv({
|
|
805
|
+
token: this.token,
|
|
806
|
+
workspaceId: this.workspaceId,
|
|
807
|
+
channel,
|
|
808
|
+
agentName: this.agentName,
|
|
809
|
+
endpoint: this.endpoint,
|
|
810
|
+
}));
|
|
811
|
+
}
|
|
686
812
|
const [cmd, ...spawnArgs] = this._spawnableCmd(kimiBin, args);
|
|
687
813
|
// Before the spawn, so the session this run creates shows up as new.
|
|
688
814
|
const sessionWatch = this._watchKimiSessions(cleanEnv, workingDir, args);
|
|
@@ -702,6 +828,7 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
702
828
|
const state = {
|
|
703
829
|
ok: false,
|
|
704
830
|
finalText: '',
|
|
831
|
+
pendingThought: '',
|
|
705
832
|
sessionId: null,
|
|
706
833
|
anyOutput: false,
|
|
707
834
|
userStopped: false,
|
|
@@ -743,12 +870,21 @@ class KimiAdapter extends LlmDirectAdapter {
|
|
|
743
870
|
for (const e of interpretKimiMessage(m)) {
|
|
744
871
|
switch (e.kind) {
|
|
745
872
|
case 'text':
|
|
873
|
+
// Held back until the turn moves on: the LAST text is the reply,
|
|
874
|
+
// posted once as the response rather than also as a thought.
|
|
746
875
|
state.anyOutput = true;
|
|
876
|
+
if (state.pendingThought) {
|
|
877
|
+
try { await this.sendThinking(channel, state.pendingThought); } catch {}
|
|
878
|
+
}
|
|
879
|
+
state.pendingThought = e.text;
|
|
747
880
|
state.finalText = e.text;
|
|
748
|
-
try { await this.sendThinking(channel, e.text); } catch {}
|
|
749
881
|
break;
|
|
750
882
|
case 'tool_start':
|
|
751
883
|
state.anyOutput = true;
|
|
884
|
+
if (state.pendingThought) {
|
|
885
|
+
try { await this.sendThinking(channel, state.pendingThought); } catch {}
|
|
886
|
+
state.pendingThought = '';
|
|
887
|
+
}
|
|
752
888
|
try {
|
|
753
889
|
await this.sendStatus(channel, e.preview ? `${e.name}: ${e.preview}` : e.name);
|
|
754
890
|
} catch {}
|
|
@@ -1041,7 +1041,7 @@ function buildOpenWorkerSystemPrompt({ agentName, workspaceId, channelName, endp
|
|
|
1041
1041
|
* constant sentence on the command line. Two consequences shape this function:
|
|
1042
1042
|
*
|
|
1043
1043
|
* - The workspace token must NEVER appear. `tokenExpr` is a SHELL EXPRESSION
|
|
1044
|
-
* (`$
|
|
1044
|
+
* (`$OPENAGENTS_WORKSPACE_AUTH`, or `$env:OPENAGENTS_WORKSPACE_AUTH` on
|
|
1045
1045
|
* Windows) that the agent expands at run time from the child environment.
|
|
1046
1046
|
* Passing the real token here would put it on disk for no benefit — and the
|
|
1047
1047
|
* guard below makes that a loud failure rather than a silent leak.
|
|
@@ -1050,17 +1050,52 @@ function buildOpenWorkerSystemPrompt({ agentName, workspaceId, channelName, endp
|
|
|
1050
1050
|
* is therefore part of the task itself rather than something the agent can
|
|
1051
1051
|
* be expected to remember.
|
|
1052
1052
|
*/
|
|
1053
|
+
/** Quote a path as a PowerShell single-quoted literal. */
|
|
1054
|
+
function psQuote(value) {
|
|
1055
|
+
return `'${String(value).replace(/'/g, "''")}'`;
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
/**
|
|
1059
|
+
* How a DeepSeek Harness run on Windows reaches the workspace API.
|
|
1060
|
+
*
|
|
1061
|
+
* dsh's Windows sandbox gives shell commands a token with no Schannel
|
|
1062
|
+
* credentials, so the `curl` recipes above fail every HTTPS request
|
|
1063
|
+
* (SEC_E_NO_CREDENTIALS) and so does Invoke-WebRequest. Node's TLS works, so the
|
|
1064
|
+
* calls go through deepseek-workspace-api.js on the adapter's own Node binary.
|
|
1065
|
+
* The recipes above stay as the reference for routes and JSON bodies.
|
|
1066
|
+
*/
|
|
1067
|
+
function buildDeepSeekWindowsApiSection({ node, helper, channelName }) {
|
|
1068
|
+
const run = `& ${psQuote(node)} ${psQuote(helper)}`;
|
|
1069
|
+
return [
|
|
1070
|
+
'## Calling the workspace API on this machine (Windows)',
|
|
1071
|
+
'This sandbox cannot open HTTPS connections with `curl.exe` or `Invoke-WebRequest` '
|
|
1072
|
+
+ '(they fail with SEC_E_NO_CREDENTIALS), so do NOT use the `curl` commands above as '
|
|
1073
|
+
+ 'written. Use them only as the reference for routes and JSON bodies, and make every '
|
|
1074
|
+
+ 'workspace call with this PowerShell helper instead. It adds the auth header itself '
|
|
1075
|
+
+ 'and prints the JSON response.',
|
|
1076
|
+
'',
|
|
1077
|
+
`- GET: \`${run} GET '/v1/files?network=...'\``,
|
|
1078
|
+
`- POST/PUT/PATCH: write the JSON body to a file with your file tool, then \`${run} POST /v1/events --body-file body.json\``,
|
|
1079
|
+
`- DELETE: \`${run} DELETE '/v1/files/FILE_ID?network=...'\``,
|
|
1080
|
+
`- Upload a file to this thread: \`${run} upload report.md --channel ${psQuote(channelName)}\``,
|
|
1081
|
+
`- Download a file: \`${run} download FILE_ID out.bin\``,
|
|
1082
|
+
'',
|
|
1083
|
+
'Never paste the workspace token into a command or a file: the helper reads it from the environment.',
|
|
1084
|
+
'',
|
|
1085
|
+
].join('\n');
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1053
1088
|
function buildDeepSeekTaskFile({
|
|
1054
1089
|
agentName, workspaceId, channelName, endpoint, tokenExpr,
|
|
1055
1090
|
mode = 'execute', disabledModules, browserEnabled = false,
|
|
1056
|
-
recap = '', request = '', attachments = '',
|
|
1091
|
+
recap = '', request = '', attachments = '', windowsApi = null,
|
|
1057
1092
|
}) {
|
|
1058
1093
|
// A token expression is a shell reference, never a credential. Anything that
|
|
1059
1094
|
// does not start with `$` is almost certainly a real token passed by mistake.
|
|
1060
1095
|
if (!tokenExpr || !/^\$/.test(String(tokenExpr))) {
|
|
1061
1096
|
throw new Error(
|
|
1062
1097
|
'buildDeepSeekTaskFile: tokenExpr must be a shell expression such as '
|
|
1063
|
-
+ '$
|
|
1098
|
+
+ '$OPENAGENTS_WORKSPACE_AUTH — never the workspace token itself.',
|
|
1064
1099
|
);
|
|
1065
1100
|
}
|
|
1066
1101
|
|
|
@@ -1072,7 +1107,9 @@ function buildDeepSeekTaskFile({
|
|
|
1072
1107
|
endpoint, workspaceId, token: tokenExpr, agentName, channelName, disabledModules, mode,
|
|
1073
1108
|
});
|
|
1074
1109
|
|
|
1075
|
-
const parts = [identity, directive, '\n', collab, '\n', modePrompt, '\n', api, '\n'
|
|
1110
|
+
const parts = [identity, directive, '\n', collab, '\n', modePrompt, '\n', api, '\n'];
|
|
1111
|
+
if (windowsApi) parts.push(buildDeepSeekWindowsApiSection({ ...windowsApi, channelName }), '\n');
|
|
1112
|
+
parts.push(buildGuardrails());
|
|
1076
1113
|
|
|
1077
1114
|
if (recap) {
|
|
1078
1115
|
parts.push(
|
package/src/cli.js
CHANGED
|
@@ -12,22 +12,30 @@ const { AUTH_MODE_KEY, CLI_LOGIN, isCliLogin } = require('./env');
|
|
|
12
12
|
// Arg parsing
|
|
13
13
|
// ---------------------------------------------------------------------------
|
|
14
14
|
|
|
15
|
+
// Flags that may be given more than once (`agn env x --set A=1 --set B=2`).
|
|
16
|
+
// They always parse to an array; every other flag keeps its last value.
|
|
17
|
+
const REPEATABLE_FLAGS = new Set(['set']);
|
|
18
|
+
|
|
15
19
|
function parseArgs(argv) {
|
|
16
20
|
const args = argv.slice(2);
|
|
17
21
|
const flags = {};
|
|
18
22
|
const allPositional = [];
|
|
23
|
+
const setFlag = (name, value) => {
|
|
24
|
+
if (REPEATABLE_FLAGS.has(name)) (flags[name] = flags[name] || []).push(value);
|
|
25
|
+
else flags[name] = value;
|
|
26
|
+
};
|
|
19
27
|
|
|
20
28
|
for (let i = 0; i < args.length; i++) {
|
|
21
29
|
const a = args[i];
|
|
22
30
|
if (a.startsWith('--')) {
|
|
23
31
|
const eq = a.indexOf('=');
|
|
24
32
|
if (eq > 0) {
|
|
25
|
-
|
|
33
|
+
setFlag(a.slice(2, eq), a.slice(eq + 1));
|
|
26
34
|
} else if (i + 1 < args.length && !args[i + 1].startsWith('--')) {
|
|
27
|
-
|
|
35
|
+
setFlag(a.slice(2), args[i + 1]);
|
|
28
36
|
i++;
|
|
29
37
|
} else {
|
|
30
|
-
|
|
38
|
+
setFlag(a.slice(2), true);
|
|
31
39
|
}
|
|
32
40
|
} else {
|
|
33
41
|
allPositional.push(a);
|
|
@@ -820,15 +828,19 @@ async function cmdEnv(connector, flags, positional) {
|
|
|
820
828
|
const type = positional[0];
|
|
821
829
|
if (!type) { print('Usage: agn env <type> [--set KEY=VALUE]'); return; }
|
|
822
830
|
|
|
823
|
-
const
|
|
824
|
-
if (
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
const
|
|
828
|
-
const
|
|
829
|
-
|
|
831
|
+
const setVals = flags.set || [];
|
|
832
|
+
if (setVals.length) {
|
|
833
|
+
// Validate every pair before saving any, so a typo in the last one does
|
|
834
|
+
// not leave the first ones half-applied.
|
|
835
|
+
const updates = {};
|
|
836
|
+
for (const setVal of setVals) {
|
|
837
|
+
const eq = typeof setVal === 'string' ? setVal.indexOf('=') : -1;
|
|
838
|
+
if (eq < 1) { print('Usage: --set KEY=VALUE'); return; }
|
|
839
|
+
updates[setVal.slice(0, eq)] = setVal.slice(eq + 1);
|
|
840
|
+
}
|
|
841
|
+
connector.saveAgentEnv(type, updates);
|
|
830
842
|
try { connector.sendDaemonCommand('reload'); } catch {}
|
|
831
|
-
print(`Saved ${
|
|
843
|
+
print(`Saved ${Object.keys(updates).join(', ')} for ${type}`);
|
|
832
844
|
return;
|
|
833
845
|
}
|
|
834
846
|
|