oira666_pi-subagent 0.7.5 → 0.7.7
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/README.md +16 -2
- package/docs/usage.md +1 -1
- package/extension/interrupt.ts +80 -83
- package/package.json +14 -6
- package/scripts/build-startup.mjs +66 -0
- package/startup.js +12589 -0
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Launches return immediately. Completion and worker messages arrive as steering t
|
|
|
6
6
|
|
|
7
7
|
Requires Pi 1.4.0 or newer, using the `@earendil-works` SDK packages. Only the latest npm Pi release is tested.
|
|
8
8
|
|
|
9
|
-
Tested against Pi 1.4.0
|
|
9
|
+
Tested against Pi 1.4.0 on Linux.
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
@@ -117,6 +117,12 @@ Delegate only when parallel work or context isolation saves enough effort to cov
|
|
|
117
117
|
|
|
118
118
|
Do not use Bash `sleep` or polling loops to wait for workers. Continue useful work, or end the turn and let completion steering wake the lead. Keep the session open. While the lead is idle and worker work remains, an animated `Waiting for subagents - don't close the session` line appears above the unchanged `Running N` line. Active lead turns keep Pi's normal `Working` indicator.
|
|
119
119
|
|
|
120
|
+
### Interrupting work
|
|
121
|
+
|
|
122
|
+
When Pi aborts the main agent, pi-subagent also stops running, queued, and parked subagent work, including detached descendants. This follows Pi's abort signal, not raw Escape keys. Escape handled by a focused overlay or dialog therefore stops no agents. Idle Escape retains Pi's normal behavior.
|
|
123
|
+
|
|
124
|
+
Press **Alt+W** to abort only the main agent and keep subagents running. This exception ends when that run settles; a later normal abort stops subagents again. Your terminal must send Alt/Option+W as a Meta key sequence, such as `ESC w`, or use the Kitty keyboard protocol. Kitty is not required for this binding. Pi 1.4.0 does not match modified Escape shortcuts, so Shift+Escape and Alt+Escape cannot be used for this action.
|
|
125
|
+
|
|
120
126
|
## Agent definitions
|
|
121
127
|
|
|
122
128
|
There are no bundled agents. Without user-created definitions, every task uses the same default worker, with no agent-specific system prompt or instructions. It receives the parent's task text unchanged. Pi's normal system prompt and delegation limits still apply.
|
|
@@ -170,11 +176,19 @@ The single-line dim `WITH SUBS` widget below the editor includes recursive worke
|
|
|
170
176
|
|
|
171
177
|
```bash
|
|
172
178
|
npm ci
|
|
179
|
+
npm run build
|
|
173
180
|
npm run check
|
|
181
|
+
npm run test:package
|
|
174
182
|
```
|
|
175
183
|
|
|
184
|
+
Pi loads `startup.js`, an ESM bundle built from the current TypeScript source with esbuild. Pi SDK, TypeBox, and Node imports stay external so Pi supplies its own host modules. The generated bundle is committed for direct Git installs, and `npm pack` and `npm publish` rebuild it through `prepack`. Run `npm run build` after source changes; do not edit the bundle. Its generated size is exempt from the source-file line limit.
|
|
185
|
+
|
|
186
|
+
The package tests unpack a fresh npm tarball, rebuild it without the existing bundle, compare source and packaged declarations through the latest Pi CLI, and exercise the packaged child runner without model requests. Build tests also check relocated module-relative assets and child entry URLs. Temporary work stays under `tmp/`.
|
|
187
|
+
|
|
176
188
|
`npm test` first installs the four declared Pi SDK packages at `@latest` with `--save-dev --ignore-scripts`, then typechecks before running tests. `npm run check` uses that same path and also checks formatting and file size. Network access is required, and a newer Pi release can update `package.json` and `package-lock.json`. Keep those changes together.
|
|
177
189
|
|
|
190
|
+
`npm run test:evergreen` typechecks and runs all unit/integration tests in an isolated temporary workspace, then runs real-Pi delegation and saved-worker resume e2e tests. Set `EVERGREEN_E2E_MODEL` to an authenticated `provider/model[:thinking]`; `EVERGREEN_PI_BIN` selects the globally installed Pi executable (defaults to `pi` on PATH). E2E keeps sessions enabled, ignores stdin, and uses a disposable agent directory with copies of your auth/model configuration. It makes real model calls and requires network access. See [EVERGREEN.md](EVERGREEN.md) for intent coverage and Pi upgrade risks.
|
|
191
|
+
|
|
178
192
|
Tests use the real SDK packages installed as development dependencies. SDK/loader integration tests exercise extension loading and argument validation. Terminal rendering tests use test themes, including ANSI styling, width limits and theme invalidation. They do not verify every installed theme or a live interactive terminal. Prompt guidance tests check generated text, not model behavior. No host loader or permissive type shims are needed. Run tests outside a delegated worker environment, or unset inherited `PI_SUBAGENT_*` storage and budget variables first.
|
|
179
193
|
|
|
180
194
|
Source organization:
|
|
@@ -187,7 +201,7 @@ Source organization:
|
|
|
187
201
|
| `types/` | Runtime contracts, transcript parsing, outcomes, usage aggregation |
|
|
188
202
|
| `ui/` | Transcript views, trees, navigation and overlays |
|
|
189
203
|
|
|
190
|
-
Root entry points preserve existing imports.
|
|
204
|
+
Root source entry points preserve existing imports. Both `index.ts` and the generated package entry `startup.js` keep the default extension registration export and the named exports `selectParentModelForSubagent`, `getSubagentsToolDescription`, `collectCombinedUsageStatusLine`, and `collectLiveUsageSummary`. `config.ts` and `agents.ts` discover configuration and definitions. Runtime and test files stay below 350 lines; the name list is static data.
|
|
191
205
|
|
|
192
206
|
See [async performance and memory](docs/async-performance.md) for cache behavior, test evidence, and remaining limits.
|
|
193
207
|
|
package/docs/usage.md
CHANGED
|
@@ -16,7 +16,7 @@ Completion is a custom message with `customType: "subagent_completion"`, display
|
|
|
16
16
|
|
|
17
17
|
A worker that settles while descendants remain active sends `Idle, waiting for children.` and its own last answer as ordinary lead steering. That is not a final completion or a final usage total. If parked, the parent saves context and exits while the root broker preserves child execution. `Finished` still waits for subtree settlement.
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
When Pi aborts the main agent, all running, queued, and parked subagent work stops, including detached descendants. In the interactive TUI, Escape uses Pi's normal interrupt handling. Escape consumed by a focused overlay or dialog stops no agents; idle Escape retains Pi's normal behavior. Alt+W aborts only the main agent and leaves subagents running for that run. A later normal abort stops them again. Alt+W requires a terminal that reports Alt/Meta+W, through a legacy Meta sequence or the Kitty keyboard protocol. Explicitly stopped workers do not automatically resume; their usage and spent budget still count.
|
|
20
20
|
|
|
21
21
|
Do not run Bash `sleep` or polling loops while waiting for workers. Do other work, or end the turn and wait for completion steering. Keep the session open. When the lead is idle with running, queued, or parked work pending, the TUI shows an animated `Waiting for subagents - don't close the session` line above `Running N`. It disappears when the lead becomes busy or all worker work finishes; Pi's native `Working` indicator is unchanged.
|
|
22
22
|
|
package/extension/interrupt.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { isKeyRelease, matchesKey } from "@earendil-works/pi-tui";
|
|
2
1
|
import { persistWorkerStops } from "../storage/worker-stops.js";
|
|
3
2
|
import { releaseCompletionDelivery } from "./async-jobs.js";
|
|
4
3
|
import { cachedSchedulerFor } from "./scheduler.js";
|
|
@@ -6,93 +5,92 @@ import { clearSyntheticResumeState, restoreModelAfterResumeFailure } from "./run
|
|
|
6
5
|
import { stopBranches } from "./stop-tool.js";
|
|
7
6
|
import type { ExtensionState } from "./state.js";
|
|
8
7
|
|
|
9
|
-
/**
|
|
8
|
+
/** Follow Pi's settled abort signal, never raw terminal input. */
|
|
10
9
|
export function registerSubagentInterrupt(state: ExtensionState): void {
|
|
11
|
-
let
|
|
10
|
+
let keepSubagents = false;
|
|
12
11
|
let startingResumeEpoch: number | undefined;
|
|
13
|
-
state.onSessionReadyForInterrupt = (
|
|
12
|
+
state.onSessionReadyForInterrupt = () => {
|
|
13
|
+
keepSubagents = false;
|
|
14
14
|
startingResumeEpoch = undefined;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
};
|
|
16
|
+
state.pi.registerShortcut("alt+w", {
|
|
17
|
+
description: "Interrupt only the main agent, leaving subagents running",
|
|
18
|
+
handler: (ctx) => {
|
|
19
|
+
if (ctx.isIdle()) return;
|
|
20
|
+
keepSubagents = true;
|
|
21
|
+
ctx.abort();
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
state.pi.on("agent_settled", (event, ctx) => {
|
|
25
|
+
const keep = keepSubagents;
|
|
26
|
+
keepSubagents = false;
|
|
27
|
+
if (!event.aborted || keep || !state.sessionActive || state.currentDepth !== 0) return;
|
|
18
28
|
const generation = state.lifecycleGeneration;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
state.activeSubagents.size ||
|
|
36
|
-
deliveries.length ||
|
|
37
|
-
state.pendingResumePlans.length ||
|
|
38
|
-
state.pendingInteractiveResumePrompt ||
|
|
39
|
-
state.pendingAutomaticResume
|
|
40
|
-
);
|
|
41
|
-
const errors: string[] = [];
|
|
42
|
-
const attempt = (operation: () => void) => {
|
|
43
|
-
try {
|
|
44
|
-
operation();
|
|
45
|
-
} catch (error) {
|
|
46
|
-
errors.push(error instanceof Error ? error.message : String(error));
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
// Gather local work before reading the ledger, so a disk error cannot hide local handles.
|
|
50
|
-
for (const entry of scheduler?.snapshot() ?? []) names.add(entry.name);
|
|
51
|
-
for (const worker of state.activeSubagents.values()) if (worker.name) names.add(worker.name);
|
|
52
|
-
for (const job of state.backgroundJobs.values()) for (const name of job.names) names.add(name);
|
|
53
|
-
for (const plan of state.pendingResumePlans)
|
|
54
|
-
for (const result of plan.details?.results ?? []) if (result.name) names.add(result.name);
|
|
55
|
-
attempt(() => {
|
|
56
|
-
// Include broker-owned descendants and parked parents, not just local handles.
|
|
57
|
-
for (const entry of scheduler?.treeStore?.snapshot() ?? []) {
|
|
58
|
-
if (["queued", "running", "parking", "suspended", "waking", "stopping"].includes(entry.status))
|
|
59
|
-
names.add(entry.name);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
hasWork ||= names.size > 0;
|
|
63
|
-
if (!hasWork && !errors.length) return;
|
|
29
|
+
// Also cancel an outstanding resume confirmation, even before plans are armed.
|
|
30
|
+
state.interruptEpoch = (state.interruptEpoch ?? 0) + 1;
|
|
31
|
+
const context = state.latestSessionCtx ?? ctx;
|
|
32
|
+
const scheduler = cachedSchedulerFor(state);
|
|
33
|
+
const deliveries = [...state.pendingCompletionDeliveries.keys()];
|
|
34
|
+
const names = new Set<string>();
|
|
35
|
+
let hasWork = !!(
|
|
36
|
+
state.backgroundJobs.size ||
|
|
37
|
+
state.activeSubagents.size ||
|
|
38
|
+
deliveries.length ||
|
|
39
|
+
state.pendingResumePlans.length ||
|
|
40
|
+
state.pendingInteractiveResumePrompt ||
|
|
41
|
+
state.pendingAutomaticResume
|
|
42
|
+
);
|
|
43
|
+
const errors: string[] = [];
|
|
44
|
+
const attempt = (operation: () => void) => {
|
|
64
45
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
} finally {
|
|
83
|
-
// Abort first, clearing Pi's queued steering before replaying accounting without a turn.
|
|
84
|
-
attempt(() => context.abort());
|
|
85
|
-
for (const id of deliveries) {
|
|
86
|
-
attempt(() => state.pendingCompletionInterrupts?.get(id)?.());
|
|
87
|
-
releaseCompletionDelivery(state, id, generation);
|
|
88
|
-
}
|
|
89
|
-
void restoreModelAfterResumeFailure(state, context);
|
|
90
|
-
if (errors.length) context.ui.notify(`Failed to stop some subagent work: ${errors.join("; ")}`, "error");
|
|
46
|
+
operation();
|
|
47
|
+
} catch (error) {
|
|
48
|
+
errors.push(error instanceof Error ? error.message : String(error));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
// Gather local work before reading the ledger, so a disk error cannot hide local handles.
|
|
52
|
+
for (const entry of scheduler?.snapshot() ?? []) names.add(entry.name);
|
|
53
|
+
for (const worker of state.activeSubagents.values()) if (worker.name) names.add(worker.name);
|
|
54
|
+
for (const job of state.backgroundJobs.values()) for (const name of job.names) names.add(name);
|
|
55
|
+
for (const plan of state.pendingResumePlans)
|
|
56
|
+
for (const result of plan.details?.results ?? []) if (result.name) names.add(result.name);
|
|
57
|
+
attempt(() => {
|
|
58
|
+
// Include broker-owned descendants and parked parents, not just local handles.
|
|
59
|
+
for (const entry of scheduler?.treeStore?.snapshot() ?? []) {
|
|
60
|
+
if (["queued", "running", "parking", "suspended", "waking", "stopping"].includes(entry.status))
|
|
61
|
+
names.add(entry.name);
|
|
91
62
|
}
|
|
92
|
-
// Preserve native Escape handling for dialogs, compaction, and the main editor.
|
|
93
|
-
return undefined;
|
|
94
63
|
});
|
|
95
|
-
|
|
64
|
+
hasWork ||= names.size > 0;
|
|
65
|
+
if (!hasWork && !errors.length) return;
|
|
66
|
+
try {
|
|
67
|
+
state.pendingInteractiveResumePrompt = null;
|
|
68
|
+
state.pendingResumePlans = [];
|
|
69
|
+
clearSyntheticResumeState(state);
|
|
70
|
+
attempt(() => {
|
|
71
|
+
if (!names.size) return;
|
|
72
|
+
const stopped = stopBranches(state, [...names]);
|
|
73
|
+
errors.push(...stopped.statuses.flatMap((status) => (status.error ? [status.error] : [])));
|
|
74
|
+
// Synchronous markers precede completion microtasks and automatic recovery.
|
|
75
|
+
persistWorkerStops(state.currentNamesFile, stopped.stoppedNames);
|
|
76
|
+
});
|
|
77
|
+
// Fallbacks are independent: a failed kill or ledger write must not skip other workers.
|
|
78
|
+
if (errors.length) {
|
|
79
|
+
for (const worker of state.activeSubagents.values()) attempt(() => worker.handle.kill?.());
|
|
80
|
+
for (const job of state.backgroundJobs.values()) attempt(() => job.controller.abort());
|
|
81
|
+
} else {
|
|
82
|
+
for (const worker of state.activeSubagents.values()) if (!worker.name) attempt(() => worker.handle.kill?.());
|
|
83
|
+
}
|
|
84
|
+
} finally {
|
|
85
|
+
// Pi has already aborted. Replay interrupted accounting without starting another turn.
|
|
86
|
+
for (const id of deliveries) {
|
|
87
|
+
attempt(() => state.pendingCompletionInterrupts?.get(id)?.());
|
|
88
|
+
releaseCompletionDelivery(state, id, generation);
|
|
89
|
+
}
|
|
90
|
+
void restoreModelAfterResumeFailure(state, context);
|
|
91
|
+
if (errors.length) context.ui.notify(`Failed to stop some subagent work: ${errors.join("; ")}`, "error");
|
|
92
|
+
}
|
|
93
|
+
});
|
|
96
94
|
state.pi.on("input", (event) => {
|
|
97
95
|
const pending = state.pendingAutomaticResume;
|
|
98
96
|
if (
|
|
@@ -119,9 +117,8 @@ export function registerSubagentInterrupt(state: ExtensionState): void {
|
|
|
119
117
|
if (epoch !== undefined && epoch !== (state.interruptEpoch ?? 0)) ctx.abort();
|
|
120
118
|
});
|
|
121
119
|
state.pi.on("session_shutdown", () => {
|
|
120
|
+
keepSubagents = false;
|
|
122
121
|
startingResumeEpoch = undefined;
|
|
123
122
|
state.pendingAutomaticResume = undefined;
|
|
124
|
-
unsubscribe();
|
|
125
|
-
unsubscribe = () => {};
|
|
126
123
|
});
|
|
127
124
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oira666_pi-subagent",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.7",
|
|
4
4
|
"description": "Subagent extension for Pi coding agent. Delegate tasks to specialized agents.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "
|
|
6
|
+
"main": "startup.js",
|
|
7
|
+
"types": "index.ts",
|
|
7
8
|
"files": [
|
|
9
|
+
"startup.js",
|
|
10
|
+
"scripts/build-startup.mjs",
|
|
8
11
|
"index.ts",
|
|
9
12
|
"agents.ts",
|
|
10
13
|
"budget.ts",
|
|
@@ -33,7 +36,7 @@
|
|
|
33
36
|
],
|
|
34
37
|
"pi": {
|
|
35
38
|
"extensions": [
|
|
36
|
-
"./
|
|
39
|
+
"./startup.js"
|
|
37
40
|
]
|
|
38
41
|
},
|
|
39
42
|
"keywords": [
|
|
@@ -55,11 +58,15 @@
|
|
|
55
58
|
},
|
|
56
59
|
"license": "MIT",
|
|
57
60
|
"scripts": {
|
|
61
|
+
"build": "node scripts/build-startup.mjs",
|
|
62
|
+
"prepack": "npm run build",
|
|
58
63
|
"pretest": "npm install --save-dev --ignore-scripts @earendil-works/pi-agent-core@latest @earendil-works/pi-ai@latest @earendil-works/pi-coding-agent@latest @earendil-works/pi-tui@latest && npm run typecheck",
|
|
59
|
-
"test": "node --import tsx/esm --test test/*.test.ts",
|
|
64
|
+
"test": "node --import tsx/esm --test test/*.test.ts test/*.test.mjs",
|
|
65
|
+
"test:package": "node --test test/startup-*.test.mjs",
|
|
66
|
+
"test:evergreen": "npm run pretest && node scripts/evergreen.mjs",
|
|
60
67
|
"typecheck": "tsc --noEmit",
|
|
61
|
-
"format": "prettier --write \"*.ts\" \"{extension,runner,storage,types,ui,test}/**/*.ts\" \"scripts
|
|
62
|
-
"format:check": "prettier --check \"*.ts\" \"{extension,runner,storage,types,ui,test}/**/*.ts\" \"scripts
|
|
68
|
+
"format": "prettier --write \"*.ts\" \"{extension,runner,storage,types,ui,test}/**/*.ts\" \"{scripts,test}/**/*.mjs\" package.json tsconfig.json .prettierrc.json",
|
|
69
|
+
"format:check": "prettier --check \"*.ts\" \"{extension,runner,storage,types,ui,test}/**/*.ts\" \"{scripts,test}/**/*.mjs\" package.json tsconfig.json .prettierrc.json",
|
|
63
70
|
"check:size": "node scripts/check-size.mjs",
|
|
64
71
|
"check": "npm test && npm run format:check && npm run check:size"
|
|
65
72
|
},
|
|
@@ -70,6 +77,7 @@
|
|
|
70
77
|
"@earendil-works/pi-tui": "^1.4.0",
|
|
71
78
|
"@sinclair/typebox": ">=0.34.0",
|
|
72
79
|
"@types/node": "^25.2.3",
|
|
80
|
+
"esbuild": "^0.28.2",
|
|
73
81
|
"prettier": "^3.9.6",
|
|
74
82
|
"tsx": "^4.23.13",
|
|
75
83
|
"typescript": "^5.9.3"
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { build, transform } from "esbuild";
|
|
2
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const packageRoot = fileURLToPath(new URL("../", import.meta.url));
|
|
7
|
+
|
|
8
|
+
/** Keep module-relative assets and child entry URLs relative to the original source file. */
|
|
9
|
+
function sourceUrls(root) {
|
|
10
|
+
return {
|
|
11
|
+
name: "source-module-urls",
|
|
12
|
+
setup(builder) {
|
|
13
|
+
builder.onLoad({ filter: /\.[cm]?[jt]s$/ }, async ({ path: file }) => {
|
|
14
|
+
const contents = await readFile(file, "utf8");
|
|
15
|
+
if (!/\bimport\s*\.\s*meta\b/.test(contents)) return;
|
|
16
|
+
const relative = "./" + path.relative(root, file).split(path.sep).map(encodeURIComponent).join("/");
|
|
17
|
+
const result = await transform(contents, {
|
|
18
|
+
loader: file.endsWith("ts") ? "ts" : "js",
|
|
19
|
+
format: "esm",
|
|
20
|
+
target: "node22",
|
|
21
|
+
define: { "import.meta.url": "__subagentSourceUrl" },
|
|
22
|
+
banner: `const __subagentSourceUrl = new URL(${JSON.stringify(relative)}, import.meta.url).href;`,
|
|
23
|
+
});
|
|
24
|
+
return { contents: result.code, loader: "js", resolveDir: path.dirname(file) };
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Bundle only local modules. Host SDK packages must be resolved by Pi's loader. */
|
|
31
|
+
export async function buildStartup({ root = packageRoot } = {}) {
|
|
32
|
+
root = path.resolve(root);
|
|
33
|
+
const result = await build({
|
|
34
|
+
absWorkingDir: root,
|
|
35
|
+
entryPoints: ["index.ts"],
|
|
36
|
+
outfile: "startup.js",
|
|
37
|
+
bundle: true,
|
|
38
|
+
packages: "external",
|
|
39
|
+
platform: "node",
|
|
40
|
+
format: "esm",
|
|
41
|
+
target: "node22",
|
|
42
|
+
metafile: true,
|
|
43
|
+
write: false,
|
|
44
|
+
plugins: [sourceUrls(root)],
|
|
45
|
+
banner: { js: "// Generated by npm run build. Edit the TypeScript sources, not this file." },
|
|
46
|
+
});
|
|
47
|
+
for (const input of Object.keys(result.metafile.inputs)) {
|
|
48
|
+
const relative = path.relative(root, path.resolve(root, input));
|
|
49
|
+
if (
|
|
50
|
+
relative.startsWith(".." + path.sep) ||
|
|
51
|
+
path.isAbsolute(relative) ||
|
|
52
|
+
relative.split(path.sep).includes("node_modules")
|
|
53
|
+
) {
|
|
54
|
+
throw new Error(`Startup bundles must contain only this package's source: ${input}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
await writeFile(path.join(root, "startup.js"), result.outputFiles[0].contents);
|
|
58
|
+
return result.metafile;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
62
|
+
const metadata = await buildStartup();
|
|
63
|
+
console.error(
|
|
64
|
+
`Built startup.js from ${Object.keys(metadata.inputs).length} local modules; package imports remain external.`,
|
|
65
|
+
);
|
|
66
|
+
}
|