aegiscode 6.8.18 → 6.8.20
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 +4 -2
- package/scripts/check.mjs +50 -0
- package/scripts/predist.mjs +11 -0
- package/src/app.js +23 -0
- package/src/chatflow.js +48 -21
- package/src/commands.js +41 -35
- package/src/devrun.js +80 -6
- package/src/models.js +166 -33
- package/src/panels.js +2 -1
- package/src/summarize.js +3 -1
- package/vendor/client/aegis.js +13 -0
- package/vendor/client/authorship-key.js +45 -4
- package/vendor/client/byok-catalog.js +49 -1
- package/vendor/client/credentials.js +94 -6
- package/vendor/client/env-file.js +161 -5
- package/vendor/client/hooks.js +427 -0
- package/vendor/client/platform.js +410 -0
- package/vendor/desktop/lib/local/engine.js +114 -39
- package/vendor/desktop/lib/local/shell.js +393 -39
- package/vendor/desktop/lib/local/tools.js +156 -13
- package/vendor/desktop/lib/settings.js +36 -1
- package/vendor/desktop/renderer/usage.js +30 -0
- package/vendor/tools/agent-gate.mjs +81 -13
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aegiscode",
|
|
3
3
|
"productName": "AEGIS Code",
|
|
4
|
-
"version": "6.8.
|
|
4
|
+
"version": "6.8.20",
|
|
5
5
|
"description": "aegiscode — the command-line version of AEGIS Desktop. The shared tool surface in your shell, over the same thin transport and tool registry as the MCP plugin and the desktop app. Ships transport + UI only; no brain.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "AEGIS Code",
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
"start": "node bin/aegiscode.js",
|
|
27
27
|
"predist": "node scripts/predist.mjs",
|
|
28
28
|
"prepublishOnly": "npm run predist",
|
|
29
|
-
"
|
|
29
|
+
"precheck": "node scripts/predist.mjs",
|
|
30
|
+
"check": "node scripts/check.mjs",
|
|
31
|
+
"pretest": "node scripts/predist.mjs",
|
|
30
32
|
"test": "node scripts/runtests.mjs"
|
|
31
33
|
},
|
|
32
34
|
"keywords": [
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Syntax-check every file `node --check` should gate on, and report all of
|
|
4
|
+
* them. Replaces the POSIX loop
|
|
5
|
+
*
|
|
6
|
+
* for f in src/*.js; do node --check "$f" || exit 1; done
|
|
7
|
+
*
|
|
8
|
+
* which npm runs through ComSpec on Windows, where `for…do…done` is not shell
|
|
9
|
+
* syntax. A Node walker keeps `npm run check` identical on every OS, and — like
|
|
10
|
+
* `runtests.mjs` — collects failures instead of stopping at the first one, so
|
|
11
|
+
* one broken file cannot hide every file after it.
|
|
12
|
+
*/
|
|
13
|
+
import { readdirSync } from 'node:fs';
|
|
14
|
+
import { spawnSync } from 'node:child_process';
|
|
15
|
+
import { dirname, join, resolve } from 'node:path';
|
|
16
|
+
import { fileURLToPath } from 'node:url';
|
|
17
|
+
|
|
18
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const cliRoot = resolve(here, '..');
|
|
20
|
+
const srcDir = join(cliRoot, 'src');
|
|
21
|
+
|
|
22
|
+
const targets = [
|
|
23
|
+
join(cliRoot, 'bin', 'aegiscode.js'),
|
|
24
|
+
...readdirSync(srcDir)
|
|
25
|
+
.filter((f) => f.endsWith('.js'))
|
|
26
|
+
.sort()
|
|
27
|
+
.map((f) => join(srcDir, f)),
|
|
28
|
+
join(here, 'predist.mjs'),
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
if (targets.length === 0) {
|
|
32
|
+
process.stderr.write('check: no files to check\n');
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const failed = [];
|
|
37
|
+
for (const file of targets) {
|
|
38
|
+
const res = spawnSync(process.execPath, ['--check', file], { stdio: 'inherit' });
|
|
39
|
+
if (res.status !== 0) failed.push({ file, status: res.status });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (failed.length) {
|
|
43
|
+
process.stderr.write(`\ncheck failed (${failed.length}):\n`);
|
|
44
|
+
for (const { file, status } of failed) {
|
|
45
|
+
process.stderr.write(` \u2717 ${file} (exit ${status})\n`);
|
|
46
|
+
}
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
process.stdout.write(`check ok: ${targets.length} files\n`);
|
package/scripts/predist.mjs
CHANGED
|
@@ -92,6 +92,17 @@ const FILES = [
|
|
|
92
92
|
// src/commands.js, so a package built without it throws MODULE_NOT_FOUND on
|
|
93
93
|
// the first picker or /byok listing instead of showing a short one.
|
|
94
94
|
'client/byok-catalog.js',
|
|
95
|
+
// The shared HOOK layer: the hook config reader behind /hooks and the
|
|
96
|
+
// installer for this repo guard hooks, with one implementation for the
|
|
97
|
+
// CLI, the desktop app and tools/agent-gate.mjs. src/commands.js resolves
|
|
98
|
+
// it through resolveShared, so a package staged without it loses the
|
|
99
|
+
// /hooks command at load time with MODULE_NOT_FOUND.
|
|
100
|
+
'client/hooks.js',
|
|
101
|
+
// The shared platform module (Phase 30.1): the one place that decides which
|
|
102
|
+
// OS this is. desktop/lib/local/tools.js requires it for its exec shell spec,
|
|
103
|
+
// and desktop/lib/local/tools.js is staged below, so leaving this out stages
|
|
104
|
+
// a vendor tree whose exec tool throws MODULE_NOT_FOUND on first use.
|
|
105
|
+
'client/platform.js',
|
|
95
106
|
'mcp/tools.js',
|
|
96
107
|
// The stdio MCP server itself — the process every editor config written by
|
|
97
108
|
// `aegiscode mcp install` points at. Staging the registry without it ships a
|
package/src/app.js
CHANGED
|
@@ -1762,6 +1762,22 @@ function createApp(options = {}) {
|
|
|
1762
1762
|
TOOLS,
|
|
1763
1763
|
ask: (prompt, o) => ask(prompt, o),
|
|
1764
1764
|
makeCommandContext: () => makeCommandContext(),
|
|
1765
|
+
// The two stores that are NOT `~/.aegiscode/.env`, which the picker's key
|
|
1766
|
+
// queue has to consult before it may ask for a key that is already saved
|
|
1767
|
+
// somewhere both hosts read:
|
|
1768
|
+
// - `accountConfigured` — the AEGIS account key in credentials.json,
|
|
1769
|
+
// written by /key and by `aegiscode login`.
|
|
1770
|
+
// - `hasProviderKey(p)` — a `byok:<provider>` row, the store /byok-key
|
|
1771
|
+
// and the desktop's Provider settings share (engine.js byokNamespace).
|
|
1772
|
+
// Without these two the picker would re-prompt for a key the machine
|
|
1773
|
+
// demonstrably holds, which is how the same key got saved twice.
|
|
1774
|
+
accountConfigured: () => !!(credentials.keyStatus() || {}).configured,
|
|
1775
|
+
hasProviderKey: (provider) => {
|
|
1776
|
+
const store = engine.settings;
|
|
1777
|
+
if (!store || typeof store.get !== 'function' || !provider) return false;
|
|
1778
|
+
const row = (store.get(byokNamespace(provider)) || {});
|
|
1779
|
+
return !!String(row.key || '').trim();
|
|
1780
|
+
},
|
|
1765
1781
|
loadModels: (o) => loadModels(o),
|
|
1766
1782
|
buildState: () => buildState(),
|
|
1767
1783
|
dispatchLine: (line, c) => handleLine(line, c),
|
|
@@ -2052,6 +2068,13 @@ function createApp(options = {}) {
|
|
|
2052
2068
|
setCloudSync,
|
|
2053
2069
|
cloudsync,
|
|
2054
2070
|
keyStatus: () => credentials.keyStatus(),
|
|
2071
|
+
accountConfigured: () => !!(credentials.keyStatus() || {}).configured,
|
|
2072
|
+
hasProviderKey: (provider) => {
|
|
2073
|
+
const store = engine.settings;
|
|
2074
|
+
if (!store || typeof store.get !== 'function' || !provider) return false;
|
|
2075
|
+
const row = (store.get(byokNamespace(provider)) || {});
|
|
2076
|
+
return !!String(row.key || '').trim();
|
|
2077
|
+
},
|
|
2055
2078
|
sessionId: () => commandCtx.sessionId,
|
|
2056
2079
|
tokenSummary,
|
|
2057
2080
|
resumeSession,
|
package/src/chatflow.js
CHANGED
|
@@ -1548,39 +1548,66 @@ async function runSession(host) {
|
|
|
1548
1548
|
* with the provider's own error until a key arrives — never a silent no-op).
|
|
1549
1549
|
*/
|
|
1550
1550
|
const collectKeyFor = async (chosen) => {
|
|
1551
|
-
|
|
1551
|
+
// EVERY key this row needs, in ask order: the AEGIS account key first (the
|
|
1552
|
+
// pooled route's identity, and what reads the catalog at all), then the
|
|
1553
|
+
// VENDOR key the row is named after when this machine lacks one
|
|
1554
|
+
// (`deepseek` → DEEPSEEK_API_KEY). One prompt was not enough: a pooled row
|
|
1555
|
+
// named after a vendor is billed to the account, but the pool calls that
|
|
1556
|
+
// vendor, so an account key alone left the turn failing upstream with
|
|
1557
|
+
// nothing the user could act on — see models.js modelKeyQueue.
|
|
1558
|
+
//
|
|
1559
|
+
// Both facts about the stores that are NOT the env file are supplied here,
|
|
1560
|
+
// because only the host knows them: `accountConfigured` (credentials.json,
|
|
1561
|
+
// written by /key or `aegiscode login`) and `hasStoredFor` (the
|
|
1562
|
+
// `byok:<provider>` rows the provider store and the desktop's provider
|
|
1563
|
+
// settings share).
|
|
1564
|
+
const queue = models.modelKeyQueue(chosen, {
|
|
1552
1565
|
// Never throws: an injected engine may carry no provider store, and a
|
|
1553
1566
|
// missing store must read as "no key" rather than break the picker.
|
|
1554
1567
|
accountConfigured: host.accountConfigured ? !!host.accountConfigured() : false,
|
|
1555
|
-
|
|
1568
|
+
hasStoredFor: (vendor) => (host.hasProviderKey ? !!host.hasProviderKey(vendor) : false),
|
|
1556
1569
|
});
|
|
1557
|
-
if (!
|
|
1558
|
-
// Quiet on purpose:
|
|
1559
|
-
// note per pick would be noise on the common path.
|
|
1570
|
+
if (!queue.length) {
|
|
1571
|
+
// Quiet on purpose: every key this row needs is already somewhere both
|
|
1572
|
+
// hosts look, and a note per pick would be noise on the common path.
|
|
1560
1573
|
return;
|
|
1561
1574
|
}
|
|
1562
1575
|
let c = null;
|
|
1563
1576
|
try { c = host.makeCommandContext(); } catch { c = null; }
|
|
1564
1577
|
if (!c || typeof c.readSecret !== 'function') {
|
|
1565
|
-
|
|
1578
|
+
// No way to ask where the user can answer: name every variable still
|
|
1579
|
+
// missing rather than only the last one, so one round of setup finishes
|
|
1580
|
+
// the job instead of leaving the second key to be discovered by failure.
|
|
1581
|
+
const missing = queue.map((s) => `${s.env}: ${s.why}`).join(' · ');
|
|
1582
|
+
note(`${chosen.id} has no key: ${missing}. Set the ones above and pick it again.`);
|
|
1566
1583
|
return;
|
|
1567
1584
|
}
|
|
1568
|
-
const
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1585
|
+
for (const step of queue) {
|
|
1586
|
+
// Pooled rows bill the account; a vendor step names its provider. The
|
|
1587
|
+
// label says WHICH key is wanted, because two prompts in a row for the
|
|
1588
|
+
// same row must not read as the same question asked twice.
|
|
1589
|
+
const label = step.role === 'account' ? 'AEGIS account key' : `${step.provider} key`;
|
|
1590
|
+
const key = String(
|
|
1591
|
+
(await c.readSecret(`${label} → ${step.env} (kept off screen, Enter to skip): `)) || ''
|
|
1592
|
+
).trim();
|
|
1593
|
+
if (!key) {
|
|
1594
|
+
// Skipping one key must not abandon the rest: the vendor key is still
|
|
1595
|
+
// worth collecting for a row whose account key the user just pasted
|
|
1596
|
+
// elsewhere, and vice versa.
|
|
1597
|
+
note(`no key given — ${step.env} is still unset, so ${chosen.id} will fail until it is.`);
|
|
1598
|
+
continue;
|
|
1599
|
+
}
|
|
1600
|
+
// `env: step.env` is what makes a per-step store possible at all: the row
|
|
1601
|
+
// alone cannot say which of its two keys this value is for.
|
|
1602
|
+
const res = models.storeModelKey(chosen, key, { env: step.env });
|
|
1603
|
+
if (!res.ok) {
|
|
1604
|
+
note(`could not save the key: ${res.error || 'unknown error'}`);
|
|
1605
|
+
continue;
|
|
1606
|
+
}
|
|
1607
|
+
note(res.changed
|
|
1608
|
+
? `${step.env} saved to ${res.file} (0600) — both hosts read that file; nothing to export.`
|
|
1609
|
+
: `${step.env} was already set in ${res.file}.`);
|
|
1580
1610
|
}
|
|
1581
|
-
note(res.changed
|
|
1582
|
-
? `${plan.env} saved to ${res.file} (0600) — both hosts read that file; nothing to export.`
|
|
1583
|
-
: `${plan.env} was already set in ${res.file}.`);
|
|
1584
1611
|
};
|
|
1585
1612
|
|
|
1586
1613
|
const handleOverlayKey = async (key) => {
|
package/src/commands.js
CHANGED
|
@@ -670,42 +670,25 @@ async function runCloudSync(c, o = {}) {
|
|
|
670
670
|
return res;
|
|
671
671
|
}
|
|
672
672
|
|
|
673
|
-
/**
|
|
673
|
+
/**
|
|
674
|
+
* Hook config and repo-hook install come from the SHARED module
|
|
675
|
+
* (`client/hooks.js`, staged to vendor/client/hooks.js in a package), because
|
|
676
|
+
* the desktop app reads the same files and installs the same `.githooks/`.
|
|
677
|
+
*
|
|
678
|
+
* This file used to carry a private `readHooks()`/`hookStats()`. Two copies of
|
|
679
|
+
* "which settings files count" is how the terminal and the GUI end up
|
|
680
|
+
* describing one machine differently, and the private copy was joined with the
|
|
681
|
+
* HOST's separator — so a Windows path was handled correctly and could not be
|
|
682
|
+
* tested anywhere but Windows.
|
|
683
|
+
*/
|
|
684
|
+
const hooksLib = require(resolveShared(path.join('client', 'hooks.js')));
|
|
685
|
+
|
|
674
686
|
function readHooks() {
|
|
675
|
-
|
|
676
|
-
path.join(os.homedir(), '.aegis', 'settings.json'),
|
|
677
|
-
path.join(process.cwd(), '.aegis', 'settings.json'),
|
|
678
|
-
path.join(os.homedir(), '.aegiscode', 'settings.json'),
|
|
679
|
-
path.join(process.cwd(), '.aegiscode', 'settings.json'),
|
|
680
|
-
path.join(os.homedir(), '.claude', 'settings.json'),
|
|
681
|
-
];
|
|
682
|
-
const hooks = {};
|
|
683
|
-
const from = [];
|
|
684
|
-
for (const p of sources) {
|
|
685
|
-
try {
|
|
686
|
-
const j = JSON.parse(fs.readFileSync(p, 'utf8'));
|
|
687
|
-
if (j && j.hooks && typeof j.hooks === 'object') {
|
|
688
|
-
from.push(p.replace(os.homedir(), '~'));
|
|
689
|
-
for (const [ev, arr] of Object.entries(j.hooks)) {
|
|
690
|
-
hooks[ev] = [...(hooks[ev] || []), ...(Array.isArray(arr) ? arr : [])];
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
} catch {}
|
|
694
|
-
}
|
|
695
|
-
return { hooks, from };
|
|
687
|
+
return hooksLib.readHookConfig();
|
|
696
688
|
}
|
|
697
689
|
|
|
698
|
-
/** {enabled,hooks,events,byEvent} from a merged hooks map. */
|
|
699
690
|
function hookStats(hooks) {
|
|
700
|
-
|
|
701
|
-
let count = 0;
|
|
702
|
-
const byEvent = {};
|
|
703
|
-
for (const [ev, arr] of Object.entries(hooks)) {
|
|
704
|
-
const n = Array.isArray(arr) ? arr.length : 0;
|
|
705
|
-
byEvent[ev] = n;
|
|
706
|
-
count += n;
|
|
707
|
-
}
|
|
708
|
-
return { enabled: count > 0, hooks: count, events, byEvent };
|
|
691
|
+
return hooksLib.hookStats(hooks);
|
|
709
692
|
}
|
|
710
693
|
|
|
711
694
|
/** Scan the standard skill dirs for SKILL.md files. */
|
|
@@ -1557,10 +1540,33 @@ const COMMANDS = [
|
|
|
1557
1540
|
},
|
|
1558
1541
|
},
|
|
1559
1542
|
{
|
|
1560
|
-
name: 'hooks', args: ['sub'], hint: '[status|list]', category: 'model',
|
|
1561
|
-
desc: 'View hooks configuration status
|
|
1543
|
+
name: 'hooks', args: ['sub'], hint: '[status|list|install]', category: 'model',
|
|
1544
|
+
desc: 'View hooks configuration status, list configured hooks, or install this repo\'s guard hooks',
|
|
1562
1545
|
handler: async (c, args) => {
|
|
1563
1546
|
const sub = (args.sub || '').toLowerCase();
|
|
1547
|
+
if (sub === 'install') {
|
|
1548
|
+
// The one mutating branch, and the one that makes the guards real: a
|
|
1549
|
+
// fresh clone has .githooks/ present and core.hooksPath unset, so a
|
|
1550
|
+
// commit runs NO guard at all (`.githooks/lib-gate.sh` says so itself).
|
|
1551
|
+
const dryRun = /--dry-run|\bdry-?run\b/.test(String(args._rest || ''));
|
|
1552
|
+
const res = hooksLib.installRepoHooks({ cwd: process.cwd(), dryRun });
|
|
1553
|
+
if (!res.ok) {
|
|
1554
|
+
note(c, res.error);
|
|
1555
|
+
if (res.actions.length) for (const a of res.actions) note(c, ` ${a}`);
|
|
1556
|
+
} else if (dryRun) {
|
|
1557
|
+
note(c, `would install the guard hooks in ${res.status.repo}`);
|
|
1558
|
+
for (const a of res.actions) note(c, ` ${a}`);
|
|
1559
|
+
if (res.status.installed) note(c, 'core.hooksPath is already .githooks — nothing to change');
|
|
1560
|
+
} else if (!res.changed) {
|
|
1561
|
+
done(c, `guard hooks already installed (core.hooksPath = .githooks)`);
|
|
1562
|
+
} else {
|
|
1563
|
+
done(c, `installed the guard hooks — core.hooksPath = .githooks (verified)`);
|
|
1564
|
+
for (const a of res.actions) note(c, ` ${a}`);
|
|
1565
|
+
}
|
|
1566
|
+
if (res.ok) note(c, res.status.execNote);
|
|
1567
|
+
c.render();
|
|
1568
|
+
return true;
|
|
1569
|
+
}
|
|
1564
1570
|
const { hooks, from } = readHooks();
|
|
1565
1571
|
if (sub === 'list') {
|
|
1566
1572
|
panel(c, panels.buildHooksList({ hooks }, c.ctx));
|
|
@@ -1573,7 +1579,7 @@ const COMMANDS = [
|
|
|
1573
1579
|
return true;
|
|
1574
1580
|
}
|
|
1575
1581
|
note(c, `unknown subcommand: ${args.sub}`);
|
|
1576
|
-
note(c, 'available: status, list');
|
|
1582
|
+
note(c, 'available: status, list, install [--dry-run]');
|
|
1577
1583
|
c.render();
|
|
1578
1584
|
return true;
|
|
1579
1585
|
},
|
package/src/devrun.js
CHANGED
|
@@ -12,6 +12,13 @@ const { spawn } = require('node:child_process');
|
|
|
12
12
|
const fs = require('node:fs');
|
|
13
13
|
const path = require('node:path');
|
|
14
14
|
|
|
15
|
+
// The one shared module that knows which OS this is (plan Phase 30.1), staged
|
|
16
|
+
// into `cli/vendor/client/` for the published layout — same resolver every
|
|
17
|
+
// other shared client module goes through, so this file never re-derives
|
|
18
|
+
// `process.platform` on its own (that duplication is F4's complaint).
|
|
19
|
+
const { resolveClientModule } = require('./shared.js');
|
|
20
|
+
const sharedPlatform = require(resolveClientModule('platform.js'));
|
|
21
|
+
|
|
15
22
|
const MAX_STREAM_LINES = 40;
|
|
16
23
|
|
|
17
24
|
/** Detect the most likely dev command for a project, or null. */
|
|
@@ -36,11 +43,27 @@ function detectDevCommand(cwd = process.cwd()) {
|
|
|
36
43
|
/**
|
|
37
44
|
* Run a shell command, streaming stdout/stderr lines to onLine. Returns a job:
|
|
38
45
|
* { stop(), done: Promise<{ code, stopped }> }
|
|
39
|
-
* The child
|
|
46
|
+
* The child — and, via platform.killTree(), its descendants — is killed when
|
|
47
|
+
* stop() is called or `signal` aborts.
|
|
48
|
+
*
|
|
49
|
+
* Options:
|
|
50
|
+
* onLine (line) => void stream sink
|
|
51
|
+
* signal AbortSignal abort => stop
|
|
52
|
+
* cwd string
|
|
53
|
+
* onError (err, result) => void where a FAILED kill is reported
|
|
54
|
+
* platform implementation or name the test seam: pass an object with
|
|
55
|
+
* `killTree` to stub the kill, or an
|
|
56
|
+
* OS name ('win32' | 'linux' | …) to
|
|
57
|
+
* drive the real module's win32 path
|
|
58
|
+
* from a non-Windows host
|
|
59
|
+
* killOptions seams forwarded to killTree ({ platform, kill, run, signal,
|
|
60
|
+
* detached, timeout })
|
|
40
61
|
*/
|
|
41
|
-
function runDevServer(command, { onLine, signal, cwd } = {}) {
|
|
42
|
-
// detached
|
|
43
|
-
//
|
|
62
|
+
function runDevServer(command, { onLine, signal, cwd, onError, platform: platformImpl, killOptions } = {}) {
|
|
63
|
+
// detached: the child leads its own process group on posix, which is what
|
|
64
|
+
// lets killTree() take the whole tree out with kill(-pid) instead of leaking
|
|
65
|
+
// grandchildren. On win32 there is no group to signal — killTree() uses
|
|
66
|
+
// `taskkill /T` to walk the parent/child tree instead.
|
|
44
67
|
const child = spawn(command, { shell: true, cwd: cwd || process.cwd(), env: process.env, detached: true });
|
|
45
68
|
let buffer = '';
|
|
46
69
|
let stopped = false;
|
|
@@ -67,8 +90,49 @@ function runDevServer(command, { onLine, signal, cwd } = {}) {
|
|
|
67
90
|
child.stderr && child.stderr.on('data', deliver);
|
|
68
91
|
if (buffer.trim() && onLine) onLine(buffer.trim()); // trailing partial line
|
|
69
92
|
|
|
93
|
+
// ---------------------------------------------------------------------
|
|
94
|
+
// Stopping the server (plan Phase 30.2, defect F3).
|
|
95
|
+
//
|
|
96
|
+
// This used to be a bare negative-pid signal to the process group, wrapped in
|
|
97
|
+
// an empty `try {} catch {}`.
|
|
98
|
+
//
|
|
99
|
+
// A negative pid is a POSIX *process-group* kill. On win32 that call throws,
|
|
100
|
+
// and the empty catch ate the throw, so the dev server and every child it
|
|
101
|
+
// had spawned were silently orphaned with no error anywhere: not in the
|
|
102
|
+
// transcript, not on stderr. The swallow was as much the bug as the signal
|
|
103
|
+
// (the same defect class the engine fixed in its Phase 21c, src/proc.js).
|
|
104
|
+
//
|
|
105
|
+
// The stop now goes through platform.killTree() (the shared module, plan
|
|
106
|
+
// 30.1): posix keeps the detached-group kill, win32 runs
|
|
107
|
+
// `taskkill /PID <pid> /T /F`, and the result is `{ ok, error }` rather than
|
|
108
|
+
// a throw — so a failure can be *reported*. It is: onError if the caller
|
|
109
|
+
// gave one, otherwise the transcript the user is already reading, otherwise
|
|
110
|
+
// stderr. Never dropped.
|
|
111
|
+
// ---------------------------------------------------------------------
|
|
112
|
+
const killApi =
|
|
113
|
+
platformImpl && typeof platformImpl === 'object' && typeof platformImpl.killTree === 'function'
|
|
114
|
+
? platformImpl
|
|
115
|
+
: sharedPlatform;
|
|
116
|
+
const killSeams = { ...(killOptions || {}) };
|
|
117
|
+
if (typeof platformImpl === 'string' && !killSeams.platform) killSeams.platform = platformImpl;
|
|
118
|
+
|
|
119
|
+
const reportKillFailure = (err) => {
|
|
120
|
+
if (typeof onError === 'function') {
|
|
121
|
+
onError(err);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const text = `[run] could not stop the dev server (pid ${child.pid}): ${err && err.message} — it may still be running`;
|
|
125
|
+
if (typeof onLine === 'function') onLine(text);
|
|
126
|
+
else console.error(text);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
let killError = null;
|
|
70
130
|
const killGroup = () => {
|
|
71
|
-
|
|
131
|
+
const res = killApi.killTree(child, killSeams);
|
|
132
|
+
if (res && res.ok) return res;
|
|
133
|
+
killError = (res && res.error) || new Error('killTree failed without an error result');
|
|
134
|
+
reportKillFailure(killError);
|
|
135
|
+
return res;
|
|
72
136
|
};
|
|
73
137
|
const onAbort = () => { stopped = true; killGroup(); };
|
|
74
138
|
if (signal) signal.addEventListener('abort', onAbort, { once: true });
|
|
@@ -92,12 +156,22 @@ function runDevServer(command, { onLine, signal, cwd } = {}) {
|
|
|
92
156
|
child.on('exit', () => setTimeout(() => settle({ code: code ?? 0, stopped }), 1000));
|
|
93
157
|
|
|
94
158
|
return {
|
|
159
|
+
// The spawned pid — the one stop() actually kills, and the value a caller
|
|
160
|
+
// (or a test, on a host that is not the OS under test) needs to reason
|
|
161
|
+
// about the kill after the fact.
|
|
162
|
+
pid: child.pid,
|
|
95
163
|
stop: () => {
|
|
96
164
|
stopped = true;
|
|
97
|
-
killGroup();
|
|
165
|
+
const res = killGroup();
|
|
98
166
|
// Pipe-holding survivors can still delay 'close' — force the job to
|
|
99
167
|
// settle so the session loop's streamJob guard can't swallow keys.
|
|
100
168
|
setTimeout(() => settle({ code: code ?? null, stopped: true }), 5000);
|
|
169
|
+
return res;
|
|
170
|
+
},
|
|
171
|
+
// The last kill failure, if any — the caller can report it after the fact
|
|
172
|
+
// instead of only through the onError callback.
|
|
173
|
+
get killError() {
|
|
174
|
+
return killError;
|
|
101
175
|
},
|
|
102
176
|
done,
|
|
103
177
|
};
|