@adea-ai/app-framework 0.40.1 → 0.41.1
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 +5 -0
- package/dist/developer-app/developer-app.d.ts +3 -0
- package/dist/developer-app/developer-app.js +36 -2
- package/dist/developer-app/workspace-follower.d.ts +46 -0
- package/dist/developer-app/workspace-follower.js +126 -0
- package/dist/framework-source.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -768,6 +768,11 @@ resolve from the file's folder):
|
|
|
768
768
|
set, so the shell build overlaps the dev server's startup and first compile (`warm`
|
|
769
769
|
paths are fetched as soon as it answers). Until it answers, the window shows a page
|
|
770
770
|
that reloads itself every second. Shell source edits (`watch`) restart the shell.
|
|
771
|
+
- While it runs it keeps the checkout a live dev environment (`followWorkspace`): every
|
|
772
|
+
few minutes `but pull` brings in the latest main, keeping the in-progress branches
|
|
773
|
+
applied. A branch that would conflict is unapplied first (GitButler keeps it to apply
|
|
774
|
+
again once rebased) and announced in a notification. A lockfile change reinstalls and
|
|
775
|
+
restarts the app (the runner exits with 75 and the launcher starts it again).
|
|
771
776
|
- `adea-developer-app install` adds "<Name> (Dev).app" to `/Applications`
|
|
772
777
|
(`ADEA_DEVELOPER_APP_DIR` overrides): a launcher that runs `run` from the checkout
|
|
773
778
|
in a login shell and logs to `~/Library/Logs/<Name> (Dev).log`. Pass
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* Dock) that starts it from the checkout.
|
|
15
15
|
*/
|
|
16
16
|
import { type ChildProcess } from 'node:child_process';
|
|
17
|
+
export { DEVELOPER_APP_RESTART_EXIT_CODE, followWorkspace } from './workspace-follower';
|
|
17
18
|
/** Set for every developer app build and run; the build hook and the shell read it. */
|
|
18
19
|
export declare const DEVELOPER_APP_VARIABLE = "ADEA_DEVELOPER_APP";
|
|
19
20
|
/** The developer app's display name, for the build hook's bundle naming. */
|
|
@@ -96,6 +97,8 @@ export declare function developerAppShellEnv(config: DeveloperAppConfig, env?: R
|
|
|
96
97
|
*/
|
|
97
98
|
export declare function runDeveloperApp(config: DeveloperAppConfig, options?: {
|
|
98
99
|
log?: (line: string) => void;
|
|
100
|
+
/** Keep the checkout current with its target branch (default true; see workspace-follower). */
|
|
101
|
+
follow?: boolean;
|
|
99
102
|
}): Promise<never>;
|
|
100
103
|
/**
|
|
101
104
|
* Install the developer app's launcher (macOS): "<Name> (Dev).app" in `directory`
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DEVELOPER_APP_RESTART_EXIT_CODE, followWorkspace } from "./workspace-follower.js";
|
|
1
2
|
import { dirname, isAbsolute, join, resolve } from "node:path";
|
|
2
3
|
import { chmodSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, symlinkSync, watch, writeFileSync } from "node:fs";
|
|
3
4
|
import { spawn, spawnSync } from "node:child_process";
|
|
@@ -291,9 +292,38 @@ async function runDeveloperApp(config, options = {}) {
|
|
|
291
292
|
});
|
|
292
293
|
for (const folder of config.watch ?? ["src"]) watch(join(config.shellDirectory, folder), { recursive: true }, (_event, file) => onChange(file ? String(file) : null));
|
|
293
294
|
startShell();
|
|
295
|
+
if (options.follow !== false) {
|
|
296
|
+
const checkout = spawnSync("git", ["rev-parse", "--show-toplevel"], {
|
|
297
|
+
cwd: config.shellDirectory,
|
|
298
|
+
encoding: "utf8"
|
|
299
|
+
}).stdout?.trim();
|
|
300
|
+
if (checkout) followWorkspace({
|
|
301
|
+
checkout,
|
|
302
|
+
log,
|
|
303
|
+
onSetAside: (branches) => notify(identity.name, `Unapplied ${branches.join(", ")}: it conflicts with main.`),
|
|
304
|
+
onDependenciesChanged: () => {
|
|
305
|
+
log("developer app: dependencies changed; reinstalling and restarting");
|
|
306
|
+
spawnSync("bun", ["install"], {
|
|
307
|
+
cwd: checkout,
|
|
308
|
+
stdio: "inherit"
|
|
309
|
+
});
|
|
310
|
+
shutdown(75);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
294
314
|
await uiReady;
|
|
295
315
|
return new Promise(() => {});
|
|
296
316
|
}
|
|
317
|
+
/** An AppleScript string literal. */
|
|
318
|
+
var appleScriptText = (value) => JSON.stringify(value.replaceAll("\"", "'"));
|
|
319
|
+
/** A macOS notification; nothing elsewhere. Best effort. */
|
|
320
|
+
function notify(title, message) {
|
|
321
|
+
if (process.platform !== "darwin") return;
|
|
322
|
+
spawn("osascript", ["-e", `display notification ${appleScriptText(message)} with title ${appleScriptText(title)}`], {
|
|
323
|
+
stdio: "ignore",
|
|
324
|
+
detached: true
|
|
325
|
+
}).unref();
|
|
326
|
+
}
|
|
297
327
|
var quote = (value) => `'${value.replaceAll("'", `'\\''`)}'`;
|
|
298
328
|
/**
|
|
299
329
|
* Install the developer app's launcher (macOS): "<Name> (Dev).app" in `directory`
|
|
@@ -317,7 +347,11 @@ function installDeveloperAppLauncher(options) {
|
|
|
317
347
|
writeFileSync(join(contents, "MacOS", executable), `#!/bin/zsh -l
|
|
318
348
|
osascript -e ${quote(notice)} >/dev/null 2>&1 &
|
|
319
349
|
cd ${quote(options.checkout)} || exit 1
|
|
320
|
-
|
|
350
|
+
# The runner exits with 75 to be started again (after a dependency update).
|
|
351
|
+
while true; do
|
|
352
|
+
${options.command.map(quote).join(" ")} >> ${quote(log)} 2>&1
|
|
353
|
+
[ $? -eq 75 ] || exit
|
|
354
|
+
done
|
|
321
355
|
`);
|
|
322
356
|
chmodSync(join(contents, "MacOS", executable), 493);
|
|
323
357
|
writeFileSync(join(contents, "Info.plist"), `<?xml version="1.0" encoding="UTF-8"?>
|
|
@@ -354,4 +388,4 @@ exec ${options.command.map(quote).join(" ")} >> ${quote(log)} 2>&1
|
|
|
354
388
|
log
|
|
355
389
|
};
|
|
356
390
|
}
|
|
357
|
-
export { DEVELOPER_APP_NAME_VARIABLE, DEVELOPER_APP_VARIABLE, createShellRestarter, developerAppIdentity, developerAppShellEnv, finishDeveloperBundle, installDeveloperAppLauncher, isDeveloperApp, nameDeveloperBundle, parseDeveloperAppConfig, readDeveloperAppConfig, runDeveloperApp };
|
|
391
|
+
export { DEVELOPER_APP_NAME_VARIABLE, DEVELOPER_APP_RESTART_EXIT_CODE, DEVELOPER_APP_VARIABLE, createShellRestarter, developerAppIdentity, developerAppShellEnv, finishDeveloperBundle, followWorkspace, installDeveloperAppLauncher, isDeveloperApp, nameDeveloperBundle, parseDeveloperAppConfig, readDeveloperAppConfig, runDeveloperApp };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** The exit code a developer app runner uses to ask its launcher to start it again. */
|
|
2
|
+
export declare const DEVELOPER_APP_RESTART_EXIT_CODE = 75;
|
|
3
|
+
export type WorkspaceRun = (command: string, args: readonly string[], cwd: string) => {
|
|
4
|
+
status: number | null;
|
|
5
|
+
output: string;
|
|
6
|
+
};
|
|
7
|
+
export type WorkspaceCheck = {
|
|
8
|
+
kind: 'current';
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'behind';
|
|
11
|
+
commits: number;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'conflicts';
|
|
14
|
+
branches: readonly string[];
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'unavailable';
|
|
17
|
+
reason: string;
|
|
18
|
+
};
|
|
19
|
+
/** Read `but pull --check`: how far behind the target is, and which branches would conflict. */
|
|
20
|
+
export declare function parsePullCheck(status: number | null, output: string): WorkspaceCheck;
|
|
21
|
+
export type WorkspaceUpdate = {
|
|
22
|
+
kind: 'updated';
|
|
23
|
+
commits: number;
|
|
24
|
+
dependenciesChanged: boolean;
|
|
25
|
+
/** Branches unapplied because they conflicted with the update. */
|
|
26
|
+
setAside: readonly string[];
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'current';
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'skipped';
|
|
31
|
+
reason: string;
|
|
32
|
+
dependenciesChanged: boolean;
|
|
33
|
+
setAside: readonly string[];
|
|
34
|
+
};
|
|
35
|
+
/** One follow step: set aside branches that would conflict, then update the checkout. */
|
|
36
|
+
export declare function updateWorkspace(checkout: string, run?: WorkspaceRun): WorkspaceUpdate;
|
|
37
|
+
/** Follow the checkout's target branch until stopped; returns the stop function. */
|
|
38
|
+
export declare function followWorkspace(options: {
|
|
39
|
+
checkout: string;
|
|
40
|
+
intervalMs?: number;
|
|
41
|
+
log?: (line: string) => void;
|
|
42
|
+
onDependenciesChanged: () => void;
|
|
43
|
+
/** Branches unapplied because they conflicted with main; tell the developer. */
|
|
44
|
+
onSetAside?: (branches: readonly string[]) => void;
|
|
45
|
+
run?: WorkspaceRun;
|
|
46
|
+
}): () => void;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { spawnSync } from "node:child_process";
|
|
5
|
+
// src/developer-app/workspace-follower.ts
|
|
6
|
+
/**
|
|
7
|
+
* Keeps the developer app's checkout a live dev environment: latest target branch (main)
|
|
8
|
+
* plus every in-progress branch applied. Every few minutes it runs `but pull`; source
|
|
9
|
+
* edits then reach the open window through hot reload and shell restarts, and a lockfile
|
|
10
|
+
* change asks the caller to reinstall and restart.
|
|
11
|
+
*
|
|
12
|
+
* A branch that would conflict with the update is unapplied first (GitButler keeps it,
|
|
13
|
+
* so it can be applied again once it is rebased) and reported, so one stale branch never
|
|
14
|
+
* blocks the update or ends up conflicted. A checkout without GitButler is left alone.
|
|
15
|
+
*/
|
|
16
|
+
/** The exit code a developer app runner uses to ask its launcher to start it again. */
|
|
17
|
+
var DEVELOPER_APP_RESTART_EXIT_CODE = 75;
|
|
18
|
+
/** Lockfiles whose change means dependencies must be reinstalled before running again. */
|
|
19
|
+
var LOCKFILES = [
|
|
20
|
+
"bun.lock",
|
|
21
|
+
"bun.lockb",
|
|
22
|
+
"package-lock.json",
|
|
23
|
+
"pnpm-lock.yaml",
|
|
24
|
+
"yarn.lock"
|
|
25
|
+
];
|
|
26
|
+
var defaultRun = (command, args, cwd) => {
|
|
27
|
+
const result = spawnSync(command, args, {
|
|
28
|
+
cwd,
|
|
29
|
+
encoding: "utf8",
|
|
30
|
+
timeout: 3e5
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
status: result.status,
|
|
34
|
+
output: `${result.stdout ?? ""}${result.stderr ?? ""}`
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
/** Read `but pull --check`: how far behind the target is, and which branches would conflict. */
|
|
38
|
+
function parsePullCheck(status, output) {
|
|
39
|
+
if (status !== 0) return {
|
|
40
|
+
kind: "unavailable",
|
|
41
|
+
reason: output.trim().split("\n")[0] ?? ""
|
|
42
|
+
};
|
|
43
|
+
const branches = [...output.matchAll(/\[conflict[^\]]*\]\s+(\S+)/g)].map((match) => match[1]);
|
|
44
|
+
if (branches.length) return {
|
|
45
|
+
kind: "conflicts",
|
|
46
|
+
branches
|
|
47
|
+
};
|
|
48
|
+
const behind = /Upstream:\s+(\d+) new commits?/.exec(output);
|
|
49
|
+
return behind && Number(behind[1]) > 0 ? {
|
|
50
|
+
kind: "behind",
|
|
51
|
+
commits: Number(behind[1])
|
|
52
|
+
} : { kind: "current" };
|
|
53
|
+
}
|
|
54
|
+
function lockfileDigest(checkout) {
|
|
55
|
+
const hash = createHash("sha256");
|
|
56
|
+
for (const name of LOCKFILES) {
|
|
57
|
+
const path = join(checkout, name);
|
|
58
|
+
if (existsSync(path)) hash.update(name).update(readFileSync(path));
|
|
59
|
+
}
|
|
60
|
+
return hash.digest("hex");
|
|
61
|
+
}
|
|
62
|
+
/** One follow step: set aside branches that would conflict, then update the checkout. */
|
|
63
|
+
function updateWorkspace(checkout, run = defaultRun) {
|
|
64
|
+
const probe = run("but", ["pull", "--check"], checkout);
|
|
65
|
+
let check = parsePullCheck(probe.status, probe.output);
|
|
66
|
+
const setAside = [];
|
|
67
|
+
const before = lockfileDigest(checkout);
|
|
68
|
+
const skipped = (reason) => ({
|
|
69
|
+
kind: "skipped",
|
|
70
|
+
reason,
|
|
71
|
+
dependenciesChanged: lockfileDigest(checkout) !== before,
|
|
72
|
+
setAside
|
|
73
|
+
});
|
|
74
|
+
if (check.kind === "conflicts") {
|
|
75
|
+
for (const branch of check.branches) {
|
|
76
|
+
if (run("but", ["unapply", branch], checkout).status !== 0) return skipped(`could not set aside ${branch}, which would conflict`);
|
|
77
|
+
setAside.push(branch);
|
|
78
|
+
}
|
|
79
|
+
const again = run("but", ["pull", "--check"], checkout);
|
|
80
|
+
check = parsePullCheck(again.status, again.output);
|
|
81
|
+
if (check.kind === "conflicts") return skipped(`${check.branches.join(", ")} would still conflict`);
|
|
82
|
+
}
|
|
83
|
+
if (check.kind === "current") return setAside.length ? {
|
|
84
|
+
kind: "updated",
|
|
85
|
+
commits: 0,
|
|
86
|
+
dependenciesChanged: lockfileDigest(checkout) !== before,
|
|
87
|
+
setAside
|
|
88
|
+
} : { kind: "current" };
|
|
89
|
+
if (check.kind === "unavailable") return skipped(check.reason);
|
|
90
|
+
const pulled = run("but", ["pull"], checkout);
|
|
91
|
+
if (pulled.status !== 0) return skipped(pulled.output.trim().split("\n")[0] ?? "but pull failed");
|
|
92
|
+
return {
|
|
93
|
+
kind: "updated",
|
|
94
|
+
commits: check.commits,
|
|
95
|
+
dependenciesChanged: lockfileDigest(checkout) !== before,
|
|
96
|
+
setAside
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/** Follow the checkout's target branch until stopped; returns the stop function. */
|
|
100
|
+
function followWorkspace(options) {
|
|
101
|
+
const { checkout, intervalMs = 3e5, log = () => {}, run = defaultRun } = options;
|
|
102
|
+
let lastSkip = "";
|
|
103
|
+
const tick = () => {
|
|
104
|
+
const update = updateWorkspace(checkout, run);
|
|
105
|
+
if (update.kind === "updated") {
|
|
106
|
+
lastSkip = "";
|
|
107
|
+
if (update.commits) log(`developer app: updated the workspace (${update.commits} new commits)`);
|
|
108
|
+
}
|
|
109
|
+
if (update.kind !== "current") {
|
|
110
|
+
if (update.setAside.length) {
|
|
111
|
+
log(`developer app: unapplied ${update.setAside.join(", ")}: conflicts with main; rebase it, then apply it again in GitButler`);
|
|
112
|
+
options.onSetAside?.(update.setAside);
|
|
113
|
+
}
|
|
114
|
+
if (update.dependenciesChanged) options.onDependenciesChanged();
|
|
115
|
+
}
|
|
116
|
+
if (update.kind === "skipped" && update.reason !== lastSkip) {
|
|
117
|
+
lastSkip = update.reason;
|
|
118
|
+
log(`developer app: workspace not updated: ${update.reason}`);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const timer = setInterval(tick, intervalMs);
|
|
122
|
+
timer.unref?.();
|
|
123
|
+
setTimeout(tick, 1e3).unref?.();
|
|
124
|
+
return () => clearInterval(timer);
|
|
125
|
+
}
|
|
126
|
+
export { DEVELOPER_APP_RESTART_EXIT_CODE, followWorkspace, parsePullCheck, updateWorkspace };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.41.1","commit":"b8b065ec637941693c8e7ddaf9058ea5f68b2f7b"}
|