@saadnvd1/agent-os 0.3.680 → 0.3.684
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 +2 -2
- package/lib/code-health/reports.ts +38 -1
- package/lib/code-health/source.ts +1 -1
- package/lib/dev-instance/spawnServer.ts +10 -6
- package/lib/doctor/checks.ts +1 -1
- package/lib/env-setup.ts +2 -0
- package/lib/files.ts +1 -0
- package/lib/orchestrator/brief.ts +1 -1
- package/lib/share/pdf.ts +32 -1
- package/lib/tasks/setup.ts +9 -2
- package/lib/worktree-deps/clone.ts +10 -0
- package/lib/worktree-deps/fastcopy.ts +8 -1
- package/lib/worktree-deps/index.ts +14 -19
- package/lib/worktree-deps/install.ts +17 -24
- package/package.json +8 -15
- package/scripts/check-native.mjs +86 -0
- package/scripts/code-health/prepass.ts +3 -3
- package/scripts/install-deps +24 -0
- package/scripts/lib/commands.sh +2 -2
- package/scripts/lib/deps-swap.sh +68 -0
- package/scripts/lib/deps-swap.test.ts +115 -0
- package/scripts/lib/pnpm.sh +36 -0
- package/scripts/lib/prerequisites.sh +9 -9
- package/scripts/publish +3 -2
- package/scripts/redeploy +25 -8
- package/scripts/setup.sh +4 -4
- package/tsconfig.json +1 -0
- package/scripts/ensure-native.mjs +0 -23
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ and check on all of it from your phone.
|
|
|
43
43
|
|
|
44
44
|
## Install
|
|
45
45
|
|
|
46
|
-
You need Node.js
|
|
46
|
+
You need Node.js 22+, tmux, and at least one agent CLI (the installer offers to set up what's missing).
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
49
|
npm install -g @saadnvd1/agent-os
|
|
@@ -74,7 +74,7 @@ npm run check # typecheck, lint, format and tests: what CI runs
|
|
|
74
74
|
npm run screenshots # regenerate screenshots/ from a demo instance with fake data
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
A pre-commit hook checks formatting, secrets and banned terms on what is staged. Route handlers may not call `*Sync` functions, and git runs only through `lib/git-exec.ts`. More in [docs/reference/development.md](docs/reference/development.md).
|
|
77
|
+
Dependencies install with pnpm, frozen to the lockfile, with a 7-day cooldown on new versions and an allowlist for install scripts: see [docs/reference/dependencies.md](docs/reference/dependencies.md) (it also covers adding a package that needs an install script and the override for an urgent security fix). A pre-commit hook checks formatting, secrets and banned terms on what is staged. Route handlers may not call `*Sync` functions, and git runs only through `lib/git-exec.ts`. More in [docs/reference/development.md](docs/reference/development.md).
|
|
78
78
|
|
|
79
79
|
## License
|
|
80
80
|
|
|
@@ -24,13 +24,50 @@ interface NpmVuln {
|
|
|
24
24
|
| { name?: string; version?: string; isSemVerMajor?: boolean };
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
interface PnpmAdvisory {
|
|
28
|
+
module_name?: string;
|
|
29
|
+
title?: string;
|
|
30
|
+
severity?: string;
|
|
31
|
+
patched_versions?: string | null;
|
|
32
|
+
findings?: { paths?: string[] }[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// pnpm audit lists advisories, not packages: one npm-style entry per module.
|
|
36
|
+
function fromAdvisories(
|
|
37
|
+
advisories: Record<string, PnpmAdvisory>
|
|
38
|
+
): Record<string, NpmVuln> {
|
|
39
|
+
const out: Record<string, NpmVuln> = {};
|
|
40
|
+
for (const a of Object.values(advisories)) {
|
|
41
|
+
const name = a.module_name ?? "";
|
|
42
|
+
if (!name) continue;
|
|
43
|
+
const paths = (a.findings ?? []).flatMap((f) => f.paths ?? []);
|
|
44
|
+
const prev = out[name];
|
|
45
|
+
const rank = (v?: string) => (v === "critical" ? 2 : v === "high" ? 1 : 0);
|
|
46
|
+
out[name] = {
|
|
47
|
+
severity:
|
|
48
|
+
rank(a.severity) >= rank(prev?.severity) ? a.severity : prev?.severity,
|
|
49
|
+
isDirect:
|
|
50
|
+
Boolean(prev?.isDirect) || paths.some((p) => /^\.>[^>]+$/.test(p)),
|
|
51
|
+
via: [...(prev?.via ?? []), a.title ?? ""],
|
|
52
|
+
fixAvailable: a.patched_versions
|
|
53
|
+
? { name, version: a.patched_versions }
|
|
54
|
+
: false,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
|
|
27
60
|
export function summarizeNpmAudit(json: unknown): NpmAuditSummary {
|
|
28
61
|
const data = (json ?? {}) as {
|
|
29
62
|
metadata?: { vulnerabilities?: Record<string, number> };
|
|
30
63
|
vulnerabilities?: Record<string, NpmVuln>;
|
|
64
|
+
advisories?: Record<string, PnpmAdvisory>;
|
|
31
65
|
};
|
|
32
66
|
const counts = { ...(data.metadata?.vulnerabilities ?? {}) };
|
|
33
|
-
const
|
|
67
|
+
const vulnerabilities = data.advisories
|
|
68
|
+
? fromAdvisories(data.advisories)
|
|
69
|
+
: (data.vulnerabilities ?? {});
|
|
70
|
+
const serious = Object.entries(vulnerabilities)
|
|
34
71
|
.filter(([, v]) => v.severity === "high" || v.severity === "critical")
|
|
35
72
|
.map(([name, v]) => {
|
|
36
73
|
const fix = v.fixAvailable;
|
|
@@ -16,7 +16,7 @@ const CODE = /\.(ts|tsx|mts|cts|js|mjs|cjs|jsx)$/;
|
|
|
16
16
|
const TEST = /(\.test\.|\.spec\.|(^|\/)__tests__\/|(^|\/)vitest\.setup\.)/;
|
|
17
17
|
// Generated, vendored or built: measured by other means or not ours.
|
|
18
18
|
const NOT_OURS =
|
|
19
|
-
/(^|\/)(node_modules|\.next[^/]*|dist|out|coverage|public
|
|
19
|
+
/(^|\/)(node_modules|\.deps|\.next[^/]*|dist|out|coverage|public)\/|\.min\.js$|(^|\/)next-env\.d\.ts$/;
|
|
20
20
|
|
|
21
21
|
export const isCode = (p: string) => CODE.test(p) && !NOT_OURS.test(p);
|
|
22
22
|
export const isTest = (p: string) => TEST.test(p);
|
|
@@ -20,12 +20,16 @@ export function spawnServer(opts: {
|
|
|
20
20
|
}): ChildProcess {
|
|
21
21
|
const { repo, port, env, stdio, detached, native } = opts;
|
|
22
22
|
assertNotLivePort(port, process.env, readLiveRecord());
|
|
23
|
-
const run = (script: string) =>
|
|
24
|
-
execFileSync(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const run = (script: string, ...args: string[]) =>
|
|
24
|
+
execFileSync(
|
|
25
|
+
process.execPath,
|
|
26
|
+
[path.join(repo, "scripts", script), ...args],
|
|
27
|
+
{
|
|
28
|
+
cwd: repo,
|
|
29
|
+
stdio: "ignore",
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
if (native) run("check-native.mjs", "--rebuild");
|
|
29
33
|
run("gen-migrations-index.mjs");
|
|
30
34
|
return spawn(process.execPath, ["--import", "tsx", "server.ts"], {
|
|
31
35
|
cwd: repo,
|
package/lib/doctor/checks.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { getAllProviderDefinitions } from "../providers/registry";
|
|
|
11
11
|
|
|
12
12
|
// The oldest Node major AgentOS runs on; scripts/lib/prerequisites.sh must agree
|
|
13
13
|
// (lib/doctor/drift.test.ts fails when they don't).
|
|
14
|
-
export const MIN_NODE_MAJOR =
|
|
14
|
+
export const MIN_NODE_MAJOR = 22;
|
|
15
15
|
|
|
16
16
|
const TOOL_MS = 5_000;
|
|
17
17
|
const CACHE_MS = 60 * 1000;
|
package/lib/env-setup.ts
CHANGED
|
@@ -22,6 +22,8 @@ export interface SetupStep {
|
|
|
22
22
|
success: boolean;
|
|
23
23
|
output?: string;
|
|
24
24
|
error?: string;
|
|
25
|
+
// The step worked, but the agent should know something about it.
|
|
26
|
+
warning?: string;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
// The stages a worktree's setup goes through, in order, for progress.
|
package/lib/files.ts
CHANGED
|
@@ -164,7 +164,7 @@ Acting:
|
|
|
164
164
|
|
|
165
165
|
The MCP servers this workspace allows (Settings → Workspaces) are yours to use through their own tools, for reading and for additive, reversible changes. Anything outbound through them (sending a message, an email, a post) is a hard line: park it with \`ask_saad\`.
|
|
166
166
|
|
|
167
|
-
Act through these tools, not the shell: they're scoped to this workspace and braked. ${full ? `The shell and your file writes are unchecked (Saad's decision, 2026-10-18: Orchestrator full access, switched in Settings → Workspaces): \`git push\`, \`gh pr merge\`, commits, \`stash\`, \`clean\`, edits in any project checkout or task worktree, AgentOS's own state, dotfiles, launch agents, .claude, CLAUDE.md, .mcp.json, hooks, \`sqlite3\` writes, \`aos sweep --arm\`, other workspaces' repositories. Use that to fix things directly instead of starting a task for every small job, but still prefer the tools for what they cover (they're scoped to this workspace and logged), and never use the shell to get around a hard line. One warning stays: never stop or restart AgentOS or its tmux; that ends every session it runs, this one included. If AgentOS itself needs a restart, \`ask_saad\`. Reading a secret file is allowed; its value is never printed, logged or sent off the machine. ` : `The shell runs anything without asking (Saad chose this on 2026-10-11), so use it to read and investigate yourself: \`gh pr list\`, \`gh run view --log-failed\`, \`gh api\` GETs, \`curl\`, \`sqlite3 -readonly\`, git in any repository, a skill's scripts, pipes and chains. Never use it to get around the tools. A deny list refuses, naming the tool to use instead: merging, closing or retargeting a PR (\`${TOOL_NAMES.sign_off}\`, \`${TOOL_NAMES.arm}\`, \`${TOOL_NAMES.land}\`, \`${TOOL_NAMES.drop}\`), \`git push\` (\`${TOOL_NAMES.quick_pr}\`), writing in a project repository or task worktree other than your own quick changes, except in a project checkout of your own workspace, where you may update and move the branch: \`git pull\` in any form, \`merge\`, \`reset\` (even \`--hard\`), \`checkout\`, \`switch\` and \`rebase\` (also as \`git -C <path>\`), then \`bundle install\`, \`npm install\` or \`bin/rails db:prepare\`. Commits, \`stash\`, \`clean\`, \`restore\` and file edits there still go through tasks and quick changes, and other workspaces' repositories, task worktrees and AgentOS's own live checkout (autodeploy deploys it) are refused for all of it are refused (\`${TOOL_NAMES.start_task}\`, \`${TOOL_NAMES.quick_change}\`), writing AgentOS's state (sqlite3 without \`-readonly\`, or files in ~/.agent-os outside your folder), stopping or restarting AgentOS or its tmux, and reading secret files (env files, keys, ~/.ssh, ~/.aws). `}Tokenvault is available through \`tv\`: use a token inside the command that needs it (e.g. \`FOO="\$(tv get <project> <desc>)" cmd\`), never print, echo or log a value, and never send one off the machine except to the service it's for. ${full ? `` : `The list catches honest mistakes, not a determined bypass: a script or \`python -c\` could do any of these unseen, and doing so would break Saad's trust in every gate. `}\`aos notify "<text>"\` pushes a message to Saad's phone. Use it for what he'd want to see now and asked for: the morning report, a real milestone (a stack landed, a blocker only he can clear). Never for routine status: one a minute at most, and he reads the rest here. ${full ? `You can read and write files anywhere (Read, Grep, Glob, Write, Edit, NotebookEdit); nothing is checked.` : `You can read files anywhere (Read, Grep, Glob), and write them (Write, Edit, NotebookEdit) anywhere except: a project repository or task worktree other than your own open quick changes' worktrees (start a task, or a quick change for a small edit, so the change goes through CI, review and scope), AgentOS's own state in ~/.agent-os outside your folder, secret files (.env, keys, ~/.ssh, ~/.aws, tokenvault and the like), and files that make something run: dotfiles and dot-folders at the top of your home (shell, git, Claude and tool config), ~/Library and /Library's launch agents, git's core.hooksPath folders, the folders on PATH, and any .git, .claude, .mcp.json, CLAUDE.md or AGENTS.md, which would hand you a shell or run code around the gates. Each write is checked before it runs, on the path with symlinks and \`..\` resolved; a refused one says why.`}
|
|
167
|
+
Act through these tools, not the shell: they're scoped to this workspace and braked. ${full ? `The shell and your file writes are unchecked (Saad's decision, 2026-10-18: Orchestrator full access, switched in Settings → Workspaces): \`git push\`, \`gh pr merge\`, commits, \`stash\`, \`clean\`, edits in any project checkout or task worktree, AgentOS's own state, dotfiles, launch agents, .claude, CLAUDE.md, .mcp.json, hooks, \`sqlite3\` writes, \`aos sweep --arm\`, other workspaces' repositories. Use that to fix things directly instead of starting a task for every small job, but still prefer the tools for what they cover (they're scoped to this workspace and logged), and never use the shell to get around a hard line. One warning stays: never stop or restart AgentOS or its tmux; that ends every session it runs, this one included. If AgentOS itself needs a restart, \`ask_saad\`. Reading a secret file is allowed; its value is never printed, logged or sent off the machine. ` : `The shell runs anything without asking (Saad chose this on 2026-10-11), so use it to read and investigate yourself: \`gh pr list\`, \`gh run view --log-failed\`, \`gh api\` GETs, \`curl\`, \`sqlite3 -readonly\`, git in any repository, a skill's scripts, pipes and chains. Never use it to get around the tools. A deny list refuses, naming the tool to use instead: merging, closing or retargeting a PR (\`${TOOL_NAMES.sign_off}\`, \`${TOOL_NAMES.arm}\`, \`${TOOL_NAMES.land}\`, \`${TOOL_NAMES.drop}\`), \`git push\` (\`${TOOL_NAMES.quick_pr}\`), writing in a project repository or task worktree other than your own quick changes, except in a project checkout of your own workspace, where you may update and move the branch: \`git pull\` in any form, \`merge\`, \`reset\` (even \`--hard\`), \`checkout\`, \`switch\` and \`rebase\` (also as \`git -C <path>\`), then \`bundle install\`, \`npm install\`, \`pnpm install\` or \`bin/rails db:prepare\`. Commits, \`stash\`, \`clean\`, \`restore\` and file edits there still go through tasks and quick changes, and other workspaces' repositories, task worktrees and AgentOS's own live checkout (autodeploy deploys it) are refused for all of it are refused (\`${TOOL_NAMES.start_task}\`, \`${TOOL_NAMES.quick_change}\`), writing AgentOS's state (sqlite3 without \`-readonly\`, or files in ~/.agent-os outside your folder), stopping or restarting AgentOS or its tmux, and reading secret files (env files, keys, ~/.ssh, ~/.aws). `}Tokenvault is available through \`tv\`: use a token inside the command that needs it (e.g. \`FOO="\$(tv get <project> <desc>)" cmd\`), never print, echo or log a value, and never send one off the machine except to the service it's for. ${full ? `` : `The list catches honest mistakes, not a determined bypass: a script or \`python -c\` could do any of these unseen, and doing so would break Saad's trust in every gate. `}\`aos notify "<text>"\` pushes a message to Saad's phone. Use it for what he'd want to see now and asked for: the morning report, a real milestone (a stack landed, a blocker only he can clear). Never for routine status: one a minute at most, and he reads the rest here. ${full ? `You can read and write files anywhere (Read, Grep, Glob, Write, Edit, NotebookEdit); nothing is checked.` : `You can read files anywhere (Read, Grep, Glob), and write them (Write, Edit, NotebookEdit) anywhere except: a project repository or task worktree other than your own open quick changes' worktrees (start a task, or a quick change for a small edit, so the change goes through CI, review and scope), AgentOS's own state in ~/.agent-os outside your folder, secret files (.env, keys, ~/.ssh, ~/.aws, tokenvault and the like), and files that make something run: dotfiles and dot-folders at the top of your home (shell, git, Claude and tool config), ~/Library and /Library's launch agents, git's core.hooksPath folders, the folders on PATH, and any .git, .claude, .mcp.json, CLAUDE.md or AGENTS.md, which would hand you a shell or run code around the gates. Each write is checked before it runs, on the path with symlinks and \`..\` resolved; a refused one says why.`}
|
|
168
168
|
|
|
169
169
|
## Untrusted text
|
|
170
170
|
|
package/lib/share/pdf.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import fs from "fs";
|
|
9
|
+
import path from "path";
|
|
9
10
|
import type { Browser, LaunchOptions } from "playwright";
|
|
10
11
|
|
|
11
12
|
const IDLE_MS = 60_000;
|
|
@@ -32,13 +33,43 @@ h1,h2,h3,h4{break-after:avoid}
|
|
|
32
33
|
img{max-width:100%;break-inside:avoid}
|
|
33
34
|
`;
|
|
34
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Playwright's headless shell, which `playwright install
|
|
38
|
+
* chromium-headless-shell` puts beside the full Chromium (same cache folder,
|
|
39
|
+
* the revision the locked package names). Null when it isn't installed.
|
|
40
|
+
*/
|
|
41
|
+
export function headlessShellPath(chromiumExecutable: string): string | null {
|
|
42
|
+
// <cache>/chromium-<rev>/<platform>/...: the shell's folder has the same <rev>.
|
|
43
|
+
const m = /^(.*)[\\/]chromium-(\d+)[\\/]/.exec(chromiumExecutable);
|
|
44
|
+
if (!m) return null;
|
|
45
|
+
const folder = path.join(m[1], `chromium_headless_shell-${m[2]}`);
|
|
46
|
+
let platform: string | undefined;
|
|
47
|
+
try {
|
|
48
|
+
platform = fs
|
|
49
|
+
.readdirSync(folder)
|
|
50
|
+
.find((d) => d.startsWith("chrome-headless-shell-"));
|
|
51
|
+
} catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
if (!platform) return null;
|
|
55
|
+
const exe = path.join(
|
|
56
|
+
folder,
|
|
57
|
+
platform,
|
|
58
|
+
process.platform === "win32"
|
|
59
|
+
? "chrome-headless-shell.exe"
|
|
60
|
+
: "chrome-headless-shell"
|
|
61
|
+
);
|
|
62
|
+
return fs.existsSync(exe) ? exe : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
35
65
|
let found: LaunchOptions | null | undefined;
|
|
36
66
|
|
|
37
67
|
/** How to launch a browser on this machine, or null when there is none. */
|
|
38
68
|
export async function findBrowser(): Promise<LaunchOptions | null> {
|
|
39
69
|
if (found !== undefined) return found;
|
|
40
70
|
const { chromium } = await import("playwright");
|
|
41
|
-
const
|
|
71
|
+
const full = chromium.executablePath();
|
|
72
|
+
const candidates = [headlessShellPath(full), full, ...CHROME_PATHS];
|
|
42
73
|
const path = candidates.find((p) => p && fs.existsSync(p));
|
|
43
74
|
found = path ? { executablePath: path, headless: true } : null;
|
|
44
75
|
return found;
|
package/lib/tasks/setup.ts
CHANGED
|
@@ -20,8 +20,10 @@ const tail = (s: string, n: number) => (s.length > n ? `...${s.slice(-n)}` : s);
|
|
|
20
20
|
export function setupOutcome(result: SetupResult | Error): TaskSetup {
|
|
21
21
|
if (result instanceof Error)
|
|
22
22
|
return { status: "failed", ms: null, error: redact(result.message) };
|
|
23
|
-
if (result.success)
|
|
24
|
-
|
|
23
|
+
if (result.success) {
|
|
24
|
+
const warning = result.steps.find((s) => s.warning)?.warning;
|
|
25
|
+
return { status: "ok", ms: result.durationMs, error: warning ?? null };
|
|
26
|
+
}
|
|
25
27
|
const failed = result.steps.filter((s) => !s.success);
|
|
26
28
|
const last = failed[failed.length - 1];
|
|
27
29
|
const error = last
|
|
@@ -31,6 +33,11 @@ export function setupOutcome(result: SetupResult | Error): TaskSetup {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export function setupNote(setup: TaskSetup): string {
|
|
36
|
+
if (setup.status === "ok" && setup.error)
|
|
37
|
+
return `
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
Note from AgentOS: ${setup.error}`;
|
|
34
41
|
if (setup.status !== "failed") return "";
|
|
35
42
|
return `
|
|
36
43
|
|
|
@@ -236,6 +236,16 @@ export async function cloneDeps(opts: {
|
|
|
236
236
|
// not, and cloning it would hand the worktree missing dependencies. Other
|
|
237
237
|
// package managers have no hidden lockfile to check, so they pass.
|
|
238
238
|
export async function nodeModulesMatchLock(dir: string): Promise<boolean> {
|
|
239
|
+
// pnpm copies the lockfile it installed from into node_modules/.pnpm.
|
|
240
|
+
const pnpmLock = await fs.promises
|
|
241
|
+
.readFile(path.join(dir, "pnpm-lock.yaml"), "utf-8")
|
|
242
|
+
.catch(() => null);
|
|
243
|
+
if (pnpmLock !== null) {
|
|
244
|
+
const installed = await fs.promises
|
|
245
|
+
.readFile(path.join(dir, "node_modules", ".pnpm", "lock.yaml"), "utf-8")
|
|
246
|
+
.catch(() => null);
|
|
247
|
+
return installed === pnpmLock;
|
|
248
|
+
}
|
|
239
249
|
const read = (file: string) =>
|
|
240
250
|
fs.promises
|
|
241
251
|
.readFile(file, "utf-8")
|
|
@@ -22,7 +22,14 @@ export const STORE_ROOT = agentosHome("deps-store");
|
|
|
22
22
|
|
|
23
23
|
// Files tools rewrite in place. A hardlink would carry the write back into
|
|
24
24
|
// the store, so these are real copies in every worktree.
|
|
25
|
-
export const MUTABLE_IN_MODULES = [
|
|
25
|
+
export const MUTABLE_IN_MODULES = [
|
|
26
|
+
".package-lock.json",
|
|
27
|
+
".modules.yaml",
|
|
28
|
+
".pnpm/lock.yaml",
|
|
29
|
+
".pnpm-workspace-state-v1.json",
|
|
30
|
+
".cache",
|
|
31
|
+
".vite",
|
|
32
|
+
];
|
|
26
33
|
|
|
27
34
|
const probed = new Map<string, boolean>();
|
|
28
35
|
|
|
@@ -7,7 +7,7 @@ import { exec } from "child_process";
|
|
|
7
7
|
import { promisify } from "util";
|
|
8
8
|
import type { SetupResult } from "../env-setup";
|
|
9
9
|
import { NO_FAST_COPY, cloneDeps } from "./clone";
|
|
10
|
-
import { detectPackageManager, setupEnv } from "./install";
|
|
10
|
+
import { detectPackageManager, setupEnv, shellCommand } from "./install";
|
|
11
11
|
|
|
12
12
|
const execAsync = promisify(exec);
|
|
13
13
|
|
|
@@ -47,8 +47,8 @@ export async function runCommand(
|
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Clone the main checkout's node_modules (or exactly agentos.json's `clone`
|
|
50
|
-
* paths), or else install: the lockfile's frozen install first, then
|
|
51
|
-
* plain one.
|
|
50
|
+
* paths), or else install: the lockfile's frozen install first, then (for
|
|
51
|
+
* a project other than AgentOS) a plain one.
|
|
52
52
|
*/
|
|
53
53
|
export async function bringDependencies(
|
|
54
54
|
result: SetupResult,
|
|
@@ -81,20 +81,15 @@ export async function bringDependencies(
|
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
96
|
-
if (run.success) return;
|
|
97
|
-
error = run.error;
|
|
98
|
-
}
|
|
99
|
-
if (error !== undefined) result.success = false;
|
|
84
|
+
const run = await deps.run(shellCommand(pm.install), worktreePath, envVars);
|
|
85
|
+
result.steps.push({
|
|
86
|
+
name: `Install dependencies (${pm.name})`,
|
|
87
|
+
command: pm.install,
|
|
88
|
+
success: run.success,
|
|
89
|
+
output: [clone.reason && `Not cloned: ${clone.reason}`, run.output]
|
|
90
|
+
.filter(Boolean)
|
|
91
|
+
.join("\n"),
|
|
92
|
+
error: run.error,
|
|
93
|
+
});
|
|
94
|
+
if (!run.success) result.success = false;
|
|
100
95
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Installing a worktree's dependencies when they can't be cloned: the
|
|
3
|
-
* lockfile's own frozen install
|
|
3
|
+
* lockfile's own frozen install, and nothing else. A plain install would
|
|
4
|
+
* resolve ranges to versions newer than the lockfile, so a lockfile that
|
|
5
|
+
* disagrees with package.json fails setup and the agent is told.
|
|
4
6
|
*/
|
|
5
7
|
|
|
6
8
|
import * as fs from "fs";
|
|
@@ -8,8 +10,7 @@ import * as path from "path";
|
|
|
8
10
|
|
|
9
11
|
export interface PackageManager {
|
|
10
12
|
name: "bun" | "pnpm" | "yarn" | "npm";
|
|
11
|
-
|
|
12
|
-
installs: string[];
|
|
13
|
+
install: string;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
// Each install includes devDependencies: the agent needs typecheck, tests
|
|
@@ -17,44 +18,29 @@ export interface PackageManager {
|
|
|
17
18
|
const BY_LOCKFILE: Array<{ file: string; pm: PackageManager }> = [
|
|
18
19
|
{
|
|
19
20
|
file: "bun.lock",
|
|
20
|
-
pm: {
|
|
21
|
-
name: "bun",
|
|
22
|
-
installs: ["bun install --frozen-lockfile", "bun install"],
|
|
23
|
-
},
|
|
21
|
+
pm: { name: "bun", install: "bun install --frozen-lockfile" },
|
|
24
22
|
},
|
|
25
23
|
{
|
|
26
24
|
file: "bun.lockb",
|
|
27
|
-
pm: {
|
|
28
|
-
name: "bun",
|
|
29
|
-
installs: ["bun install --frozen-lockfile", "bun install"],
|
|
30
|
-
},
|
|
25
|
+
pm: { name: "bun", install: "bun install --frozen-lockfile" },
|
|
31
26
|
},
|
|
32
27
|
{
|
|
33
28
|
file: "pnpm-lock.yaml",
|
|
34
29
|
pm: {
|
|
35
30
|
name: "pnpm",
|
|
36
|
-
|
|
37
|
-
"pnpm install --frozen-lockfile --prod=false",
|
|
38
|
-
"pnpm install --prod=false",
|
|
39
|
-
],
|
|
31
|
+
install: "pnpm install --frozen-lockfile --prod=false",
|
|
40
32
|
},
|
|
41
33
|
},
|
|
42
34
|
{
|
|
43
35
|
file: "yarn.lock",
|
|
44
36
|
pm: {
|
|
45
37
|
name: "yarn",
|
|
46
|
-
|
|
47
|
-
"yarn install --frozen-lockfile --production=false",
|
|
48
|
-
"yarn install --production=false",
|
|
49
|
-
],
|
|
38
|
+
install: "yarn install --frozen-lockfile --production=false",
|
|
50
39
|
},
|
|
51
40
|
},
|
|
52
41
|
{
|
|
53
42
|
file: "package-lock.json",
|
|
54
|
-
pm: {
|
|
55
|
-
name: "npm",
|
|
56
|
-
installs: ["npm ci --include=dev", "npm install --include=dev"],
|
|
57
|
-
},
|
|
43
|
+
pm: { name: "npm", install: "npm ci --include=dev" },
|
|
58
44
|
},
|
|
59
45
|
];
|
|
60
46
|
|
|
@@ -68,11 +54,18 @@ export function detectPackageManager(
|
|
|
68
54
|
}
|
|
69
55
|
if (fs.existsSync(path.join(projectPath, "package.json"))) {
|
|
70
56
|
// No lockfile, so nothing to be frozen to.
|
|
71
|
-
return { name: "npm",
|
|
57
|
+
return { name: "npm", install: "npm install --include=dev" };
|
|
72
58
|
}
|
|
73
59
|
return null;
|
|
74
60
|
}
|
|
75
61
|
|
|
62
|
+
// pnpm may exist only as a corepack shim that was never enabled; the shell
|
|
63
|
+
// defines `pnpm` through corepack when the command is missing.
|
|
64
|
+
export function shellCommand(command: string): string {
|
|
65
|
+
if (!command.startsWith("pnpm ")) return command;
|
|
66
|
+
return `if ! command -v pnpm >/dev/null 2>&1; then pnpm() { COREPACK_ENABLE_DOWNLOAD_PROMPT=0 corepack pnpm "$@"; }; fi; ${command}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
76
69
|
// What setup commands run under: the server's environment without the
|
|
77
70
|
// settings that make an install skip devDependencies.
|
|
78
71
|
export function setupEnv(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saadnvd1/agent-os",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.684",
|
|
4
4
|
"description": "Self-hosted web UI for managing Claude Code sessions",
|
|
5
5
|
"bin": {
|
|
6
6
|
"agent-os": "scripts/agent-os"
|
|
@@ -24,29 +24,24 @@
|
|
|
24
24
|
"tsconfig.json",
|
|
25
25
|
"postcss.config.mjs",
|
|
26
26
|
"tailwind.config.ts",
|
|
27
|
-
"package-lock.json",
|
|
28
27
|
"README.md",
|
|
29
28
|
"LICENSE"
|
|
30
29
|
],
|
|
31
30
|
"scripts": {
|
|
32
|
-
"predev": "node scripts/
|
|
31
|
+
"predev": "node scripts/check-native.mjs --rebuild && node scripts/gen-migrations-index.mjs",
|
|
33
32
|
"dev": "AGENTOS_DEV=1 tsx server.ts",
|
|
34
33
|
"dev:task": "tsx scripts/dev-task.ts",
|
|
35
34
|
"dev:stop": "tsx scripts/dev-stop.ts",
|
|
36
35
|
"disk:dry-run": "tsx scripts/disk-dry-run.ts",
|
|
37
36
|
"prebuild": "node scripts/gen-migrations-index.mjs",
|
|
38
37
|
"build": "next build",
|
|
39
|
-
"prestart": "node scripts/
|
|
38
|
+
"prestart": "node scripts/check-native.mjs --rebuild && node scripts/gen-migrations-index.mjs",
|
|
40
39
|
"start": "NODE_ENV=production AGENTOS_SERVER=live node --import tsx server.ts",
|
|
41
40
|
"pretypecheck": "node scripts/gen-migrations-index.mjs",
|
|
42
41
|
"typecheck": "tsc --noEmit",
|
|
43
42
|
"setup": "bash scripts/setup.sh",
|
|
44
43
|
"postinstall": "chmod +x node_modules/node-pty/prebuilds/*/spawn-helper 2>/dev/null || true",
|
|
45
44
|
"prepare": "husky",
|
|
46
|
-
"tauri": "tauri",
|
|
47
|
-
"tauri:dev": "tauri dev",
|
|
48
|
-
"tauri:build": "tauri build",
|
|
49
|
-
"tauri:build:linux": "docker build -t agentos-linux -f src-tauri/Dockerfile.linux src-tauri && docker run --rm -v $(pwd)/src-tauri/target:/app/target agentos-linux",
|
|
50
45
|
"prelint": "node scripts/gen-migrations-index.mjs",
|
|
51
46
|
"lint": "eslint .",
|
|
52
47
|
"format": "prettier --write .",
|
|
@@ -71,7 +66,7 @@
|
|
|
71
66
|
"author": "Saad Naveed",
|
|
72
67
|
"license": "MIT",
|
|
73
68
|
"engines": {
|
|
74
|
-
"node": ">=
|
|
69
|
+
"node": ">=22"
|
|
75
70
|
},
|
|
76
71
|
"bugs": {
|
|
77
72
|
"url": "https://github.com/saadnvd1/agent-os/issues"
|
|
@@ -155,15 +150,15 @@
|
|
|
155
150
|
"serwist": "^9.5.7",
|
|
156
151
|
"sonner": "^2.0.7",
|
|
157
152
|
"tailwind-merge": "^3.4.0",
|
|
153
|
+
"unified": "^11.0.5",
|
|
158
154
|
"valtio": "^2.3.0",
|
|
159
155
|
"ws": "^8.19.0",
|
|
160
156
|
"zod": "^4.6.5"
|
|
161
157
|
},
|
|
162
158
|
"devDependencies": {
|
|
163
159
|
"@tailwindcss/postcss": "^4.1.18",
|
|
164
|
-
"@tauri-apps/api": "^2.12.1",
|
|
165
|
-
"@tauri-apps/cli": "^2.12.1",
|
|
166
160
|
"@types/better-sqlite3": "^7.6.13",
|
|
161
|
+
"@types/hast": "^3.0.4",
|
|
167
162
|
"@types/jsdom": "^30.0.0",
|
|
168
163
|
"@types/mdast": "^4.0.4",
|
|
169
164
|
"@types/node": "^20.19.27",
|
|
@@ -177,6 +172,7 @@
|
|
|
177
172
|
"jsdom": "^30.1.2",
|
|
178
173
|
"prettier": "^3.7.4",
|
|
179
174
|
"prettier-plugin-tailwindcss": "^0.7.2",
|
|
175
|
+
"remark-parse": "^11.0.0",
|
|
180
176
|
"sharp": "^0.35.5",
|
|
181
177
|
"tailwindcss": "^4.1.18",
|
|
182
178
|
"tsx": "^4.23.15",
|
|
@@ -184,8 +180,5 @@
|
|
|
184
180
|
"typescript": "^5.9.3",
|
|
185
181
|
"vitest": "^4.1.11"
|
|
186
182
|
},
|
|
187
|
-
"
|
|
188
|
-
"dompurify": "^3.4.16",
|
|
189
|
-
"postcss-selector-parser": "^7.1.6"
|
|
190
|
-
}
|
|
183
|
+
"packageManager": "pnpm@11.28.5+sha512.484563d30b4c2ad27cb48aa94ff2b302dbcebc8ff6bf28816c2589886e146ce7f76f354f3bc1a438e6f5e9768c302aa0a6f7add8232903cd4cf81426cbc14d9e"
|
|
191
184
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Proves the native modules work in a node_modules tree: open a SQLite
|
|
2
|
+
// database with better-sqlite3 and spawn a pty with node-pty. Used before a
|
|
3
|
+
// deploy swaps an install in, and by predev/prestart.
|
|
4
|
+
// node scripts/check-native.mjs [node_modules dir] (default: this checkout's)
|
|
5
|
+
// --rebuild on a Node ABI mismatch, run `pnpm rebuild` once and check again
|
|
6
|
+
import { createRequire } from "module";
|
|
7
|
+
import { execFileSync } from "child_process";
|
|
8
|
+
import fs from "fs";
|
|
9
|
+
import os from "os";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
12
|
+
|
|
13
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
const rebuild = args.includes("--rebuild");
|
|
16
|
+
const modules = path.resolve(
|
|
17
|
+
args.find((a) => !a.startsWith("--")) ?? path.join(here, "..", "node_modules")
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
async function sqlite(require) {
|
|
21
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "aos-native-"));
|
|
22
|
+
try {
|
|
23
|
+
const db = require("better-sqlite3")(path.join(dir, "check.db"));
|
|
24
|
+
db.exec("create table t (v text); insert into t values ('ok')");
|
|
25
|
+
const row = db.prepare("select v from t").get();
|
|
26
|
+
db.close();
|
|
27
|
+
if (row?.v !== "ok") throw new Error("better-sqlite3 read back nothing");
|
|
28
|
+
} finally {
|
|
29
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function pty(require) {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const p = require("node-pty").spawn("/bin/sh", ["-c", "echo pty-ok"], {});
|
|
36
|
+
let out = "";
|
|
37
|
+
const timer = setTimeout(() => {
|
|
38
|
+
p.kill();
|
|
39
|
+
reject(new Error("node-pty: no exit within 10s"));
|
|
40
|
+
}, 10_000);
|
|
41
|
+
p.onData((d) => (out += d));
|
|
42
|
+
p.onExit(({ exitCode }) => {
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
if (exitCode === 0 && out.includes("pty-ok")) resolve();
|
|
45
|
+
else reject(new Error(`node-pty: exit ${exitCode}, output ${out}`));
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function failures() {
|
|
51
|
+
const require = createRequire(path.join(modules, "noop.js"));
|
|
52
|
+
const found = [];
|
|
53
|
+
for (const [name, run] of [
|
|
54
|
+
["better-sqlite3", sqlite],
|
|
55
|
+
["node-pty", pty],
|
|
56
|
+
]) {
|
|
57
|
+
try {
|
|
58
|
+
await run(require);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
found.push({ name, message: String(err?.message ?? err) });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let bad = await failures();
|
|
67
|
+
if (
|
|
68
|
+
bad.length &&
|
|
69
|
+
rebuild &&
|
|
70
|
+
bad.some((b) => b.message.includes("NODE_MODULE_VERSION"))
|
|
71
|
+
) {
|
|
72
|
+
const names = bad.map((b) => b.name);
|
|
73
|
+
console.log(`Rebuilding ${names.join(", ")} for Node ${process.version}...`);
|
|
74
|
+
execFileSync("pnpm", ["rebuild", ...names], {
|
|
75
|
+
cwd: path.dirname(modules),
|
|
76
|
+
stdio: "inherit",
|
|
77
|
+
});
|
|
78
|
+
bad = await failures();
|
|
79
|
+
}
|
|
80
|
+
if (bad.length) {
|
|
81
|
+
for (const b of bad)
|
|
82
|
+
console.error(`native check failed: ${b.name}: ${b.message}`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
console.log(`native modules ok (${modules})`);
|
|
86
|
+
process.exit(0);
|
|
@@ -142,11 +142,11 @@ async function prepass(args: string[]) {
|
|
|
142
142
|
const steps: Record<Collector, () => string | void> = {
|
|
143
143
|
deps: () => {
|
|
144
144
|
const prod = JSON.parse(
|
|
145
|
-
run("
|
|
145
|
+
run("pnpm", ["audit", "--prod", "--json"], root) || "{}"
|
|
146
146
|
);
|
|
147
|
-
const all = JSON.parse(run("
|
|
147
|
+
const all = JSON.parse(run("pnpm", ["audit", "--json"], root) || "{}");
|
|
148
148
|
const outdated = JSON.parse(
|
|
149
|
-
run("
|
|
149
|
+
run("pnpm", ["outdated", "--format", "json"], root) || "{}"
|
|
150
150
|
);
|
|
151
151
|
result.deps = {
|
|
152
152
|
prod: summarizeNpmAudit(prod),
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Install this checkout's dependencies the one way AgentOS does: pnpm, frozen
|
|
3
|
+
# to pnpm-lock.yaml, only the build scripts pnpm-workspace.yaml allows, then a
|
|
4
|
+
# check that the native modules work and the PDF browser. For first installs
|
|
5
|
+
# (setup, `agent-os install`); a running server's updates go through
|
|
6
|
+
# scripts/redeploy, which installs beside the live tree.
|
|
7
|
+
# scripts/install-deps [--no-browser]
|
|
8
|
+
set -euo pipefail
|
|
9
|
+
cd "$(dirname "$0")/.."
|
|
10
|
+
# shellcheck source=lib/pnpm.sh
|
|
11
|
+
source scripts/lib/pnpm.sh
|
|
12
|
+
|
|
13
|
+
if [ -s "$HOME/.nvm/nvm.sh" ]; then
|
|
14
|
+
# shellcheck disable=SC1091
|
|
15
|
+
source "$HOME/.nvm/nvm.sh" >/dev/null
|
|
16
|
+
nvm use >/dev/null
|
|
17
|
+
fi
|
|
18
|
+
use_pnpm
|
|
19
|
+
|
|
20
|
+
# devDependencies are needed to build, even when the shell has NODE_ENV=production.
|
|
21
|
+
unset NODE_ENV npm_config_production npm_config_omit
|
|
22
|
+
pnpm install --frozen-lockfile
|
|
23
|
+
node scripts/check-native.mjs
|
|
24
|
+
[ "${1:-}" = "--no-browser" ] || install_pdf_browser
|
package/scripts/lib/commands.sh
CHANGED
|
@@ -43,7 +43,7 @@ cmd_install() {
|
|
|
43
43
|
|
|
44
44
|
# Install dependencies
|
|
45
45
|
log_info "Installing dependencies..."
|
|
46
|
-
|
|
46
|
+
scripts/install-deps
|
|
47
47
|
|
|
48
48
|
# Build for production
|
|
49
49
|
log_info "Building for production..."
|
|
@@ -296,7 +296,7 @@ cmd_update() {
|
|
|
296
296
|
git pull --ff-only
|
|
297
297
|
|
|
298
298
|
log_info "Installing dependencies..."
|
|
299
|
-
|
|
299
|
+
scripts/install-deps
|
|
300
300
|
|
|
301
301
|
log_info "Rebuilding..."
|
|
302
302
|
npm run build
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Install dependencies beside the live ones, prove the native modules work in
|
|
3
|
+
# them, and only then swap them in. A deploy that brings a broken install
|
|
4
|
+
# fails here, and the node_modules the running server reads is never touched.
|
|
5
|
+
# The tree being replaced stays in .deps/prev for one rollback.
|
|
6
|
+
# Sourced by scripts/redeploy; run from the repository root, after use_pnpm.
|
|
7
|
+
# Test hooks: AGENTOS_INSTALL_CMD (default `pnpm install --frozen-lockfile`),
|
|
8
|
+
# AGENTOS_NATIVE_CHECK (default `node scripts/check-native.mjs <dir>`).
|
|
9
|
+
|
|
10
|
+
DEPS=.deps
|
|
11
|
+
STAGE=$DEPS/stage
|
|
12
|
+
PREV=$DEPS/prev
|
|
13
|
+
STAMP=.agentos-deps
|
|
14
|
+
|
|
15
|
+
# What an install depends on. A new Node or CPU rebuilds the native modules.
|
|
16
|
+
deps_stamp() {
|
|
17
|
+
{
|
|
18
|
+
cat package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc 2>/dev/null
|
|
19
|
+
node -p 'process.version + process.platform + process.arch'
|
|
20
|
+
} | shasum -a 256 | cut -d' ' -f1
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
# 0 and a staged tree to swap in, or 10 when the live install is already
|
|
24
|
+
# right, or 1 with the live tree untouched.
|
|
25
|
+
install_beside() {
|
|
26
|
+
local stamp
|
|
27
|
+
stamp=$(deps_stamp)
|
|
28
|
+
if [ -d node_modules ] && [ "$(cat "node_modules/$STAMP" 2>/dev/null)" = "$stamp" ]; then
|
|
29
|
+
echo "Dependencies unchanged."
|
|
30
|
+
# The last build ran on these same dependencies, so a rollback has
|
|
31
|
+
# nothing to put back.
|
|
32
|
+
rm -rf "$PREV"
|
|
33
|
+
return 10
|
|
34
|
+
fi
|
|
35
|
+
rm -rf "$STAGE"
|
|
36
|
+
mkdir -p "$STAGE"
|
|
37
|
+
cp package.json pnpm-lock.yaml pnpm-workspace.yaml "$STAGE/"
|
|
38
|
+
[ -f .npmrc ] && cp .npmrc "$STAGE/"
|
|
39
|
+
# HUSKY=0: the staged copy is not a git checkout.
|
|
40
|
+
if ! (cd "$STAGE" && HUSKY=0 bash -c "${AGENTOS_INSTALL_CMD:-pnpm install --frozen-lockfile}"); then
|
|
41
|
+
rm -rf "$STAGE"
|
|
42
|
+
echo "Install failed; the live node_modules is untouched." >&2
|
|
43
|
+
return 1
|
|
44
|
+
fi
|
|
45
|
+
if ! bash -c "${AGENTOS_NATIVE_CHECK:-node scripts/check-native.mjs \"\$1\"}" _ "$STAGE/node_modules"; then
|
|
46
|
+
rm -rf "$STAGE"
|
|
47
|
+
echo "Native modules do not load in the new install; the live node_modules is untouched." >&2
|
|
48
|
+
return 1
|
|
49
|
+
fi
|
|
50
|
+
echo "$stamp" > "$STAGE/node_modules/$STAMP"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
swap_deps() {
|
|
54
|
+
[ -d "$STAGE/node_modules" ] || { echo "no checked install to swap in" >&2; return 1; }
|
|
55
|
+
rm -rf "$PREV"
|
|
56
|
+
mkdir -p "$DEPS"
|
|
57
|
+
[ -d node_modules ] && mv node_modules "$PREV"
|
|
58
|
+
mv "$STAGE/node_modules" node_modules
|
|
59
|
+
rm -rf "$STAGE"
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
# Put the node_modules from before the last swap back (a failed build, or
|
|
63
|
+
# `redeploy --rollback`); the current one is dropped.
|
|
64
|
+
restore_deps() {
|
|
65
|
+
[ -d "$PREV" ] || return 0
|
|
66
|
+
rm -rf node_modules
|
|
67
|
+
mv "$PREV" node_modules
|
|
68
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
rmSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
} from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
11
|
+
import { tempDir } from "@/lib/test-temp";
|
|
12
|
+
|
|
13
|
+
const LIB = join(import.meta.dirname, "deps-swap.sh");
|
|
14
|
+
|
|
15
|
+
let dir: string;
|
|
16
|
+
const read = (p: string) => readFileSync(join(dir, p), "utf8");
|
|
17
|
+
|
|
18
|
+
// Runs the library's functions in `dir` with a fake install and native check.
|
|
19
|
+
function run(script: string, env: Record<string, string> = {}) {
|
|
20
|
+
return spawnSync("bash", ["-c", `source "${LIB}"; ${script}`], {
|
|
21
|
+
cwd: dir,
|
|
22
|
+
encoding: "utf8",
|
|
23
|
+
env: { ...process.env, ...env },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const INSTALL = "mkdir -p node_modules && echo new > node_modules/marker";
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
dir = tempDir("deps-swap-");
|
|
31
|
+
for (const f of ["package.json", "pnpm-lock.yaml", "pnpm-workspace.yaml"])
|
|
32
|
+
writeFileSync(join(dir, f), `{}\n`);
|
|
33
|
+
mkdirSync(join(dir, "node_modules"));
|
|
34
|
+
writeFileSync(join(dir, "node_modules/marker"), "old\n");
|
|
35
|
+
});
|
|
36
|
+
afterEach(() => rmSync(dir, { recursive: true, force: true }));
|
|
37
|
+
|
|
38
|
+
describe("install_beside", () => {
|
|
39
|
+
it("installs beside, checks, and swaps in; the old tree is kept for a rollback", () => {
|
|
40
|
+
const r = run("install_beside && swap_deps", {
|
|
41
|
+
AGENTOS_INSTALL_CMD: INSTALL,
|
|
42
|
+
AGENTOS_NATIVE_CHECK: "true",
|
|
43
|
+
});
|
|
44
|
+
expect(r.status).toBe(0);
|
|
45
|
+
expect(read("node_modules/marker")).toBe("new\n");
|
|
46
|
+
expect(read(".deps/prev/marker")).toBe("old\n");
|
|
47
|
+
expect(existsSync(join(dir, ".deps/stage"))).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("leaves the live node_modules alone when the native check fails", () => {
|
|
51
|
+
const r = run("install_beside", {
|
|
52
|
+
AGENTOS_INSTALL_CMD: INSTALL,
|
|
53
|
+
AGENTOS_NATIVE_CHECK: "exit 1",
|
|
54
|
+
});
|
|
55
|
+
expect(r.status).toBe(1);
|
|
56
|
+
expect(r.stderr).toContain("Native modules do not load");
|
|
57
|
+
expect(read("node_modules/marker")).toBe("old\n");
|
|
58
|
+
expect(existsSync(join(dir, ".deps/stage"))).toBe(false);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("leaves the live node_modules alone when the install fails", () => {
|
|
62
|
+
const r = run("install_beside", {
|
|
63
|
+
AGENTOS_INSTALL_CMD: "exit 3",
|
|
64
|
+
AGENTOS_NATIVE_CHECK: "true",
|
|
65
|
+
});
|
|
66
|
+
expect(r.status).toBe(1);
|
|
67
|
+
expect(read("node_modules/marker")).toBe("old\n");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("skips the install when nothing it depends on changed", () => {
|
|
71
|
+
const first = run("install_beside && swap_deps", {
|
|
72
|
+
AGENTOS_INSTALL_CMD: INSTALL,
|
|
73
|
+
AGENTOS_NATIVE_CHECK: "true",
|
|
74
|
+
});
|
|
75
|
+
expect(first.status).toBe(0);
|
|
76
|
+
const again = run("install_beside", {
|
|
77
|
+
AGENTOS_INSTALL_CMD: "exit 9",
|
|
78
|
+
AGENTOS_NATIVE_CHECK: "exit 9",
|
|
79
|
+
});
|
|
80
|
+
expect(again.status).toBe(10);
|
|
81
|
+
// A rollback has nothing to restore: the last build used these same deps.
|
|
82
|
+
expect(existsSync(join(dir, ".deps/prev"))).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("installs again when the lockfile changes", () => {
|
|
86
|
+
run("install_beside && swap_deps", {
|
|
87
|
+
AGENTOS_INSTALL_CMD: INSTALL,
|
|
88
|
+
AGENTOS_NATIVE_CHECK: "true",
|
|
89
|
+
});
|
|
90
|
+
writeFileSync(join(dir, "pnpm-lock.yaml"), "changed\n");
|
|
91
|
+
const r = run("install_beside", {
|
|
92
|
+
AGENTOS_INSTALL_CMD: INSTALL,
|
|
93
|
+
AGENTOS_NATIVE_CHECK: "true",
|
|
94
|
+
});
|
|
95
|
+
expect(r.status).toBe(0);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("restore_deps", () => {
|
|
100
|
+
it("puts the previous node_modules back after a swap", () => {
|
|
101
|
+
run("install_beside && swap_deps && restore_deps", {
|
|
102
|
+
AGENTOS_INSTALL_CMD: INSTALL,
|
|
103
|
+
AGENTOS_NATIVE_CHECK: "true",
|
|
104
|
+
});
|
|
105
|
+
expect(read("node_modules/marker")).toBe("old\n");
|
|
106
|
+
expect(existsSync(join(dir, ".deps/prev"))).toBe(false);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("does nothing without a previous tree", () => {
|
|
110
|
+
rmSync(join(dir, ".deps"), { recursive: true, force: true });
|
|
111
|
+
const r = run("restore_deps");
|
|
112
|
+
expect(r.status).toBe(0);
|
|
113
|
+
expect(read("node_modules/marker")).toBe("old\n");
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Make `pnpm` runnable: the pinned version comes from package.json's
|
|
3
|
+
# packageManager field through corepack (bundled with Node 22; Node 25+ needs
|
|
4
|
+
# `npm i -g corepack`). Sourced by scripts/install-deps and scripts/redeploy.
|
|
5
|
+
|
|
6
|
+
use_pnpm() {
|
|
7
|
+
export COREPACK_ENABLE_DOWNLOAD_PROMPT=0
|
|
8
|
+
if ! command -v pnpm >/dev/null 2>&1 && command -v corepack >/dev/null 2>&1; then
|
|
9
|
+
corepack enable pnpm >/dev/null 2>&1 || true
|
|
10
|
+
fi
|
|
11
|
+
if ! command -v pnpm >/dev/null 2>&1; then
|
|
12
|
+
echo "pnpm is not available. Use Node 22 (it bundles corepack: corepack enable pnpm) or npm i -g corepack." >&2
|
|
13
|
+
return 1
|
|
14
|
+
fi
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
# Share -> Download -> PDF prints with Playwright's headless shell, at the
|
|
18
|
+
# revision the locked playwright package names. A failed download only warns:
|
|
19
|
+
# a deploy must not hang on a CDN, and the PDF option hides itself without a
|
|
20
|
+
# browser. Run after the install, from the repository root.
|
|
21
|
+
install_pdf_browser() {
|
|
22
|
+
if ! pnpm exec playwright install chromium-headless-shell; then
|
|
23
|
+
echo "Warning: could not download the PDF browser; share PDF is unavailable until 'pnpm exec playwright install chromium-headless-shell' succeeds." >&2
|
|
24
|
+
return 0
|
|
25
|
+
fi
|
|
26
|
+
if [ "$(uname -s)" = Linux ]; then
|
|
27
|
+
local bin missing
|
|
28
|
+
bin=$(node -e 'const p=require("playwright").chromium.executablePath();const fs=require("fs"),path=require("path");const root=path.dirname(path.dirname(path.dirname(p)));const d=fs.readdirSync(root).filter(x=>x.startsWith("chromium_headless_shell-")).sort().pop();if(d){const b=fs.readdirSync(path.join(root,d)).find(x=>x.startsWith("chrome-headless-shell-"));if(b)console.log(path.join(root,d,b,"chrome-headless-shell"))}' 2>/dev/null || true)
|
|
29
|
+
if [ -n "$bin" ] && command -v ldd >/dev/null 2>&1; then
|
|
30
|
+
missing=$(ldd "$bin" 2>/dev/null | grep -c 'not found' || true)
|
|
31
|
+
if [ "${missing:-0}" -gt 0 ]; then
|
|
32
|
+
echo "Warning: the PDF browser is missing $missing system libraries; run: sudo pnpm exec playwright install-deps chromium-headless-shell" >&2
|
|
33
|
+
fi
|
|
34
|
+
fi
|
|
35
|
+
fi
|
|
36
|
+
}
|
|
@@ -47,7 +47,7 @@ check_node() {
|
|
|
47
47
|
if command -v node &> /dev/null; then
|
|
48
48
|
local version
|
|
49
49
|
version=$(node -v | sed 's/v//' | cut -d. -f1)
|
|
50
|
-
if [[ "$version" -ge
|
|
50
|
+
if [[ "$version" -ge 22 ]]; then
|
|
51
51
|
local node_path=$(command -v node)
|
|
52
52
|
log_success "Found Node.js v$(node -v | sed 's/v//') at $node_path"
|
|
53
53
|
return 0
|
|
@@ -60,7 +60,7 @@ check_node() {
|
|
|
60
60
|
if command -v node &> /dev/null; then
|
|
61
61
|
local version
|
|
62
62
|
version=$(node -v | sed 's/v//' | cut -d. -f1)
|
|
63
|
-
if [[ "$version" -ge
|
|
63
|
+
if [[ "$version" -ge 22 ]]; then
|
|
64
64
|
local node_path=$(command -v node)
|
|
65
65
|
local manager=""
|
|
66
66
|
|
|
@@ -202,10 +202,10 @@ install_node() {
|
|
|
202
202
|
if command -v node &> /dev/null; then
|
|
203
203
|
local version
|
|
204
204
|
version=$(node -v | sed 's/v//' | cut -d. -f1)
|
|
205
|
-
if [[ "$version" -ge
|
|
205
|
+
if [[ "$version" -ge 22 ]]; then
|
|
206
206
|
return 0
|
|
207
207
|
fi
|
|
208
|
-
log_warn "Node.js $version found, but
|
|
208
|
+
log_warn "Node.js $version found, but 22+ required"
|
|
209
209
|
fi
|
|
210
210
|
|
|
211
211
|
log_info "Installing Node.js..."
|
|
@@ -224,9 +224,9 @@ install_node() {
|
|
|
224
224
|
export PATH="$HOME/.local/share/fnm:$PATH"
|
|
225
225
|
eval "$(fnm env --use-on-cd)"
|
|
226
226
|
|
|
227
|
-
# Install and use Node.js
|
|
228
|
-
fnm install
|
|
229
|
-
fnm use
|
|
227
|
+
# Install and use Node.js 22
|
|
228
|
+
fnm install 22
|
|
229
|
+
fnm use 22
|
|
230
230
|
|
|
231
231
|
# Add fnm to shell profile
|
|
232
232
|
local shell_profile=""
|
|
@@ -261,7 +261,7 @@ install_node() {
|
|
|
261
261
|
sudo yum install -y nodejs
|
|
262
262
|
;;
|
|
263
263
|
*)
|
|
264
|
-
log_error "Please install Node.js
|
|
264
|
+
log_error "Please install Node.js 22+ manually: https://nodejs.org"
|
|
265
265
|
exit 1
|
|
266
266
|
;;
|
|
267
267
|
esac
|
|
@@ -499,7 +499,7 @@ check_and_install_prerequisites() {
|
|
|
499
499
|
|
|
500
500
|
# What this distro has no installer for here is still missing.
|
|
501
501
|
local still=()
|
|
502
|
-
check_node > /dev/null || still+=("node
|
|
502
|
+
check_node > /dev/null || still+=("node 22+")
|
|
503
503
|
check_git > /dev/null || still+=("git")
|
|
504
504
|
check_tmux > /dev/null || still+=("tmux")
|
|
505
505
|
if [[ ${#still[@]} -gt 0 ]]; then
|
package/scripts/publish
CHANGED
|
@@ -14,10 +14,11 @@ trap 'rm -f "$npmrc"' EXIT
|
|
|
14
14
|
chmod 600 "$npmrc"
|
|
15
15
|
printf '//registry.npmjs.org/:_authToken=%s\n' "$token" > "$npmrc"
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
# npm is pinned (at least a week old), not @latest: this runs with the publish token.
|
|
18
|
+
echo "Publishing $name@$version as $(npx -y npm@11.21.0 whoami --userconfig "$npmrc")"
|
|
18
19
|
# A 409 "previously staged" means npm already took this version (an earlier
|
|
19
20
|
# run gave up waiting): that's not a failure, just keep waiting for it.
|
|
20
|
-
if ! out=$(NODE_ENV=development npx -y npm@
|
|
21
|
+
if ! out=$(NODE_ENV=development npx -y npm@11.21.0 publish --access public \
|
|
21
22
|
--userconfig "$npmrc" --ignore-scripts --loglevel warn 2>&1); then
|
|
22
23
|
echo "$out"
|
|
23
24
|
echo "$out" | grep -qiE "previously staged|cannot publish over" || exit 1
|
package/scripts/redeploy
CHANGED
|
@@ -8,6 +8,10 @@ set -euo pipefail
|
|
|
8
8
|
cd "$(dirname "$0")/.."
|
|
9
9
|
# shellcheck source=lib/build-swap.sh
|
|
10
10
|
source scripts/lib/build-swap.sh
|
|
11
|
+
# shellcheck source=lib/pnpm.sh
|
|
12
|
+
source scripts/lib/pnpm.sh
|
|
13
|
+
# shellcheck source=lib/deps-swap.sh
|
|
14
|
+
source scripts/lib/deps-swap.sh
|
|
11
15
|
|
|
12
16
|
if [ -s "$HOME/.nvm/nvm.sh" ]; then
|
|
13
17
|
# shellcheck disable=SC1091
|
|
@@ -15,23 +19,36 @@ if [ -s "$HOME/.nvm/nvm.sh" ]; then
|
|
|
15
19
|
nvm use >/dev/null
|
|
16
20
|
fi
|
|
17
21
|
|
|
22
|
+
# The pull can replace this script, so what follows runs from a fresh start.
|
|
23
|
+
if [ "${1:-}" != "--rollback" ] && [ "${1:-}" != "--pulled" ]; then
|
|
24
|
+
echo "::phase pulling"
|
|
25
|
+
git pull --ff-only
|
|
26
|
+
exec bash "$0" --pulled
|
|
27
|
+
fi
|
|
28
|
+
|
|
18
29
|
acquire_build_lock
|
|
19
30
|
|
|
20
31
|
if [ "${1:-}" = "--rollback" ]; then
|
|
21
32
|
rollback_build
|
|
33
|
+
# The build and the dependencies it ran on go back together.
|
|
34
|
+
restore_deps
|
|
22
35
|
else
|
|
23
|
-
echo "::phase pulling"
|
|
24
|
-
git pull --ff-only
|
|
25
36
|
echo "::phase installing"
|
|
37
|
+
use_pnpm
|
|
26
38
|
# The build needs dev dependencies even when the shell runs with
|
|
27
39
|
# NODE_ENV=production (as sessions started by AgentOS do).
|
|
28
|
-
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
unset NODE_ENV npm_config_production npm_config_omit
|
|
41
|
+
# Installed beside the live node_modules and checked (SQLite opens, a pty
|
|
42
|
+
# spawns) before they replace it: a broken install fails the deploy here,
|
|
43
|
+
# and the running server keeps the build and dependencies it has.
|
|
44
|
+
swapped=0
|
|
45
|
+
install_beside && rc=0 || rc=$?
|
|
46
|
+
[ "$rc" = 0 ] && { swap_deps; swapped=1; }
|
|
47
|
+
[ "$rc" = 0 ] || [ "$rc" = 10 ] || exit 1
|
|
48
|
+
install_pdf_browser
|
|
33
49
|
echo "::phase building"
|
|
34
|
-
|
|
50
|
+
# A build that fails on the new dependencies puts the old ones back.
|
|
51
|
+
build_beside || { [ "$swapped" = 1 ] && restore_deps; exit 1; }
|
|
35
52
|
swap_build
|
|
36
53
|
fi
|
|
37
54
|
|
package/scripts/setup.sh
CHANGED
|
@@ -8,13 +8,13 @@ echo ""
|
|
|
8
8
|
# Check Node.js
|
|
9
9
|
if ! command -v node &> /dev/null; then
|
|
10
10
|
echo "Error: Node.js is not installed"
|
|
11
|
-
echo "Install Node.js
|
|
11
|
+
echo "Install Node.js 22+ from https://nodejs.org"
|
|
12
12
|
exit 1
|
|
13
13
|
fi
|
|
14
14
|
|
|
15
15
|
NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1)
|
|
16
|
-
if [ "$NODE_VERSION" -lt
|
|
17
|
-
echo "Error: Node.js
|
|
16
|
+
if [ "$NODE_VERSION" -lt 22 ]; then
|
|
17
|
+
echo "Error: Node.js 22+ required (found v$NODE_VERSION)"
|
|
18
18
|
exit 1
|
|
19
19
|
fi
|
|
20
20
|
echo "Node.js: $(node -v)"
|
|
@@ -60,7 +60,7 @@ fi
|
|
|
60
60
|
# Install dependencies
|
|
61
61
|
echo ""
|
|
62
62
|
echo "Installing dependencies..."
|
|
63
|
-
|
|
63
|
+
scripts/install-deps
|
|
64
64
|
|
|
65
65
|
echo ""
|
|
66
66
|
echo "Setup complete!"
|
package/tsconfig.json
CHANGED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Native modules are compiled for one Node ABI. After a Node upgrade they fail
|
|
2
|
-
// at the first database call, so check before starting and rebuild if needed.
|
|
3
|
-
import { createRequire } from "module";
|
|
4
|
-
import { execSync } from "child_process";
|
|
5
|
-
|
|
6
|
-
const require = createRequire(import.meta.url);
|
|
7
|
-
const modules = ["better-sqlite3", "node-pty"];
|
|
8
|
-
|
|
9
|
-
function loads(name) {
|
|
10
|
-
try {
|
|
11
|
-
if (name === "better-sqlite3") require(name)(":memory:").close();
|
|
12
|
-
else require(name);
|
|
13
|
-
return true;
|
|
14
|
-
} catch (err) {
|
|
15
|
-
return !String(err?.message).includes("NODE_MODULE_VERSION");
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const stale = modules.filter((m) => !loads(m));
|
|
20
|
-
if (stale.length) {
|
|
21
|
-
console.log(`Rebuilding ${stale.join(", ")} for Node ${process.version}...`);
|
|
22
|
-
execSync(`npm rebuild ${stale.join(" ")}`, { stdio: "inherit" });
|
|
23
|
-
}
|