abtars 0.1.0-alpha.14 → 0.1.0-alpha.16
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/bundle/abtars-cli.js +2 -2
- package/bundle/chunk-TQG56KI3.js +542 -0
- package/bundle/chunk-TQG56KI3.js.map +7 -0
- package/bundle/chunk-XIEKGESU.js +541 -0
- package/bundle/chunk-XIEKGESU.js.map +7 -0
- package/bundle/meta.json +21 -11
- package/bundle/update-RWL26Q5R.js +14 -0
- package/bundle/update-RWL26Q5R.js.map +7 -0
- package/bundle/update-XLWLAPLP.js +14 -0
- package/bundle/update-XLWLAPLP.js.map +7 -0
- package/package.json +1 -1
package/bundle/abtars-cli.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
showHintOnce,
|
|
5
5
|
update
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TQG56KI3.js";
|
|
7
7
|
import {
|
|
8
8
|
install
|
|
9
9
|
} from "./chunk-RB3X66KM.js";
|
|
@@ -1036,7 +1036,7 @@ Next: cd into the abtars repo and run 'abtars update' to build and activate.
|
|
|
1036
1036
|
process.stdout.write(`
|
|
1037
1037
|
\u2500\u2500 Running 'abtars update' \u2500\u2500
|
|
1038
1038
|
`);
|
|
1039
|
-
const { update: update2 } = await import("./update-
|
|
1039
|
+
const { update: update2 } = await import("./update-XLWLAPLP.js");
|
|
1040
1040
|
const updRc = await update2({ source: "local", fromLocal: true, allowAbmindMismatch: false });
|
|
1041
1041
|
if (updRc !== 0) {
|
|
1042
1042
|
process.stderr.write(`
|
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __bundleCreateRequire } from 'node:module'; import { fileURLToPath as __bundleFileURLToPath } from 'node:url'; import { dirname as __bundleDirname } from 'node:path'; const require = __bundleCreateRequire(import.meta.url); const __chunk_filename = __bundleFileURLToPath(import.meta.url); const __chunk_dirname = __bundleDirname(__chunk_filename);
|
|
3
|
+
import {
|
|
4
|
+
RETENTION,
|
|
5
|
+
acquireLock,
|
|
6
|
+
activate,
|
|
7
|
+
emptyManifest,
|
|
8
|
+
hashFile,
|
|
9
|
+
packagePaths,
|
|
10
|
+
pruneReleases,
|
|
11
|
+
readManifest,
|
|
12
|
+
writeManifest
|
|
13
|
+
} from "./chunk-HXJRZWKA.js";
|
|
14
|
+
import {
|
|
15
|
+
init_log_and_swallow,
|
|
16
|
+
logAndSwallow
|
|
17
|
+
} from "./chunk-EX2SRTUE.js";
|
|
18
|
+
|
|
19
|
+
// src/cli/commands/update.ts
|
|
20
|
+
init_log_and_swallow();
|
|
21
|
+
import { hostname } from "node:os";
|
|
22
|
+
import { join as join4, dirname } from "node:path";
|
|
23
|
+
import { readFileSync as readFileSync3, existsSync as existsSync4, mkdirSync } from "node:fs";
|
|
24
|
+
import { copyFile as copyFile2, mkdir as mkdir3, chmod, readdir, readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
25
|
+
|
|
26
|
+
// src/cli/update-sources/local.ts
|
|
27
|
+
import { spawnSync } from "node:child_process";
|
|
28
|
+
import { existsSync } from "node:fs";
|
|
29
|
+
import { copyFile, cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
30
|
+
import { join } from "node:path";
|
|
31
|
+
var LocalBuildError = class extends Error {
|
|
32
|
+
constructor(message, hint) {
|
|
33
|
+
super(hint ? `${message}
|
|
34
|
+
|
|
35
|
+
${hint}` : message);
|
|
36
|
+
this.hint = hint;
|
|
37
|
+
this.name = "LocalBuildError";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
function runCmd(cmd, args, cwd) {
|
|
41
|
+
const r = spawnSync(cmd, args, { cwd, encoding: "utf-8" });
|
|
42
|
+
if (r.error) throw new LocalBuildError(`${cmd} ${args.join(" ")} failed: ${r.error.message}`);
|
|
43
|
+
if (r.status !== 0) {
|
|
44
|
+
throw new LocalBuildError(
|
|
45
|
+
`${cmd} ${args.join(" ")} exited with status ${r.status}`,
|
|
46
|
+
r.stderr?.trim() || void 0
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return r.stdout.trim();
|
|
50
|
+
}
|
|
51
|
+
function tryCmd(cmd, args, cwd) {
|
|
52
|
+
const r = spawnSync(cmd, args, { cwd, encoding: "utf-8" });
|
|
53
|
+
if (r.status !== 0) return null;
|
|
54
|
+
return r.stdout.trim();
|
|
55
|
+
}
|
|
56
|
+
function checkStaleness(repoRoot, allowStale) {
|
|
57
|
+
const commit = runCmd("git", ["rev-parse", "--short", "HEAD"], repoRoot);
|
|
58
|
+
const branch = tryCmd("git", ["rev-parse", "--abbrev-ref", "HEAD"], repoRoot);
|
|
59
|
+
if (allowStale) return { commit, branch: branch === "HEAD" ? null : branch };
|
|
60
|
+
if (branch === "HEAD" || branch === null) {
|
|
61
|
+
throw new LocalBuildError(
|
|
62
|
+
"Working tree is in detached HEAD (no current branch).",
|
|
63
|
+
"Cannot check for staleness. Pass --from-local to proceed with the current tree."
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
runCmd("git", ["fetch", "--quiet"], repoRoot);
|
|
67
|
+
const upstream = tryCmd("git", ["rev-parse", "--abbrev-ref", `${branch}@{upstream}`], repoRoot);
|
|
68
|
+
if (upstream === null) {
|
|
69
|
+
throw new LocalBuildError(
|
|
70
|
+
`Branch '${branch}' has no upstream configured.`,
|
|
71
|
+
"Cannot check for staleness. Push the branch, or pass --from-local to proceed with the current tree."
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const behindStr = tryCmd("git", ["rev-list", "--count", `HEAD..${upstream}`], repoRoot);
|
|
75
|
+
const behind = behindStr === null ? null : Number(behindStr);
|
|
76
|
+
if (behind === null || !Number.isFinite(behind)) {
|
|
77
|
+
throw new LocalBuildError(
|
|
78
|
+
`Could not determine how far HEAD is behind ${upstream}.`,
|
|
79
|
+
"Pass --from-local to proceed anyway."
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (behind > 0) {
|
|
83
|
+
throw new LocalBuildError(
|
|
84
|
+
`Current branch: ${branch} (${commit})
|
|
85
|
+
${upstream} is ahead by ${behind} commit${behind === 1 ? "" : "s"}.`,
|
|
86
|
+
`Run 'git pull' first, or pass --from-local to build from the current tree.`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return { commit, branch };
|
|
90
|
+
}
|
|
91
|
+
async function readPackageVersion(repoRoot) {
|
|
92
|
+
const pkg = JSON.parse(await readFile(join(repoRoot, "package.json"), "utf-8"));
|
|
93
|
+
if (typeof pkg.version !== "string") {
|
|
94
|
+
throw new LocalBuildError("package.json has no version field.");
|
|
95
|
+
}
|
|
96
|
+
return pkg.version;
|
|
97
|
+
}
|
|
98
|
+
function makeLocalBuildSource(opts = {}) {
|
|
99
|
+
const repoRoot = opts.repoRoot ?? process.cwd();
|
|
100
|
+
const isNpmPackage = !existsSync(join(repoRoot, ".git"));
|
|
101
|
+
return {
|
|
102
|
+
name: "local",
|
|
103
|
+
async prepare(ctx) {
|
|
104
|
+
if (isNpmPackage) {
|
|
105
|
+
const bundleDir = join(repoRoot, "bundle");
|
|
106
|
+
if (!existsSync(bundleDir)) {
|
|
107
|
+
throw new Error(`No bundle/ found at ${repoRoot}. Run from the abtars npm package or a git checkout.`);
|
|
108
|
+
}
|
|
109
|
+
const pkgVersion2 = await readPackageVersion(repoRoot);
|
|
110
|
+
const version2 = pkgVersion2;
|
|
111
|
+
const stagedPath2 = join(ctx.releasesDir, version2);
|
|
112
|
+
await rm(stagedPath2, { recursive: true, force: true });
|
|
113
|
+
await mkdir(stagedPath2, { recursive: true });
|
|
114
|
+
await cp(bundleDir, join(stagedPath2, "bundle"), { recursive: true });
|
|
115
|
+
const coreDir = join(repoRoot, "core");
|
|
116
|
+
if (existsSync(coreDir)) await cp(coreDir, join(stagedPath2, "core"), { recursive: true });
|
|
117
|
+
const scriptsSrc = join(repoRoot, "scripts");
|
|
118
|
+
if (existsSync(scriptsSrc)) await cp(scriptsSrc, join(stagedPath2, "scripts"), { recursive: true });
|
|
119
|
+
const manifestSrc = join(repoRoot, "install-manifest.json");
|
|
120
|
+
if (existsSync(manifestSrc)) await copyFile(manifestSrc, join(stagedPath2, "install-manifest.json"));
|
|
121
|
+
await writeFile(join(stagedPath2, "package.json"), JSON.stringify({ type: "module", name: "abtars", version: version2 }, null, 2) + "\n");
|
|
122
|
+
process.stdout.write(`\u2713 staged ${version2} (from npm package)
|
|
123
|
+
`);
|
|
124
|
+
return { version: version2, stagedPath: stagedPath2, commit: null, branch: null, packageLockHash: null, source: "local" };
|
|
125
|
+
}
|
|
126
|
+
const { commit, branch } = checkStaleness(repoRoot, opts.allowStale === true || ctx.allowStale);
|
|
127
|
+
const pkgVersion = await readPackageVersion(repoRoot);
|
|
128
|
+
const version = `${pkgVersion}-${commit}`;
|
|
129
|
+
if (opts.skipInstall !== true) {
|
|
130
|
+
runCmd("npm", ["install", "--no-audit", "--no-fund"], repoRoot);
|
|
131
|
+
}
|
|
132
|
+
const useBundle = process.env["AGENTBRIDGE_BUILD_MODE"] !== "tsc";
|
|
133
|
+
if (useBundle) {
|
|
134
|
+
runCmd("npm", ["run", "bundle"], repoRoot);
|
|
135
|
+
const stagedPath2 = join(ctx.releasesDir, version);
|
|
136
|
+
await rm(stagedPath2, { recursive: true, force: true });
|
|
137
|
+
await mkdir(stagedPath2, { recursive: true });
|
|
138
|
+
await cp(join(repoRoot, "bundle"), join(stagedPath2, "bundle"), { recursive: true });
|
|
139
|
+
const coreSkillsSrc = join(repoRoot, "core", "skills");
|
|
140
|
+
if (existsSync(coreSkillsSrc)) {
|
|
141
|
+
await cp(coreSkillsSrc, join(stagedPath2, "core", "skills"), { recursive: true });
|
|
142
|
+
}
|
|
143
|
+
await writeFile(join(stagedPath2, "package.json"), JSON.stringify({ type: "module", name: "abtars", version }, null, 2) + "\n");
|
|
144
|
+
await copyFile(join(repoRoot, "install-manifest.json"), join(stagedPath2, "install-manifest.json"));
|
|
145
|
+
const packageLockHash2 = await hashFile(join(repoRoot, "package-lock.json"));
|
|
146
|
+
return { version, stagedPath: stagedPath2, commit, branch, packageLockHash: packageLockHash2, source: "local" };
|
|
147
|
+
}
|
|
148
|
+
runCmd("npm", ["run", "build"], repoRoot);
|
|
149
|
+
const stagedPath = join(ctx.releasesDir, version);
|
|
150
|
+
await rm(stagedPath, { recursive: true, force: true });
|
|
151
|
+
await mkdir(stagedPath, { recursive: true });
|
|
152
|
+
await cp(join(repoRoot, "dist"), join(stagedPath, "dist"), { recursive: true });
|
|
153
|
+
await copyFile(join(repoRoot, "install-manifest.json"), join(stagedPath, "install-manifest.json"));
|
|
154
|
+
await rm(ctx.nodeModulesDir, { recursive: true, force: true });
|
|
155
|
+
await mkdir(ctx.nodeModulesDir, { recursive: true });
|
|
156
|
+
const rsyncResult = spawnSync(
|
|
157
|
+
"rsync",
|
|
158
|
+
["-aL", "--quiet", `${join(repoRoot, "node_modules")}/`, `${ctx.nodeModulesDir}/`],
|
|
159
|
+
{ stdio: "inherit" }
|
|
160
|
+
);
|
|
161
|
+
if (rsyncResult.status !== 0) {
|
|
162
|
+
throw new LocalBuildError(
|
|
163
|
+
`rsync of node_modules failed (status ${rsyncResult.status ?? -1})`,
|
|
164
|
+
`Ensure rsync is installed. Falling back to node cp would re-create symlinks.`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
const packageLockHash = await hashFile(join(repoRoot, "package-lock.json"));
|
|
168
|
+
return { version, stagedPath, commit, branch, packageLockHash, source: "local" };
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/cli/update-sources/npm.ts
|
|
174
|
+
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
175
|
+
import { existsSync as existsSync2, readFileSync, unlinkSync } from "node:fs";
|
|
176
|
+
import { mkdir as mkdir2, rm as rm2 } from "node:fs/promises";
|
|
177
|
+
import { join as join2 } from "node:path";
|
|
178
|
+
var TIMEOUT_MS = 6e4;
|
|
179
|
+
function run(cmd, args, cwd) {
|
|
180
|
+
const r = spawnSync2(cmd, args, { cwd, encoding: "utf-8", timeout: TIMEOUT_MS });
|
|
181
|
+
if (r.error) throw new Error(`${cmd} ${args.join(" ")}: ${r.error.message}`);
|
|
182
|
+
if (r.status !== 0) throw new Error(`${cmd} ${args.join(" ")} exited ${r.status}: ${r.stderr?.trim()}`);
|
|
183
|
+
return r.stdout.trim();
|
|
184
|
+
}
|
|
185
|
+
function readLocalVersion(home) {
|
|
186
|
+
try {
|
|
187
|
+
const pkg = JSON.parse(readFileSync(join2(home, "current", "package.json"), "utf-8"));
|
|
188
|
+
return pkg.version ?? null;
|
|
189
|
+
} catch {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function makeNpmSource(packageName) {
|
|
194
|
+
return {
|
|
195
|
+
name: "npm",
|
|
196
|
+
async prepare(ctx) {
|
|
197
|
+
const latest = run("npm", ["view", packageName, "version"], ctx.home);
|
|
198
|
+
const current = readLocalVersion(ctx.home);
|
|
199
|
+
if (latest === current) {
|
|
200
|
+
throw new Error(`Already at latest version (${latest}). Nothing to update.`);
|
|
201
|
+
}
|
|
202
|
+
const stagedPath = join2(ctx.releasesDir, latest);
|
|
203
|
+
await rm2(stagedPath, { recursive: true, force: true });
|
|
204
|
+
await mkdir2(stagedPath, { recursive: true });
|
|
205
|
+
run("npm", ["pack", `${packageName}@${latest}`, "--pack-destination", stagedPath], stagedPath);
|
|
206
|
+
const tgzName = `${packageName}-${latest}.tgz`.replace("@", "").replace("/", "-");
|
|
207
|
+
const tgzPath = join2(stagedPath, tgzName);
|
|
208
|
+
run("tar", ["-xzf", tgzPath, "--strip-components=1"], stagedPath);
|
|
209
|
+
if (existsSync2(tgzPath)) unlinkSync(tgzPath);
|
|
210
|
+
run("npm", ["install", "--omit=dev", "--no-audit", "--no-fund"], stagedPath);
|
|
211
|
+
return { version: latest, stagedPath, commit: null, branch: null, packageLockHash: null, source: "npm" };
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/components/hints.ts
|
|
217
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, writeFileSync, renameSync } from "node:fs";
|
|
218
|
+
import { join as join3 } from "node:path";
|
|
219
|
+
function manifestPath() {
|
|
220
|
+
const home = process.env["ABTARS_HOME"] ?? join3(process.env["HOME"] ?? "", ".abtars");
|
|
221
|
+
return join3(home, "manifest.json");
|
|
222
|
+
}
|
|
223
|
+
function readManifest2() {
|
|
224
|
+
const path = manifestPath();
|
|
225
|
+
if (!existsSync3(path)) return {};
|
|
226
|
+
try {
|
|
227
|
+
return JSON.parse(readFileSync2(path, "utf-8"));
|
|
228
|
+
} catch {
|
|
229
|
+
return {};
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function writeManifestAtomic(data) {
|
|
233
|
+
const path = manifestPath();
|
|
234
|
+
const tmp = path + ".tmp";
|
|
235
|
+
writeFileSync(tmp, JSON.stringify(data, null, 2) + "\n");
|
|
236
|
+
renameSync(tmp, path);
|
|
237
|
+
}
|
|
238
|
+
function showHintOnce(id, text) {
|
|
239
|
+
const manifest = readManifest2();
|
|
240
|
+
const seen = manifest["hintsSeen"] ?? {};
|
|
241
|
+
if (seen[id]) return;
|
|
242
|
+
process.stderr.write(`
|
|
243
|
+
\u{1F4A1} ${text}
|
|
244
|
+
|
|
245
|
+
`);
|
|
246
|
+
seen[id] = (/* @__PURE__ */ new Date()).toISOString();
|
|
247
|
+
manifest["hintsSeen"] = seen;
|
|
248
|
+
writeManifestAtomic(manifest);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// src/cli/commands/update.ts
|
|
252
|
+
function readJsonField(file, field) {
|
|
253
|
+
try {
|
|
254
|
+
return JSON.parse(readFileSync3(file, "utf-8"))[field];
|
|
255
|
+
} catch {
|
|
256
|
+
return void 0;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
async function update(opts) {
|
|
260
|
+
if (opts.source !== "local" && opts.source !== "npm") {
|
|
261
|
+
process.stderr.write(`--source ${opts.source} is not yet supported.
|
|
262
|
+
Use --source local (default) or --source npm.
|
|
263
|
+
`);
|
|
264
|
+
return 2;
|
|
265
|
+
}
|
|
266
|
+
const paths = packagePaths("abtars");
|
|
267
|
+
if (!existsSync4(paths.releases) && existsSync4(join4(paths.home, "current"))) {
|
|
268
|
+
process.stdout.write("Migrating old layout \u2192 releases/...\n");
|
|
269
|
+
mkdirSync(paths.releases, { recursive: true });
|
|
270
|
+
}
|
|
271
|
+
const release = await acquireLock(paths.lock, `update --source ${opts.source}`);
|
|
272
|
+
try {
|
|
273
|
+
let repoRoot = opts.repoRoot ?? process.cwd();
|
|
274
|
+
if (!opts.repoRoot && !existsSync4(join4(repoRoot, ".git"))) {
|
|
275
|
+
const { realpathSync } = await import("node:fs");
|
|
276
|
+
const scriptPath = realpathSync(process.argv[1] ?? "");
|
|
277
|
+
const candidate = join4(dirname(scriptPath), "..");
|
|
278
|
+
if (existsSync4(join4(candidate, "bundle"))) repoRoot = candidate;
|
|
279
|
+
}
|
|
280
|
+
const source = opts.source === "npm" ? makeNpmSource("abtars") : makeLocalBuildSource({ repoRoot, allowStale: opts.fromLocal });
|
|
281
|
+
if (opts.fromLocal) {
|
|
282
|
+
showHintOnce("update-from-local", "Building from working copy (--from-local). To sync with remote first: git pull && abtars update");
|
|
283
|
+
}
|
|
284
|
+
process.stdout.write(`Building from local checkout (${process.cwd()})...
|
|
285
|
+
`);
|
|
286
|
+
const staged = await source.prepare({
|
|
287
|
+
releasesDir: paths.releases,
|
|
288
|
+
nodeModulesDir: paths.nodeModules,
|
|
289
|
+
home: paths.home,
|
|
290
|
+
allowStale: opts.fromLocal
|
|
291
|
+
});
|
|
292
|
+
process.stdout.write(`\u2713 staged ${staged.version} at ${staged.stagedPath}
|
|
293
|
+
`);
|
|
294
|
+
{
|
|
295
|
+
const pkgPath = join4(staged.stagedPath, "package.json");
|
|
296
|
+
const { readFileSync: readFileSync4, writeFileSync: writeFileSync2 } = await import("node:fs");
|
|
297
|
+
try {
|
|
298
|
+
const pkg = JSON.parse(readFileSync4(pkgPath, "utf-8"));
|
|
299
|
+
const externals = { patchright: "^1.59.4", "rettiwt-api": "^4.1.3" };
|
|
300
|
+
pkg.dependencies = { ...pkg.dependencies, ...externals };
|
|
301
|
+
writeFileSync2(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
|
|
302
|
+
const { execSync } = await import("node:child_process");
|
|
303
|
+
execSync("npm install --omit=dev --ignore-scripts 2>/dev/null", { cwd: staged.stagedPath, timeout: 6e4 });
|
|
304
|
+
process.stdout.write(`\u2713 external deps installed
|
|
305
|
+
`);
|
|
306
|
+
} catch (err) {
|
|
307
|
+
process.stdout.write(`\u26A0 external deps install failed: ${err instanceof Error ? err.message : String(err)}
|
|
308
|
+
`);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
{
|
|
312
|
+
const { existsSync: existsSync5, unlinkSync: unlinkSync2, symlinkSync } = await import("node:fs");
|
|
313
|
+
const mainLink = join4(staged.stagedPath, "main.js");
|
|
314
|
+
try {
|
|
315
|
+
unlinkSync2(mainLink);
|
|
316
|
+
} catch (err) {
|
|
317
|
+
logAndSwallow("update", "op", err);
|
|
318
|
+
}
|
|
319
|
+
const entry = existsSync5(join4(staged.stagedPath, "bundle", "abtars.js")) ? "bundle/abtars.js" : "dist/main.js";
|
|
320
|
+
symlinkSync(entry, mainLink);
|
|
321
|
+
}
|
|
322
|
+
const { existsSync: ex2, lstatSync, readlinkSync, symlinkSync: sl2, mkdirSync: mk2 } = await import("node:fs");
|
|
323
|
+
const oldNm = join4(paths.home, "current", "node_modules");
|
|
324
|
+
const preservedLinks = [];
|
|
325
|
+
if (ex2(oldNm)) {
|
|
326
|
+
for (const name of ["abmind", "better-sqlite3"]) {
|
|
327
|
+
const p = join4(oldNm, name);
|
|
328
|
+
try {
|
|
329
|
+
if (ex2(p) && lstatSync(p).isSymbolicLink()) preservedLinks.push({ name, target: readlinkSync(p) });
|
|
330
|
+
} catch {
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
await activate(paths.current, staged.version);
|
|
335
|
+
process.stdout.write(`\u2713 current -> releases/${staged.version}
|
|
336
|
+
`);
|
|
337
|
+
if (preservedLinks.length > 0) {
|
|
338
|
+
const newNm = join4(paths.home, "current", "node_modules");
|
|
339
|
+
mk2(newNm, { recursive: true });
|
|
340
|
+
for (const { name, target } of preservedLinks) {
|
|
341
|
+
try {
|
|
342
|
+
sl2(target, join4(newNm, name));
|
|
343
|
+
} catch {
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const prior = await readManifest(paths.manifest);
|
|
348
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
349
|
+
const newPriorReleases = prior?.version ? [
|
|
350
|
+
{
|
|
351
|
+
version: prior.version,
|
|
352
|
+
commit: prior.commit,
|
|
353
|
+
activatedAt: prior.activatedAt,
|
|
354
|
+
packageLockHash: prior.packageLockHash
|
|
355
|
+
},
|
|
356
|
+
...prior.priorReleases ?? []
|
|
357
|
+
].slice(0, RETENTION - 1) : prior?.priorReleases ?? [];
|
|
358
|
+
await writeManifest(paths.manifest, {
|
|
359
|
+
...prior ?? emptyManifest("abtars", hostname()),
|
|
360
|
+
version: staged.version,
|
|
361
|
+
commit: staged.commit,
|
|
362
|
+
branch: staged.branch,
|
|
363
|
+
packageLockHash: staged.packageLockHash,
|
|
364
|
+
activatedAt: now,
|
|
365
|
+
source: "local",
|
|
366
|
+
priorReleases: newPriorReleases
|
|
367
|
+
});
|
|
368
|
+
process.stdout.write(`\u2713 manifest updated
|
|
369
|
+
`);
|
|
370
|
+
const pruned = await pruneReleases(
|
|
371
|
+
paths.releases,
|
|
372
|
+
[staged.version, ...newPriorReleases.map((r) => r.version)],
|
|
373
|
+
staged.version,
|
|
374
|
+
RETENTION
|
|
375
|
+
);
|
|
376
|
+
if (pruned.length > 0) {
|
|
377
|
+
process.stdout.write(`\u2713 pruned ${pruned.length} old release${pruned.length === 1 ? "" : "s"}: ${pruned.join(", ")}
|
|
378
|
+
`);
|
|
379
|
+
}
|
|
380
|
+
process.stdout.write(`
|
|
381
|
+
Update complete: ${staged.version}
|
|
382
|
+
`);
|
|
383
|
+
const { loadManifest } = await import("./install-manifest-MCJCAYSR.js");
|
|
384
|
+
const sourceRoot = staged.stagedPath;
|
|
385
|
+
const installManifest = loadManifest(sourceRoot);
|
|
386
|
+
const repoScripts = join4(sourceRoot, "scripts");
|
|
387
|
+
const destScripts = join4(paths.home, "scripts");
|
|
388
|
+
await mkdir3(destScripts, { recursive: true });
|
|
389
|
+
const allScriptFiles = await readdir(repoScripts).catch(() => []);
|
|
390
|
+
const matchesInclude = (name) => installManifest.scripts.include.some((pattern) => {
|
|
391
|
+
const ext = pattern.replace("*", "");
|
|
392
|
+
return name.endsWith(ext);
|
|
393
|
+
});
|
|
394
|
+
const scriptFiles = allScriptFiles.filter(matchesInclude);
|
|
395
|
+
const home = process.env["HOME"] ?? "";
|
|
396
|
+
let serviceChanged = false;
|
|
397
|
+
const installMode = (await readManifest(paths.manifest))?.installMode ?? "supervised";
|
|
398
|
+
const isExecutable = (name) => {
|
|
399
|
+
const ext = installManifest.scripts.executable.replace("*", "");
|
|
400
|
+
return name.endsWith(ext);
|
|
401
|
+
};
|
|
402
|
+
for (const name of scriptFiles) {
|
|
403
|
+
await copyFile2(join4(repoScripts, name), join4(destScripts, name));
|
|
404
|
+
if (isExecutable(name)) await chmod(join4(destScripts, name), 493);
|
|
405
|
+
if (isExecutable(name)) {
|
|
406
|
+
await copyFile2(join4(repoScripts, name), join4(paths.home, name));
|
|
407
|
+
await chmod(join4(paths.home, name), 493);
|
|
408
|
+
}
|
|
409
|
+
const macService = installManifest.services.supervised.macos;
|
|
410
|
+
if (macService && name === macService.plist && process.platform === "darwin" && home && installMode === "supervised") {
|
|
411
|
+
const launchAgentsDir = join4(home, "Library", "LaunchAgents");
|
|
412
|
+
await mkdir3(launchAgentsDir, { recursive: true });
|
|
413
|
+
const dst = join4(launchAgentsDir, name);
|
|
414
|
+
const oldContent = await readFile2(dst, "utf-8").catch(() => "");
|
|
415
|
+
let templated = await readFile2(join4(repoScripts, name), "utf-8");
|
|
416
|
+
for (const ph of macService.placeholders) templated = templated.replaceAll(ph, home);
|
|
417
|
+
await writeFile2(dst, templated);
|
|
418
|
+
if (oldContent !== templated) serviceChanged = true;
|
|
419
|
+
}
|
|
420
|
+
const linuxService = installManifest.services.supervised.linux;
|
|
421
|
+
if (linuxService?.units.includes(name) && process.platform === "linux" && home && installMode === "supervised") {
|
|
422
|
+
const systemdDir = join4(home, ".config", "systemd", "user");
|
|
423
|
+
await mkdir3(systemdDir, { recursive: true });
|
|
424
|
+
const dst = join4(systemdDir, name);
|
|
425
|
+
const oldContent = await readFile2(dst, "utf-8").catch(() => "");
|
|
426
|
+
await copyFile2(join4(repoScripts, name), dst);
|
|
427
|
+
const newContent = await readFile2(dst, "utf-8").catch(() => "");
|
|
428
|
+
if (oldContent !== newContent) serviceChanged = true;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
process.stdout.write(`\u2713 scripts refreshed (${scriptFiles.length} files)
|
|
432
|
+
`);
|
|
433
|
+
const { writeWrapper } = await import("./install-AJ7VW76P.js");
|
|
434
|
+
await mkdir3(paths.bin, { recursive: true });
|
|
435
|
+
for (const name of installManifest.cliWrappers) {
|
|
436
|
+
await writeWrapper(paths.bin, name, paths.current, false);
|
|
437
|
+
}
|
|
438
|
+
process.stdout.write(`\u2713 wrappers refreshed (${installManifest.cliWrappers.length} files)
|
|
439
|
+
`);
|
|
440
|
+
const { rmSync, cpSync, readdirSync } = await import("node:fs");
|
|
441
|
+
const skillsCoreSrc = join4(staged.stagedPath, "core", "skills");
|
|
442
|
+
const skillsCoreDst = join4(paths.home, "skills", "core");
|
|
443
|
+
if (existsSync4(skillsCoreSrc)) {
|
|
444
|
+
rmSync(skillsCoreDst, { recursive: true, force: true });
|
|
445
|
+
cpSync(skillsCoreSrc, skillsCoreDst, { recursive: true });
|
|
446
|
+
const files = readdirSync(skillsCoreDst, { recursive: true });
|
|
447
|
+
const count = files.filter((f) => f.endsWith("SKILL.md")).length;
|
|
448
|
+
process.stdout.write(`\u2713 skills/core synced (${count} skills)
|
|
449
|
+
`);
|
|
450
|
+
}
|
|
451
|
+
for (const d of ["custom", "downloaded", "self"]) {
|
|
452
|
+
await mkdir3(join4(paths.home, "skills", d), { recursive: true });
|
|
453
|
+
}
|
|
454
|
+
for (const stale of ["memory", "ops", "tools", "coding"]) {
|
|
455
|
+
const p = join4(paths.home, "skills", stale);
|
|
456
|
+
if (existsSync4(p)) {
|
|
457
|
+
rmSync(p, { recursive: true, force: true });
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (serviceChanged) {
|
|
461
|
+
if (process.platform === "darwin") {
|
|
462
|
+
process.stdout.write(`\u26A0\uFE0F LaunchAgent plist updated \u2014 reload with: launchctl bootout gui/$(id -u)/com.abtars.watchdog && launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.abtars.watchdog.plist
|
|
463
|
+
`);
|
|
464
|
+
} else {
|
|
465
|
+
process.stdout.write(`\u26A0\uFE0F systemd service updated \u2014 reload with: systemctl --user daemon-reload && systemctl --user restart abtars-watchdog
|
|
466
|
+
`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
void hashFile;
|
|
470
|
+
const { ensureInstallInvariants } = await import("./ensure-invariants-K2ZUZ6NR.js");
|
|
471
|
+
const invariantResults = await ensureInstallInvariants(process.cwd(), paths.home);
|
|
472
|
+
if (invariantResults.length > 0) {
|
|
473
|
+
process.stdout.write(`\u2713 invariants: ${invariantResults.join(", ")}
|
|
474
|
+
`);
|
|
475
|
+
}
|
|
476
|
+
const doctorPath = join4(paths.home, "scripts", "doctor.sh");
|
|
477
|
+
if (existsSync4(doctorPath)) {
|
|
478
|
+
process.stdout.write("\n\u{1FA7A} Health check...\n");
|
|
479
|
+
try {
|
|
480
|
+
const { execSync } = await import("node:child_process");
|
|
481
|
+
execSync(`bash "${doctorPath}" --fix`, { stdio: "inherit", timeout: 3e4 });
|
|
482
|
+
} catch (err) {
|
|
483
|
+
process.stderr.write(`\u26A0\uFE0F doctor --fix failed: ${err instanceof Error ? err.message : String(err)}
|
|
484
|
+
`);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const manifestForRestart = await readManifest(paths.manifest);
|
|
488
|
+
const restartMode = manifestForRestart?.installMode;
|
|
489
|
+
if (!restartMode) {
|
|
490
|
+
process.stderr.write("\u274C installMode not set in manifest.json. Run 'abtars install' first.\n");
|
|
491
|
+
return 1;
|
|
492
|
+
}
|
|
493
|
+
if (restartMode === "supervised-daemon" || restartMode === "supervised") {
|
|
494
|
+
process.stdout.write("\nRestarting bridge via watchdog...\n");
|
|
495
|
+
const wdLock = join4(paths.home, "watchdog.lock");
|
|
496
|
+
const wdPid = readJsonField(wdLock, "pid");
|
|
497
|
+
if (wdPid && wdPid > 0) {
|
|
498
|
+
try {
|
|
499
|
+
process.kill(wdPid, "SIGUSR1");
|
|
500
|
+
process.stdout.write(`\u267B\uFE0F USR1 sent to watchdog (PID ${wdPid}) \u2014 bridge will restart
|
|
501
|
+
`);
|
|
502
|
+
} catch {
|
|
503
|
+
process.stdout.write(`\u26A0\uFE0F Could not signal watchdog (PID ${wdPid}). Restart manually:
|
|
504
|
+
`);
|
|
505
|
+
if (process.platform === "darwin") {
|
|
506
|
+
process.stdout.write(` launchctl kickstart -k gui/$(id -u)/com.abtars.watchdog
|
|
507
|
+
`);
|
|
508
|
+
} else {
|
|
509
|
+
process.stdout.write(` systemctl --user restart abtars-watchdog
|
|
510
|
+
`);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
} else {
|
|
514
|
+
process.stdout.write(`\u26A0\uFE0F Watchdog not running. Cold restart...
|
|
515
|
+
`);
|
|
516
|
+
const { restart } = await import("./abtars-restart.js");
|
|
517
|
+
await restart({ cold: true }).catch((err) => {
|
|
518
|
+
process.stderr.write(`\u26A0\uFE0F Restart failed: ${err instanceof Error ? err.message : String(err)}
|
|
519
|
+
`);
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
} else {
|
|
523
|
+
process.stdout.write("\nRestarting bridge...\n");
|
|
524
|
+
const { restart } = await import("./abtars-restart.js");
|
|
525
|
+
await restart({ cold: true }).catch((err) => {
|
|
526
|
+
process.stderr.write(`\u26A0\uFE0F Restart failed: ${err instanceof Error ? err.message : String(err)}
|
|
527
|
+
`);
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
const { printHealthSummary } = await import("./health-check-RJ2SUJYL.js");
|
|
531
|
+
printHealthSummary(paths.home);
|
|
532
|
+
return 0;
|
|
533
|
+
} finally {
|
|
534
|
+
await release();
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export {
|
|
539
|
+
showHintOnce,
|
|
540
|
+
update
|
|
541
|
+
};
|
|
542
|
+
//# sourceMappingURL=chunk-TQG56KI3.js.map
|