droidsembly 0.4.0-beta.4 → 0.4.0-beta.6
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.it.md +16 -5
- package/README.md +15 -5
- package/bin/cubefarm.js +2 -296
- package/bin/droidsembly.js +304 -0
- package/bin/environment.d.ts +3 -0
- package/bin/environment.js +48 -0
- package/dist/assets/AccessibilitySettings-BLUQhCir.js +32 -0
- package/dist/assets/{AccessibilitySettings-HrzBDUTN.css → AccessibilitySettings-DGcxiTfe.css} +1 -1
- package/dist/assets/{AppViewer-CqGa1r0z.js → AppViewer-CkRhHzAg.js} +2 -2
- package/dist/assets/{Balloon-dO9J4khp.js → Balloon-CyA9jx7L.js} +1 -1
- package/dist/assets/{Batched-CmXZtCvQ.js → Batched-BnwN-jIb.js} +1 -1
- package/dist/assets/{Birds-D51xGT0l.js → Birds-T-cAlNXa.js} +1 -1
- package/dist/assets/{Blimp-C2c_AKRR.js → Blimp-D5lM1i8g.js} +1 -1
- package/dist/assets/{BufferGeometryUtils-Dcu0heeS.js → BufferGeometryUtils-BQuR3FyE.js} +1 -1
- package/dist/assets/{Duck-CzFiUF6U.js → Duck-Df57hNLp.js} +1 -1
- package/dist/assets/{Effects-DwOi-gSQ.js → Effects-BkJu9eYu.js} +1 -1
- package/dist/assets/{Fireworks-Cc2mGzPJ.js → Fireworks-BB1Mfdb3.js} +1 -1
- package/dist/assets/{Helicopter-ltB-x8hG.js → Helicopter-B5NObfW4.js} +1 -1
- package/dist/assets/{Hurricane-C2qHsRw4.js → Hurricane-CGsnFbNg.js} +1 -1
- package/dist/assets/{Kaiju-DPHVjFjg.js → Kaiju-5SPvHn_6.js} +1 -1
- package/dist/assets/{Meteors-CxcguXTJ.js → Meteors-rA1sR1A3.js} +1 -1
- package/dist/assets/{MissionConsole-BUE2mijT.js → MissionConsole-zJYkK_M1.js} +1 -1
- package/dist/assets/{Office-NV5zlSnK.js → Office-fRdJ34l-.js} +44 -44
- package/dist/assets/{PhotoPanel-CDqgU99Z.js → PhotoPanel-DiplEiL_.js} +1 -1
- package/dist/assets/{PhotoScene-RRXC4_Jv.js → PhotoScene-DG1ui0Av.js} +3 -3
- package/dist/assets/{Plane-BQB72TWZ.js → Plane-CtJDMF4A.js} +1 -1
- package/dist/assets/Pocket-x37KplGU.js +2 -0
- package/dist/assets/{Rainbow-DIpZi5-z.js → Rainbow-Bbqcvhxa.js} +1 -1
- package/dist/assets/{Roof-Cd9I0jtG.js → Roof-DP8gTSp6.js} +1 -1
- package/dist/assets/{Shell-DCqHgrm_.js → Shell-BzhH2Tnv.js} +2 -2
- package/dist/assets/{Skywriting-BH6FCdEl.js → Skywriting-CDweiNEJ.js} +1 -1
- package/dist/assets/TerminalView-CZkLeOi6.js +17 -0
- package/dist/assets/{ToyWorld--k4uqi9k.js → ToyWorld-ZLc2l8lQ.js} +1 -1
- package/dist/assets/{Ufo-C5cYunS9.js → Ufo-CQvPbWUN.js} +1 -1
- package/dist/assets/{Whale-BAXeezd8.js → Whale-Mz6Mfxvb.js} +1 -1
- package/dist/assets/all-AJNOOWx8.js +11 -0
- package/dist/assets/{bloomMarks-JYeAmd4d.js → bloomMarks-CWsszTY1.js} +1 -1
- package/dist/assets/{cheerRules-DvM2z9Qg.js → cheerRules-Bs7u6fhI.js} +1 -1
- package/dist/assets/{cityLayout-VU-ug-r6.js → cityLayout-1I0cF38a.js} +1 -1
- package/dist/assets/{dogState-Bm3YZHwy.js → dogState-DSYyIK7C.js} +1 -1
- package/dist/assets/{doors-D7Z3s-7W.js → doors-BUM4Izj_.js} +1 -1
- package/dist/assets/{gallery-CSWmy4Tf.js → gallery-BntMgHVx.js} +1 -1
- package/dist/assets/gate-B4Yyimy5.js +2 -0
- package/dist/assets/{index-COpmc42S.css → index-0ut5ekje.css} +1 -1
- package/dist/assets/index-BoDJkaEF.js +10 -0
- package/dist/assets/{instantReplay-FXf2kJ7B.js → instantReplay-D8hjR3t4.js} +1 -1
- package/dist/assets/{interact-BatJVhca.js → interact-Bj1zja21.js} +1 -1
- package/dist/assets/{jsx-runtime-CXW0f58S.js → jsx-runtime-CZP6s5wa.js} +1 -1
- package/dist/assets/{kit-D3twk12W.js → kit-iArIGJf-.js} +1 -1
- package/dist/assets/mic-B-UxYaQY.js +1 -0
- package/dist/assets/{photoMode-B8pRCF0O.js → photoMode-CRSRNKrX.js} +1 -1
- package/dist/assets/{pipeline-BgOS9JnJ.js → pipeline-DvDJ46O5.js} +1 -1
- package/dist/assets/{rapier-BvQbKz0M.js → rapier-Dtx9m4Xq.js} +1 -1
- package/dist/assets/{rig-BgSxc8mA.js → rig-Bs_tw8rH.js} +1 -1
- package/dist/assets/{speechLanguage-Cak8tdL0.js → speechLanguage-CSuv5EYa.js} +1 -1
- package/dist/assets/store-D1ymxjG0.js +5 -0
- package/dist/assets/useDayTime-Cn8OOG-d.js +1 -0
- package/dist/assets/useGraphics-CnMUzm0p.js +1 -0
- package/dist/assets/voiceMessages-CvKdLaYv.js +1 -0
- package/dist/assets/{weatherState-BQ3UU4vU.js → weatherState-BGsd5Mzz.js} +1 -1
- package/dist/index.html +4 -4
- package/dist-server/index.js +1668 -730
- package/dist-server/index.js.map +4 -4
- package/dist-server/ptyHost.js +6 -2
- package/dist-server/ptyHost.js.map +2 -2
- package/dist-server/skills/ceo-app-starter.md +53 -0
- package/docs/app-starter-provenance.md +25 -0
- package/docs/app-starter.md +107 -0
- package/package.json +5 -3
- package/dist/assets/AccessibilitySettings-6ZCswq5I.js +0 -30
- package/dist/assets/Pocket-CjK6fv97.js +0 -2
- package/dist/assets/TerminalView-CoH1yh6r.js +0 -17
- package/dist/assets/all-BsJ98bWd.js +0 -11
- package/dist/assets/gate-DwsbbSNS.js +0 -2
- package/dist/assets/index-D_Et7Vx8.js +0 -10
- package/dist/assets/mic-BJ0eYLIj.js +0 -1
- package/dist/assets/store-Buxt6UcJ.js +0 -5
- package/dist/assets/useDayTime-0ms3va3h.js +0 -1
- package/dist/assets/useGraphics-p7LAuvYj.js +0 -1
- package/dist/assets/voiceMessages-hO1SDnOS.js +0 -1
package/dist-server/ptyHost.js
CHANGED
|
@@ -10,6 +10,9 @@ import * as nodePty from "@lydell/node-pty";
|
|
|
10
10
|
var PTY_PROTOCOL = 1;
|
|
11
11
|
var encode = (m) => `${JSON.stringify(m)}
|
|
12
12
|
`;
|
|
13
|
+
function ptyExitCode(value) {
|
|
14
|
+
return typeof value === "number" && Number.isSafeInteger(value) ? value : -1;
|
|
15
|
+
}
|
|
13
16
|
function readMessages(sock, onMessage) {
|
|
14
17
|
let buf = "";
|
|
15
18
|
sock.setEncoding("utf8");
|
|
@@ -86,9 +89,10 @@ function start(m) {
|
|
|
86
89
|
while (h.bytes > BACKLOG_BYTES && h.backlog.length > 1) h.bytes -= h.backlog.shift().length;
|
|
87
90
|
});
|
|
88
91
|
proc.onExit(({ exitCode }) => {
|
|
89
|
-
h.exit = exitCode;
|
|
92
|
+
h.exit = ptyExitCode(exitCode);
|
|
93
|
+
if (h.exit !== exitCode) note("terminal exit status unavailable; reporting unknown failure (-1)");
|
|
90
94
|
quietly(() => proc.kill());
|
|
91
|
-
if (h.attached && office) send({ op: "exit", id: m.id, code:
|
|
95
|
+
if (h.attached && office) send({ op: "exit", id: m.id, code: h.exit });
|
|
92
96
|
if (h.attached && office || h.killed) held.delete(m.id);
|
|
93
97
|
});
|
|
94
98
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../server/ptyHost.ts", "../server/ptyProtocol.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from 'node:fs';\nimport http from 'node:http';\nimport net from 'node:net';\nimport path from 'node:path';\nimport { spawn } from 'node:child_process';\nimport * as nodePty from '@lydell/node-pty';\nimport { encode, PTY_PROTOCOL, readMessages, type FromHost, type HeldPty, type ToHost } from './ptyProtocol.ts';\n\n// The office's terminal keeper: a small process of its own that runs the agents' CLIs in pseudo-terminals, so they\n// keep working while the office restarts (an update, a crash, a code change in development). The office connects over\n// a local socket (one office at a time), starts and drives CLIs through it and, when it comes back, picks up the ones\n// still running. The CLIs' hooks come in here too and wait while the office is away, so none is lost and none fails.\n//\n// node ptyHost.js launch <socket> <secret file> starts a keeper outside the caller's process tree, then exits\n// node ptyHost.js serve <socket> <secret file> is the keeper\n\n/** Output kept per terminal while no office is listening. */\nconst BACKLOG_BYTES = 2 * 1024 * 1024;\n/** A hook waits this long for an office (the CLIs are told 120 s). */\nconst HOOK_WAIT_MS = 110_000;\n/** With no office for this long, nobody is coming back: the terminals are stopped. */\nconst ORPHAN_MS = 10 * 60_000;\n/** Nothing left to keep and no office: the keeper goes. */\nconst IDLE_EXIT_MS = 60_000;\n\nconst [mode, socketPath, secretFile] = process.argv.slice(2);\n\nif (mode === 'launch') {\n // A detached child whose parent exits at once: the office's process tree (which the launcher kills on a restart)\n // doesn't include it, and on Windows nothing ties it to a console window.\n spawn(process.execPath, [...process.execArgv, process.argv[1], 'serve', socketPath, secretFile], { detached: true, stdio: 'ignore', windowsHide: true }).unref();\n process.exit(0);\n}\n\nconst logFile = path.join(path.dirname(secretFile), 'pty-host.log');\nconst note = (text: string) => fs.appendFile(logFile, `${new Date().toISOString()} ${text}\\n`, () => undefined);\nprocess.on('uncaughtException', (err) => note(`uncaught: ${err.stack ?? err}`));\nfor (const sig of ['SIGINT', 'SIGHUP', 'SIGBREAK'] as const) process.on(sig, () => undefined); // the office's console isn't ours\n\nconst secret = fs.readFileSync(secretFile, 'utf8').trim();\n\ninterface Held {\n proc: nodePty.IPty;\n meta: unknown;\n /** An office is taking this terminal's output right now. */\n attached: boolean;\n backlog: string[];\n bytes: number;\n exit: number | null;\n /** The office stopped it: nobody needs to hear how it ended. */\n killed: boolean;\n}\nconst held = new Map<string, Held>();\nlet office: net.Socket | null = null;\nlet officeLeft = Date.now();\nlet hooksOpen = false; // the connected office has picked up its terminals and takes hooks\n\nconst send = (m: FromHost) => {\n if (office && !office.destroyed) office.write(encode(m));\n};\n\nfunction killTree(pid: number) {\n if (process.platform === 'win32') {\n spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' }).once('error', () => undefined);\n return;\n }\n try {\n process.kill(-pid, 'SIGTERM'); // the CLI leads its own session: take its MCP servers and tools with it\n } catch {\n try {\n process.kill(pid, 'SIGTERM');\n } catch {\n // already gone\n }\n }\n}\n\n// ---------- terminals ----------\n\nfunction start(m: Extract<ToHost, { op: 'spawn' }>) {\n let proc: nodePty.IPty;\n try {\n // Windows' own console host lingers after each CLI exits (one conhost.exe per terminal, forever in a keeper that\n // outlives restarts); the one node-pty ships goes with its terminal.\n proc = nodePty.spawn(m.file, m.args, { name: 'xterm-256color', cols: m.cols, rows: m.rows, cwd: m.cwd, env: m.env, useConptyDll: true });\n } catch (err) {\n send({ op: 'failed', id: m.id, error: (err as Error).message });\n return;\n }\n const h: Held = { proc, meta: m.meta, attached: true, backlog: [], bytes: 0, exit: null, killed: false };\n held.set(m.id, h);\n send({ op: 'spawned', id: m.id, pid: proc.pid });\n proc.onData((data) => {\n if (h.attached && office) return send({ op: 'data', id: m.id, data });\n h.backlog.push(data);\n h.bytes += data.length;\n while (h.bytes > BACKLOG_BYTES && h.backlog.length > 1) h.bytes -= h.backlog.shift()!.length;\n });\n proc.onExit(({ exitCode }) => {\n h.exit = exitCode;\n quietly(() => proc.kill()); // on Windows the terminal's console host (conhost.exe) outlives the CLI until then\n if (h.attached && office) send({ op: 'exit', id: m.id, code: exitCode });\n if ((h.attached && office) || h.killed) held.delete(m.id);\n });\n}\n\nfunction attach(id: string) {\n const h = held.get(id);\n if (!h) return send({ op: 'exit', id, code: -1 });\n h.attached = true;\n if (h.backlog.length) send({ op: 'data', id, data: h.backlog.join('') });\n h.backlog = [];\n h.bytes = 0;\n if (h.exit !== null) {\n send({ op: 'exit', id, code: h.exit });\n held.delete(id);\n }\n}\n\nfunction stopAll() {\n for (const h of held.values()) if (h.exit === null) killTree(h.proc.pid);\n}\n\n// ---------- hooks: CLIs call here, the office answers ----------\n\ninterface Waiting {\n token: string;\n body: unknown;\n res: http.ServerResponse;\n timer: NodeJS.Timeout;\n sent: boolean;\n}\nconst waiting = new Map<number, Waiting>();\nlet nextRid = 1;\n\nfunction answer(rid: number, reply: unknown) {\n const w = waiting.get(rid);\n if (!w) return;\n waiting.delete(rid);\n clearTimeout(w.timer);\n if (!w.res.writableEnded) w.res.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(reply ?? {}));\n}\n\n/** Hooks that waited for an office go to the one that's ready (again, if the office before it went without answering). */\nfunction passHooks() {\n if (!office || !hooksOpen) return;\n for (const [rid, w] of waiting) {\n if (w.sent) continue;\n w.sent = true;\n send({ op: 'hook', rid, token: w.token, body: w.body });\n }\n}\n\nconst hooks = http.createServer((req, res) => {\n const token = req.method === 'POST' ? req.url?.match(/^\\/api\\/hooks\\/([\\w-]+)$/)?.[1] : undefined;\n if (!token) return void res.writeHead(404).end();\n const chunks: Buffer[] = [];\n let size = 0;\n req.on('data', (c: Buffer) => {\n size += c.length;\n if (size <= 64 * 1024 * 1024) chunks.push(c);\n });\n req.on('end', () => {\n let body: unknown = {};\n try {\n body = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}');\n } catch {\n // not JSON: an empty hook\n }\n const rid = nextRid++;\n waiting.set(rid, { token, body, res, timer: setTimeout(() => answer(rid, {}), HOOK_WAIT_MS), sent: false });\n passHooks();\n });\n});\n\n// ---------- the office ----------\n\nfunction connected(sock: net.Socket) {\n let helloed = false;\n readMessages<ToHost>(sock, (m) => {\n if (!helloed) {\n if (m.op !== 'hello' || m.secret !== secret) return void sock.destroy();\n helloed = true;\n if (office && office !== sock) office.destroy();\n office = sock;\n hooksOpen = false;\n const ptys: HeldPty[] = [...held].map(([id, h]) => ({ id, pid: h.proc.pid, meta: h.meta, exit: h.exit }));\n send({ op: 'ready', version: PTY_PROTOCOL, hookPort: (hooks.address() as net.AddressInfo).port, ptys, pid: process.pid });\n return;\n }\n const h = 'id' in m ? held.get(m.id) : undefined;\n switch (m.op) {\n case 'spawn':\n return start(m);\n case 'attach':\n return attach(m.id);\n case 'write':\n return void (h && h.exit === null && quietly(() => h.proc.write(m.data)));\n case 'resize':\n return void (h && h.exit === null && quietly(() => h.proc.resize(m.cols, m.rows)));\n case 'meta':\n if (h) h.meta = m.meta;\n return;\n case 'kill':\n if (h) h.killed = true;\n if (h?.exit === null) killTree(h.proc.pid);\n else if (h) held.delete(m.id);\n return;\n case 'hooksReady':\n hooksOpen = true;\n return passHooks();\n case 'hookReply':\n return answer(m.rid, m.answer);\n case 'shutdown':\n stopAll();\n setTimeout(() => process.exit(0), 3000);\n return;\n }\n });\n sock.on('error', () => undefined);\n sock.on('close', () => {\n if (office !== sock) return;\n office = null;\n officeLeft = Date.now();\n for (const h of held.values()) h.attached = false;\n for (const w of waiting.values()) w.sent = false; // unanswered: the next office gets them\n });\n}\n\n/** A pseudo-terminal whose CLI just died throws on writes and resizes before it reports the exit. */\nfunction quietly(fn: () => void) {\n try {\n fn();\n } catch {\n // its exit is on the way\n }\n}\n\nconst server = net.createServer(connected);\nserver.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code !== 'EADDRINUSE' || process.platform === 'win32') {\n note(`cannot listen on ${socketPath}: ${err.message}`);\n process.exit(1);\n }\n // A Unix socket file left behind: take it over, unless a keeper still answers on it.\n const probe = net.connect(socketPath, () => {\n probe.destroy();\n process.exit(0);\n });\n probe.on('error', () => {\n fs.rmSync(socketPath, { force: true });\n server.listen(socketPath);\n });\n});\n\nhooks.listen(0, '127.0.0.1', () => server.listen(socketPath));\n\nlet orphaned = false;\nsetInterval(() => {\n if (office) return void (orphaned = false);\n const away = Date.now() - officeLeft;\n if (away > ORPHAN_MS) {\n for (const [id, h] of held) if (h.exit !== null) held.delete(id);\n if (held.size && !orphaned) {\n orphaned = true;\n note(`no office for ${Math.round(away / 60_000)} min: stopping ${held.size} terminal(s)`);\n stopAll();\n }\n }\n if (held.size === 0 && away > IDLE_EXIT_MS) process.exit(0);\n}, 10_000).unref();\n", "import crypto from 'node:crypto';\nimport path from 'node:path';\nimport type { Socket } from 'node:net';\n\n// What the office and its terminal keeper (ptyHost.ts) say to each other over their local socket: one JSON message\n// per line. Kept free of the rest of the server so the keeper stays small and starts fast.\n\n/** Bumped when the messages change: an office that finds a keeper on another version replaces it. */\nexport const PTY_PROTOCOL = 1;\n\n/** A terminal the keeper holds, as it reports it to an office that (re)connects. */\nexport interface HeldPty {\n id: string;\n pid: number;\n /** What the office stored with it (who it belongs to, its session). */\n meta: unknown;\n /** The CLI has exited (while no office was listening): its exit code. */\n exit: number | null;\n}\n\nexport type ToHost =\n | { op: 'hello'; secret: string; version: number }\n | { op: 'hooksReady' } // the office has picked up its terminals: hooks that waited for it can come in now\n | { op: 'spawn'; id: string; file: string; args: string[]; cwd: string; env: Record<string, string>; cols: number; rows: number; meta: unknown }\n | { op: 'attach'; id: string } // an office picking up a terminal it found: what it missed, then everything live\n | { op: 'write'; id: string; data: string }\n | { op: 'resize'; id: string; cols: number; rows: number }\n | { op: 'meta'; id: string; meta: unknown }\n | { op: 'kill'; id: string }\n | { op: 'hookReply'; rid: number; answer: unknown }\n | { op: 'shutdown' }; // stop every terminal and exit (a keeper on another version)\n\nexport type FromHost =\n | { op: 'ready'; version: number; hookPort: number; ptys: HeldPty[]; pid?: number }\n | { op: 'spawned'; id: string; pid: number }\n | { op: 'failed'; id: string; error: string }\n | { op: 'data'; id: string; data: string }\n | { op: 'exit'; id: string; code: number }\n | { op: 'hook'; rid: number; token: string; body: unknown };\n\n/** The keeper's socket for an office home: a named pipe on Windows, a Unix socket in the home elsewhere. */\nexport function hostSocket(home: string, platform = process.platform): string {\n if (platform !== 'win32') return path.join(home, 'pty.sock');\n const tag = crypto.createHash('sha1').update(path.resolve(home).toLowerCase()).digest('hex').slice(0, 12);\n return `\\\\\\\\.\\\\pipe\\\\cubefarm-pty-${tag}`;\n}\n\nexport const encode = (m: ToHost | FromHost) => `${JSON.stringify(m)}\\n`;\n\n/** Calls back with each message a socket sends (newline-delimited JSON); a line that isn't JSON is skipped. */\nexport function readMessages<T>(sock: Socket, onMessage: (m: T) => void) {\n let buf = '';\n sock.setEncoding('utf8');\n sock.on('data', (chunk: string) => {\n buf += chunk;\n let nl: number;\n while ((nl = buf.indexOf('\\n')) >= 0) {\n const line = buf.slice(0, nl);\n buf = buf.slice(nl + 1);\n if (!line) continue;\n let m: T;\n try {\n m = JSON.parse(line) as T;\n } catch {\n continue;\n }\n onMessage(m);\n }\n });\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,SAAS;AAChB,OAAO,UAAU;AACjB,SAAS,aAAa;AACtB,YAAY,aAAa;;;ACGlB,IAAM,eAAe;AAuCrB,IAAM,SAAS,CAAC,MAAyB,GAAG,KAAK,UAAU,CAAC,CAAC;AAAA;
|
|
4
|
+
"sourcesContent": ["import fs from 'node:fs';\nimport http from 'node:http';\nimport net from 'node:net';\nimport path from 'node:path';\nimport { spawn } from 'node:child_process';\nimport * as nodePty from '@lydell/node-pty';\nimport { encode, PTY_PROTOCOL, ptyExitCode, readMessages, type FromHost, type HeldPty, type ToHost } from './ptyProtocol.ts';\n\n// The office's terminal keeper: a small process of its own that runs the agents' CLIs in pseudo-terminals, so they\n// keep working while the office restarts (an update, a crash, a code change in development). The office connects over\n// a local socket (one office at a time), starts and drives CLIs through it and, when it comes back, picks up the ones\n// still running. The CLIs' hooks come in here too and wait while the office is away, so none is lost and none fails.\n//\n// node ptyHost.js launch <socket> <secret file> starts a keeper outside the caller's process tree, then exits\n// node ptyHost.js serve <socket> <secret file> is the keeper\n\n/** Output kept per terminal while no office is listening. */\nconst BACKLOG_BYTES = 2 * 1024 * 1024;\n/** A hook waits this long for an office (the CLIs are told 120 s). */\nconst HOOK_WAIT_MS = 110_000;\n/** With no office for this long, nobody is coming back: the terminals are stopped. */\nconst ORPHAN_MS = 10 * 60_000;\n/** Nothing left to keep and no office: the keeper goes. */\nconst IDLE_EXIT_MS = 60_000;\n\nconst [mode, socketPath, secretFile] = process.argv.slice(2);\n\nif (mode === 'launch') {\n // A detached child whose parent exits at once: the office's process tree (which the launcher kills on a restart)\n // doesn't include it, and on Windows nothing ties it to a console window.\n spawn(process.execPath, [...process.execArgv, process.argv[1], 'serve', socketPath, secretFile], { detached: true, stdio: 'ignore', windowsHide: true }).unref();\n process.exit(0);\n}\n\nconst logFile = path.join(path.dirname(secretFile), 'pty-host.log');\nconst note = (text: string) => fs.appendFile(logFile, `${new Date().toISOString()} ${text}\\n`, () => undefined);\nprocess.on('uncaughtException', (err) => note(`uncaught: ${err.stack ?? err}`));\nfor (const sig of ['SIGINT', 'SIGHUP', 'SIGBREAK'] as const) process.on(sig, () => undefined); // the office's console isn't ours\n\nconst secret = fs.readFileSync(secretFile, 'utf8').trim();\n\ninterface Held {\n proc: nodePty.IPty;\n meta: unknown;\n /** An office is taking this terminal's output right now. */\n attached: boolean;\n backlog: string[];\n bytes: number;\n exit: number | null;\n /** The office stopped it: nobody needs to hear how it ended. */\n killed: boolean;\n}\nconst held = new Map<string, Held>();\nlet office: net.Socket | null = null;\nlet officeLeft = Date.now();\nlet hooksOpen = false; // the connected office has picked up its terminals and takes hooks\n\nconst send = (m: FromHost) => {\n if (office && !office.destroyed) office.write(encode(m));\n};\n\nfunction killTree(pid: number) {\n if (process.platform === 'win32') {\n spawn('taskkill', ['/PID', String(pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' }).once('error', () => undefined);\n return;\n }\n try {\n process.kill(-pid, 'SIGTERM'); // the CLI leads its own session: take its MCP servers and tools with it\n } catch {\n try {\n process.kill(pid, 'SIGTERM');\n } catch {\n // already gone\n }\n }\n}\n\n// ---------- terminals ----------\n\nfunction start(m: Extract<ToHost, { op: 'spawn' }>) {\n let proc: nodePty.IPty;\n try {\n // Windows' own console host lingers after each CLI exits (one conhost.exe per terminal, forever in a keeper that\n // outlives restarts); the one node-pty ships goes with its terminal.\n proc = nodePty.spawn(m.file, m.args, { name: 'xterm-256color', cols: m.cols, rows: m.rows, cwd: m.cwd, env: m.env, useConptyDll: true });\n } catch (err) {\n send({ op: 'failed', id: m.id, error: (err as Error).message });\n return;\n }\n const h: Held = { proc, meta: m.meta, attached: true, backlog: [], bytes: 0, exit: null, killed: false };\n held.set(m.id, h);\n send({ op: 'spawned', id: m.id, pid: proc.pid });\n proc.onData((data) => {\n if (h.attached && office) return send({ op: 'data', id: m.id, data });\n h.backlog.push(data);\n h.bytes += data.length;\n while (h.bytes > BACKLOG_BYTES && h.backlog.length > 1) h.bytes -= h.backlog.shift()!.length;\n });\n proc.onExit(({ exitCode }) => {\n h.exit = ptyExitCode(exitCode);\n if (h.exit !== exitCode) note('terminal exit status unavailable; reporting unknown failure (-1)');\n quietly(() => proc.kill()); // on Windows the terminal's console host (conhost.exe) outlives the CLI until then\n if (h.attached && office) send({ op: 'exit', id: m.id, code: h.exit });\n if ((h.attached && office) || h.killed) held.delete(m.id);\n });\n}\n\nfunction attach(id: string) {\n const h = held.get(id);\n if (!h) return send({ op: 'exit', id, code: -1 });\n h.attached = true;\n if (h.backlog.length) send({ op: 'data', id, data: h.backlog.join('') });\n h.backlog = [];\n h.bytes = 0;\n if (h.exit !== null) {\n send({ op: 'exit', id, code: h.exit });\n held.delete(id);\n }\n}\n\nfunction stopAll() {\n for (const h of held.values()) if (h.exit === null) killTree(h.proc.pid);\n}\n\n// ---------- hooks: CLIs call here, the office answers ----------\n\ninterface Waiting {\n token: string;\n body: unknown;\n res: http.ServerResponse;\n timer: NodeJS.Timeout;\n sent: boolean;\n}\nconst waiting = new Map<number, Waiting>();\nlet nextRid = 1;\n\nfunction answer(rid: number, reply: unknown) {\n const w = waiting.get(rid);\n if (!w) return;\n waiting.delete(rid);\n clearTimeout(w.timer);\n if (!w.res.writableEnded) w.res.writeHead(200, { 'content-type': 'application/json' }).end(JSON.stringify(reply ?? {}));\n}\n\n/** Hooks that waited for an office go to the one that's ready (again, if the office before it went without answering). */\nfunction passHooks() {\n if (!office || !hooksOpen) return;\n for (const [rid, w] of waiting) {\n if (w.sent) continue;\n w.sent = true;\n send({ op: 'hook', rid, token: w.token, body: w.body });\n }\n}\n\nconst hooks = http.createServer((req, res) => {\n const token = req.method === 'POST' ? req.url?.match(/^\\/api\\/hooks\\/([\\w-]+)$/)?.[1] : undefined;\n if (!token) return void res.writeHead(404).end();\n const chunks: Buffer[] = [];\n let size = 0;\n req.on('data', (c: Buffer) => {\n size += c.length;\n if (size <= 64 * 1024 * 1024) chunks.push(c);\n });\n req.on('end', () => {\n let body: unknown = {};\n try {\n body = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}');\n } catch {\n // not JSON: an empty hook\n }\n const rid = nextRid++;\n waiting.set(rid, { token, body, res, timer: setTimeout(() => answer(rid, {}), HOOK_WAIT_MS), sent: false });\n passHooks();\n });\n});\n\n// ---------- the office ----------\n\nfunction connected(sock: net.Socket) {\n let helloed = false;\n readMessages<ToHost>(sock, (m) => {\n if (!helloed) {\n if (m.op !== 'hello' || m.secret !== secret) return void sock.destroy();\n helloed = true;\n if (office && office !== sock) office.destroy();\n office = sock;\n hooksOpen = false;\n const ptys: HeldPty[] = [...held].map(([id, h]) => ({ id, pid: h.proc.pid, meta: h.meta, exit: h.exit }));\n send({ op: 'ready', version: PTY_PROTOCOL, hookPort: (hooks.address() as net.AddressInfo).port, ptys, pid: process.pid });\n return;\n }\n const h = 'id' in m ? held.get(m.id) : undefined;\n switch (m.op) {\n case 'spawn':\n return start(m);\n case 'attach':\n return attach(m.id);\n case 'write':\n return void (h && h.exit === null && quietly(() => h.proc.write(m.data)));\n case 'resize':\n return void (h && h.exit === null && quietly(() => h.proc.resize(m.cols, m.rows)));\n case 'meta':\n if (h) h.meta = m.meta;\n return;\n case 'kill':\n if (h) h.killed = true;\n if (h?.exit === null) killTree(h.proc.pid);\n else if (h) held.delete(m.id);\n return;\n case 'hooksReady':\n hooksOpen = true;\n return passHooks();\n case 'hookReply':\n return answer(m.rid, m.answer);\n case 'shutdown':\n stopAll();\n setTimeout(() => process.exit(0), 3000);\n return;\n }\n });\n sock.on('error', () => undefined);\n sock.on('close', () => {\n if (office !== sock) return;\n office = null;\n officeLeft = Date.now();\n for (const h of held.values()) h.attached = false;\n for (const w of waiting.values()) w.sent = false; // unanswered: the next office gets them\n });\n}\n\n/** A pseudo-terminal whose CLI just died throws on writes and resizes before it reports the exit. */\nfunction quietly(fn: () => void) {\n try {\n fn();\n } catch {\n // its exit is on the way\n }\n}\n\nconst server = net.createServer(connected);\nserver.on('error', (err: NodeJS.ErrnoException) => {\n if (err.code !== 'EADDRINUSE' || process.platform === 'win32') {\n note(`cannot listen on ${socketPath}: ${err.message}`);\n process.exit(1);\n }\n // A Unix socket file left behind: take it over, unless a keeper still answers on it.\n const probe = net.connect(socketPath, () => {\n probe.destroy();\n process.exit(0);\n });\n probe.on('error', () => {\n fs.rmSync(socketPath, { force: true });\n server.listen(socketPath);\n });\n});\n\nhooks.listen(0, '127.0.0.1', () => server.listen(socketPath));\n\nlet orphaned = false;\nsetInterval(() => {\n if (office) return void (orphaned = false);\n const away = Date.now() - officeLeft;\n if (away > ORPHAN_MS) {\n for (const [id, h] of held) if (h.exit !== null) held.delete(id);\n if (held.size && !orphaned) {\n orphaned = true;\n note(`no office for ${Math.round(away / 60_000)} min: stopping ${held.size} terminal(s)`);\n stopAll();\n }\n }\n if (held.size === 0 && away > IDLE_EXIT_MS) process.exit(0);\n}, 10_000).unref();\n", "import crypto from 'node:crypto';\nimport path from 'node:path';\nimport type { Socket } from 'node:net';\n\n// What the office and its terminal keeper (ptyHost.ts) say to each other over their local socket: one JSON message\n// per line. Kept free of the rest of the server so the keeper stays small and starts fast.\n\n/** Bumped when the messages change: an office that finds a keeper on another version replaces it. */\nexport const PTY_PROTOCOL = 1;\n\n/** A terminal the keeper holds, as it reports it to an office that (re)connects. */\nexport interface HeldPty {\n id: string;\n pid: number;\n /** What the office stored with it (who it belongs to, its session). */\n meta: unknown;\n /** The CLI has exited (while no office was listening): its exit code. */\n exit: number | null;\n}\n\nexport type ToHost =\n | { op: 'hello'; secret: string; version: number }\n | { op: 'hooksReady' } // the office has picked up its terminals: hooks that waited for it can come in now\n | { op: 'spawn'; id: string; file: string; args: string[]; cwd: string; env: Record<string, string>; cols: number; rows: number; meta: unknown }\n | { op: 'attach'; id: string } // an office picking up a terminal it found: what it missed, then everything live\n | { op: 'write'; id: string; data: string }\n | { op: 'resize'; id: string; cols: number; rows: number }\n | { op: 'meta'; id: string; meta: unknown }\n | { op: 'kill'; id: string }\n | { op: 'hookReply'; rid: number; answer: unknown }\n | { op: 'shutdown' }; // stop every terminal and exit (a keeper on another version)\n\nexport type FromHost =\n | { op: 'ready'; version: number; hookPort: number; ptys: HeldPty[]; pid?: number }\n | { op: 'spawned'; id: string; pid: number }\n | { op: 'failed'; id: string; error: string }\n | { op: 'data'; id: string; data: string }\n | { op: 'exit'; id: string; code: number }\n | { op: 'hook'; rid: number; token: string; body: unknown };\n\n/** The keeper's socket for an office home: a named pipe on Windows, a Unix socket in the home elsewhere. */\nexport function hostSocket(home: string, platform = process.platform): string {\n if (platform !== 'win32') return path.join(home, 'pty.sock');\n const tag = crypto.createHash('sha1').update(path.resolve(home).toLowerCase()).digest('hex').slice(0, 12);\n return `\\\\\\\\.\\\\pipe\\\\cubefarm-pty-${tag}`;\n}\n\nexport const encode = (m: ToHost | FromHost) => `${JSON.stringify(m)}\\n`;\n\n/** A missing native/legacy exit status must never disappear from JSON or be\n * mistaken for success. -1 already represents an unverified/failed terminal.\n * Do not invent a successful code or guess the CLI's intended status.\n */\nexport function ptyExitCode(value: unknown): number {\n return typeof value === 'number' && Number.isSafeInteger(value) ? value : -1;\n}\n\n/** Calls back with each message a socket sends (newline-delimited JSON); a line that isn't JSON is skipped. */\nexport function readMessages<T>(sock: Socket, onMessage: (m: T) => void) {\n let buf = '';\n sock.setEncoding('utf8');\n sock.on('data', (chunk: string) => {\n buf += chunk;\n let nl: number;\n while ((nl = buf.indexOf('\\n')) >= 0) {\n const line = buf.slice(0, nl);\n buf = buf.slice(nl + 1);\n if (!line) continue;\n let m: T;\n try {\n m = JSON.parse(line) as T;\n } catch {\n continue;\n }\n onMessage(m);\n }\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,SAAS;AAChB,OAAO,UAAU;AACjB,SAAS,aAAa;AACtB,YAAY,aAAa;;;ACGlB,IAAM,eAAe;AAuCrB,IAAM,SAAS,CAAC,MAAyB,GAAG,KAAK,UAAU,CAAC,CAAC;AAAA;AAM7D,SAAS,YAAY,OAAwB;AAClD,SAAO,OAAO,UAAU,YAAY,OAAO,cAAc,KAAK,IAAI,QAAQ;AAC5E;AAGO,SAAS,aAAgB,MAAc,WAA2B;AACvE,MAAI,MAAM;AACV,OAAK,YAAY,MAAM;AACvB,OAAK,GAAG,QAAQ,CAAC,UAAkB;AACjC,WAAO;AACP,QAAI;AACJ,YAAQ,KAAK,IAAI,QAAQ,IAAI,MAAM,GAAG;AACpC,YAAM,OAAO,IAAI,MAAM,GAAG,EAAE;AAC5B,YAAM,IAAI,MAAM,KAAK,CAAC;AACtB,UAAI,CAAC,KAAM;AACX,UAAI;AACJ,UAAI;AACF,YAAI,KAAK,MAAM,IAAI;AAAA,MACrB,QAAQ;AACN;AAAA,MACF;AACA,gBAAU,CAAC;AAAA,IACb;AAAA,EACF,CAAC;AACH;;;AD5DA,IAAM,gBAAgB,IAAI,OAAO;AAEjC,IAAM,eAAe;AAErB,IAAM,YAAY,KAAK;AAEvB,IAAM,eAAe;AAErB,IAAM,CAAC,MAAM,YAAY,UAAU,IAAI,QAAQ,KAAK,MAAM,CAAC;AAE3D,IAAI,SAAS,UAAU;AAGrB,QAAM,QAAQ,UAAU,CAAC,GAAG,QAAQ,UAAU,QAAQ,KAAK,CAAC,GAAG,SAAS,YAAY,UAAU,GAAG,EAAE,UAAU,MAAM,OAAO,UAAU,aAAa,KAAK,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rC,WAAO,OAAO,UAAU;AAAA,EAC1B,CAAC;AACH,CAAC;AAED,MAAM,OAAO,GAAG,aAAa,MAAM,OAAO,OAAO,UAAU,CAAC;AAE5D,IAAI,WAAW;AACf,YAAY,MAAM;AAChB,MAAI,OAAQ,QAAO,MAAM,WAAW;AACpC,QAAM,OAAO,KAAK,IAAI,IAAI;AAC1B,MAAI,OAAO,WAAW;AACpB,eAAW,CAAC,IAAI,CAAC,KAAK,KAAM,KAAI,EAAE,SAAS,KAAM,MAAK,OAAO,EAAE;AAC/D,QAAI,KAAK,QAAQ,CAAC,UAAU;AAC1B,iBAAW;AACX,WAAK,iBAAiB,KAAK,MAAM,OAAO,GAAM,CAAC,kBAAkB,KAAK,IAAI,cAAc;AACxF,cAAQ;AAAA,IACV;AAAA,EACF;AACA,MAAI,KAAK,SAAS,KAAK,OAAO,aAAc,SAAQ,KAAK,CAAC;AAC5D,GAAG,GAAM,EAAE,MAAM;",
|
|
6
6
|
"names": ["h"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# CEO app-starter — planning only
|
|
2
|
+
|
|
3
|
+
Original Droidsembly instructions, authored from the manager's A5 requirements.
|
|
4
|
+
Only for a local CEO new-app job; never add these to worker sessions.
|
|
5
|
+
|
|
6
|
+
Use only this project's persisted transcript, decisions and revision. Do not read or
|
|
7
|
+
write global CEO notes for this job. Do not infer facts from another project or a
|
|
8
|
+
previous CLI conversation. Reply in the configured office language.
|
|
9
|
+
|
|
10
|
+
Interview adaptively: a short recap, then one relevant question, then finish this
|
|
11
|
+
turn. Do not wait in a running process for a reply. Reuse known answers. Clarify
|
|
12
|
+
the problem, intended users and ownership, their main actions, the data model,
|
|
13
|
+
the minimum useful first version, explicit exclusions and the intended design.
|
|
14
|
+
Consider authentication, uploads, email, accessibility, privacy, payments or AI
|
|
15
|
+
only when pertinent; do not turn the conversation into a fixed questionnaire.
|
|
16
|
+
|
|
17
|
+
Before recommending ANY database, establish separately:
|
|
18
|
+
1. where workers will work (this computer or Upstash Boxes);
|
|
19
|
+
2. where isolated tests and previews will run;
|
|
20
|
+
3. where the finished application will be published;
|
|
21
|
+
4. whether synthetic examples suffice or existing data is needed;
|
|
22
|
+
5. whether that data must stay local or may safely be copied.
|
|
23
|
+
|
|
24
|
+
SQLite and Docker do not imply local workers. Synthetic seed data can be reproduced
|
|
25
|
+
in each Box. Existing non-transferable local data requires local workers: explain
|
|
26
|
+
why the computer must remain on and request confirmation. For existing data with
|
|
27
|
+
Box workers, discuss anonymized copies or a safely reachable service. Never expose
|
|
28
|
+
a local database publicly. Neon is an option, not a requirement. Do not ask for
|
|
29
|
+
credentials, DSNs, private data or dumps; record only non-secret descriptions.
|
|
30
|
+
Tests and migrations use separate disposable environments, never production as a
|
|
31
|
+
laboratory. Read-only consultation of existing data is not permission to migrate it.
|
|
32
|
+
Docker availability is a prerequisite to verify, not a fact inferred from a choice.
|
|
33
|
+
SQLite to Postgres may require application changes and tested migrations.
|
|
34
|
+
|
|
35
|
+
Recommend a suitable stack with reasons and alternatives; respect the user's
|
|
36
|
+
preferences. No mandatory framework, authentication library or provider. Ask about
|
|
37
|
+
visual style, supplied branding, mobile/desktop needs and accessible interaction.
|
|
38
|
+
|
|
39
|
+
When the requirements are sufficiently clear, call update_app_plan with the
|
|
40
|
+
complete structured plan: requirements, users, data model, MVP/exclusions, stack
|
|
41
|
+
and alternatives, design, all environments and data handling, isolation,
|
|
42
|
+
prerequisites/risks, and at most 12 cohesive worker tasks. Each task has a stable
|
|
43
|
+
ID, exact title/body with acceptance criteria and dependencies by task ID.
|
|
44
|
+
Include executable setup, migrations, seeds, configuration and verification as
|
|
45
|
+
worker tasks where needed. Keep dependency chains to two steps at most.
|
|
46
|
+
Otherwise call update_app_plan with decisions and exactly one question.
|
|
47
|
+
|
|
48
|
+
You may NOT approve a plan, file its issues, scale its team, provision a machine,
|
|
49
|
+
install globally, scaffold, write application code, run shell commands or deploy.
|
|
50
|
+
Every executable action is only a proposal for normal workers. A chat "yes" is
|
|
51
|
+
an answer, never publication authority. Tell the manager to read the full plan
|
|
52
|
+
and use the explicit approval button. Only the application publishes the exact
|
|
53
|
+
approved revision. Changes require a new revision and new approval.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# A5 provenance and reuse decision
|
|
2
|
+
|
|
3
|
+
Checked 20 November 2026:
|
|
4
|
+
|
|
5
|
+
- Development base: `origin/dev`, fetched and independently checked with
|
|
6
|
+
`git ls-remote`: `5d47c5029e31d73788fed271bf035ceea08467c1`.
|
|
7
|
+
- Dedicated branch: `feat/ceo-app-starter-20261120`. The original checkout's
|
|
8
|
+
uncommitted `boxCli.ts`, `boxMachines.ts`, `swarm.ts` work is untouched.
|
|
9
|
+
- Conceptual reference: Leon van Zyl,
|
|
10
|
+
<https://github.com/leonvanzyl/skills/tree/main/skills/apps/start-an-app>.
|
|
11
|
+
- Inspected upstream tree revision:
|
|
12
|
+
`4204b6501704ba452424b7ed0eef64d08dd9fc84`, complete recursive tree (not truncated
|
|
13
|
+
by the GitHub API). Start-app subtree `4ab26fd5826ee1eec6ae36736fa86ff5a960eb85`,
|
|
14
|
+
references tree `90402decf21b1e2b703d41c5c9c2e9fafb1154d1`,
|
|
15
|
+
SKILL blob `7668e1f8163131239c7179c386c2dc8de4310056`.
|
|
16
|
+
- README and SKILL contain no applicable redistribution license. No applicable
|
|
17
|
+
license file found in the tree. Root LICENSE and GitHub license API: HTTP 404.
|
|
18
|
+
This is **not proof of the absence of permission**, nor permission to copy.
|
|
19
|
+
|
|
20
|
+
The manager explicitly authorized an **original resource from the A5 requirements**
|
|
21
|
+
instead of a textual adaptation. `server/skills/ceo-app-starter.md` is that resource.
|
|
22
|
+
No upstream text or references are copied, translated, packaged or downloaded at
|
|
23
|
+
runtime. Attribution above identifies the conceptual reference, not a license
|
|
24
|
+
grant. Redistribution of upstream material remains unapproved and is not needed
|
|
25
|
+
by this implementation. The project's existing license applies to the new work.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# New application planning (A5)
|
|
2
|
+
|
|
3
|
+
This feature is in the development sources, **not in the published beta.5**.
|
|
4
|
+
It applies only to **Something new → Create project**, with CEO intervention on.
|
|
5
|
+
Existing repositories and new projects with CEO intervention off keep their old
|
|
6
|
+
behavior. The initial folder, Git, README and remote repository are still created
|
|
7
|
+
by that explicit button; that does not mean the application has been built.
|
|
8
|
+
|
|
9
|
+
## Interview → review → approval → normal work
|
|
10
|
+
|
|
11
|
+
After **Create project**, an inline status shows the request in progress, then
|
|
12
|
+
a persistent **Project created: owner/name** confirmation. **Open project
|
|
13
|
+
interview** opens that project's thread, even when other interviews are pending.
|
|
14
|
+
The form cannot submit again while pending; after success, **Create another
|
|
15
|
+
project** explicitly starts a fresh form. If creation is not confirmed, the error
|
|
16
|
+
stays beside the form and the entered name is retained. Check the project list
|
|
17
|
+
before retrying an uncertain request; an interrupted response does not prove
|
|
18
|
+
the remote creation failed.
|
|
19
|
+
|
|
20
|
+
During the interview, the current CEO question stays directly above the reply
|
|
21
|
+
box. Earlier turns and accumulated decisions are collapsed by default and can
|
|
22
|
+
be expanded independently without pushing the reply box away. The complete
|
|
23
|
+
proposed plan and all tasks remain expanded for review before approval.
|
|
24
|
+
|
|
25
|
+
1. Open Chat in the phone, manager console or Pocket. Select the project's
|
|
26
|
+
**New app plan** conversation, not the company-wide chat. An empty brief is OK.
|
|
27
|
+
2. Answer the CEO's focused questions. Requirements, users, ownership, data model,
|
|
28
|
+
MVP/exclusions, stack alternatives and visual design are saved per project.
|
|
29
|
+
Never paste credentials, connection strings, private records or database dumps.
|
|
30
|
+
3. Before recommending a database the CEO asks where workers, tests/previews and
|
|
31
|
+
the deployed app will run, and about sample/existing data and transferability.
|
|
32
|
+
4. Read the **complete proposed plan**, including every task and dependency.
|
|
33
|
+
**Modify plan** invalidates the old revision immediately. You can also answer
|
|
34
|
+
with a requested change. An ordinary “yes” never authorizes publication.
|
|
35
|
+
5. Confirm you have read the plan and agreed the environments (including isolation
|
|
36
|
+
of migrations/tests from production). For non-transferable local data, also
|
|
37
|
+
explicitly confirm local workers and keeping the computer on.
|
|
38
|
+
6. Use **Approve plan and create issues**. It identifies the project, draft,
|
|
39
|
+
revision and SHA-256 fingerprint you saw. Stale or duplicate approvals fail.
|
|
40
|
+
|
|
41
|
+
No project worker, Box, issue from the plan or preview is prepared before the
|
|
42
|
+
gate. Company chat, generic CEO tools, onboarding, periodic reviews and manual
|
|
43
|
+
issue creation do not bypass the hold. Other projects are unaffected. These are
|
|
44
|
+
application workflow checks, not new agent sandboxes, hooks or CLI permission rules.
|
|
45
|
+
Agents remain ordinary unsandboxed sessions under the manager's own setup.
|
|
46
|
+
|
|
47
|
+
Once all issues and dependencies are confirmed, normal build/QA/fix scheduling
|
|
48
|
+
takes over. Current auto-assign and auto-merge settings are respected, **not reset**.
|
|
49
|
+
With auto-assign on this may start paid AI work and use approved team Box resources.
|
|
50
|
+
Approval does not authorize paid accounts, database provisioning, deploys or
|
|
51
|
+
real-data transfers. The CEO plans; ordinary workers execute the approved tasks.
|
|
52
|
+
|
|
53
|
+
## Database and Box FAQ
|
|
54
|
+
|
|
55
|
+
- **SQLite needs local workers?** No. Each Box can have a separate SQLite file
|
|
56
|
+
generated from synthetic seed data. Do not commit real database files.
|
|
57
|
+
- **Docker means local workers?** No. The plan must specify where Docker will be
|
|
58
|
+
available and how each worker/test/preview gets an isolated database. Choosing
|
|
59
|
+
Docker does not prove it is installed or running; workers must verify it.
|
|
60
|
+
- **Neon required?** No. It is one possible hosted Postgres recommendation.
|
|
61
|
+
Use the stack and host that meet the agreed requirements.
|
|
62
|
+
- **Existing data cannot leave this PC?** Explain the constraint and explicitly
|
|
63
|
+
choose local workers; the computer needs to remain available. Never silently
|
|
64
|
+
route to Boxes. Host mismatches hold work; sessions/worktrees are not migrated.
|
|
65
|
+
- **Existing data with Box workers?** Propose approved anonymized copies or a
|
|
66
|
+
safely reachable service, distinguishing read-only consultation from disposable
|
|
67
|
+
development/migration databases. Never publicly expose a local database or use
|
|
68
|
+
production as a shared test lab.
|
|
69
|
+
- **SQLite now, Postgres later?** This may need code changes and tested migrations,
|
|
70
|
+
not just a new environment variable. Include that work in the plan when relevant.
|
|
71
|
+
|
|
72
|
+
## Restart, partial publishing and reconciliation
|
|
73
|
+
|
|
74
|
+
The transcript and plan are durable project state, not the last CLI conversation.
|
|
75
|
+
Claude SDK, local Claude Code and local OpenCode use the same conditional local
|
|
76
|
+
instructions without changing providers. Workers never receive this CEO skill.
|
|
77
|
+
No runtime download or global skill installation is involved. The resource is
|
|
78
|
+
original; see [provenance and reuse decision](app-starter-provenance.md).
|
|
79
|
+
|
|
80
|
+
The publisher uses the approved tasks directly; it does not ask an AI to rewrite
|
|
81
|
+
them. A ledger records pending → in-flight → confirmed, or unknown on ambiguous
|
|
82
|
+
failure. Each issue carries a stable HTML marker for that draft/revision/task.
|
|
83
|
+
Dependencies are resolved by confirmed task IDs before creating dependent issues.
|
|
84
|
+
Remote content and dependencies are checked before releasing normal scheduling.
|
|
85
|
+
|
|
86
|
+
- **Pause** stops subsequent actions; it cannot undo a GitHub request already in
|
|
87
|
+
flight. Created issues and ledger entries are kept.
|
|
88
|
+
- **Cancel** leaves the project held and retains its issues; it does not delete
|
|
89
|
+
remote issues or silently switch to the unguided workflow. Cancellation is final.
|
|
90
|
+
- An interrupted publisher restarts **paused**, never blindly publishing on boot.
|
|
91
|
+
**Resume / reconcile** checks all GitHub issue states via paginated reads, not
|
|
92
|
+
search-index timing, and continues only from confirmed/pending entries.
|
|
93
|
+
- A lost response can be reconciled if exactly one marker with matching approved
|
|
94
|
+
title/body exists. Missing, duplicate or edited marked issues keep the project
|
|
95
|
+
paused. Inspect the ledger and remote issues; do not blindly click “create again”
|
|
96
|
+
or delete duplicates. This version does not offer an automatic override for
|
|
97
|
+
unknown outcomes: manual resolution needs an explicit operator decision.
|
|
98
|
+
- This is **not absolute exactly-once**: GitHub creation and local persistence are
|
|
99
|
+
not a distributed transaction. External edits/deletes after verification remain
|
|
100
|
+
possible. Do not let a second office share the same state home.
|
|
101
|
+
- If the agreed worker host lacks resources or a compatible local CLI, setup
|
|
102
|
+
waits with an explanation. Configure those resources and hire a compatible
|
|
103
|
+
worker; there is no fallback to a different host.
|
|
104
|
+
|
|
105
|
+
Secret-paste checks are heuristic, not a guarantee that arbitrary free text
|
|
106
|
+
contains no secret. Do not supply real data. Demo and fake-backend tests validate
|
|
107
|
+
workflow, not real database isolation, Docker, cloud provider availability or deploys.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "droidsembly",
|
|
3
|
-
"version": "0.4.0-beta.
|
|
3
|
+
"version": "0.4.0-beta.6",
|
|
4
4
|
"description": "Droidsembly: a visual 3D office and mobile dashboard for coordinating AI coding agents on your GitHub projects.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"claude-code",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"author": "Leon van Zyl",
|
|
24
24
|
"type": "module",
|
|
25
25
|
"bin": {
|
|
26
|
-
"droidsembly": "bin/
|
|
26
|
+
"droidsembly": "bin/droidsembly.js"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public",
|
|
@@ -33,7 +33,9 @@
|
|
|
33
33
|
"files": [
|
|
34
34
|
"bin",
|
|
35
35
|
"dist",
|
|
36
|
-
"dist-server"
|
|
36
|
+
"dist-server",
|
|
37
|
+
"docs/app-starter.md",
|
|
38
|
+
"docs/app-starter-provenance.md"
|
|
37
39
|
],
|
|
38
40
|
"engines": {
|
|
39
41
|
"node": ">=22"
|