@openagents-org/agent-launcher 0.2.211 → 0.2.212

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openagents-org/agent-launcher",
3
- "version": "0.2.211",
3
+ "version": "0.2.212",
4
4
  "description": "OpenAgents Launcher — install, configure, and run AI coding agents from your terminal",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/registry.json CHANGED
@@ -1807,12 +1807,12 @@
1807
1807
  "requires": [
1808
1808
  "nodejs"
1809
1809
  ],
1810
- "supported_version": "0.2.1-rc.2",
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.2",
1814
- "linux": "npm install -g @deepseek-ai/dsh@0.2.1-rc.2",
1815
- "windows": "npm install -g @deepseek-ai/dsh@0.2.1-rc.2"
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.2 (bin `dsh` -> lib/bin.js, ESM).
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.2`) and upstream says compatibility may
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.2';
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
- [FAILURE.MODEL, /\b(model[_\s-]?not[_\s-]?found|unknown model|unsupported model|no such model|context[_\s-]?length|token limit|quota|rate[_\s-]?limit|429)/i],
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)));
@@ -121,8 +121,25 @@ const BOOTSTRAP_KEY = '\u0000bootstrap';
121
121
  const RECAP_HEAD = 30;
122
122
  const RECAP_TAIL = 60;
123
123
 
124
- /** The environment variable the task file tells the agent to read. */
125
- const TOKEN_ENV = 'OPENAGENTS_WORKSPACE_TOKEN';
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({ model: this._model(), gatewayBaseUrl: this._gatewayBaseUrl() });
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;
@@ -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
- * (`$OPENAGENTS_WORKSPACE_TOKEN`, or `$env:OPENAGENTS_WORKSPACE_TOKEN` on
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
- + '$OPENAGENTS_WORKSPACE_TOKEN — never the workspace token itself.',
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', buildGuardrails()];
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
- flags[a.slice(2, eq)] = a.slice(eq + 1);
33
+ setFlag(a.slice(2, eq), a.slice(eq + 1));
26
34
  } else if (i + 1 < args.length && !args[i + 1].startsWith('--')) {
27
- flags[a.slice(2)] = args[i + 1];
35
+ setFlag(a.slice(2), args[i + 1]);
28
36
  i++;
29
37
  } else {
30
- flags[a.slice(2)] = true;
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 setVal = flags.set;
824
- if (setVal) {
825
- const eq = setVal.indexOf('=');
826
- if (eq < 1) { print('Usage: --set KEY=VALUE'); return; }
827
- const key = setVal.slice(0, eq);
828
- const val = setVal.slice(eq + 1);
829
- connector.saveAgentEnv(type, { [key]: val });
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 ${key} for ${type}`);
843
+ print(`Saved ${Object.keys(updates).join(', ')} for ${type}`);
832
844
  return;
833
845
  }
834
846