viewable-one 0.12.1 → 0.12.3
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/CHANGELOG.md +71 -1
- package/README.md +31 -48
- package/SPAWN.md +136 -79
- package/glytch.mjs +41 -10
- package/lib/acp.mjs +152 -150
- package/lib/admission.mjs +25 -5
- package/lib/agent-selection.mjs +5 -4
- package/lib/agents.mjs +68 -24
- package/lib/answerTag.mjs +47 -0
- package/lib/atomic.mjs +1 -16
- package/lib/auth.mjs +172 -52
- package/lib/authenticatedHttp.mjs +10 -3
- package/lib/boardside.mjs +28 -12
- package/lib/child.mjs +129 -116
- package/lib/claudeModels.mjs +168 -0
- package/lib/codex-rpc.mjs +2 -2
- package/lib/codex.mjs +50 -50
- package/lib/codexApps.mjs +17 -3
- package/lib/codexToolInputs.mjs +98 -22
- package/lib/codingChecks.mjs +8 -4
- package/lib/conversationRules.mjs +47 -7
- package/lib/detect.mjs +39 -24
- package/lib/devserver.mjs +30 -19
- package/lib/doctor.mjs +10 -8
- package/lib/folderReads.mjs +96 -0
- package/lib/followUps.mjs +170 -0
- package/lib/hosted.mjs +13 -4
- package/lib/init-connect.mjs +29 -10
- package/lib/lateResume.mjs +135 -0
- package/lib/logindaemon.mjs +129 -49
- package/lib/logs.mjs +2 -2
- package/lib/mcpjson.mjs +35 -2
- package/lib/memberPreview.mjs +22 -14
- package/lib/multiwatch.mjs +28 -41
- package/lib/pagePictures.mjs +15 -12
- package/lib/pageRoutes.mjs +5 -2
- package/lib/paths.mjs +3 -3
- package/lib/permissionAsk.mjs +344 -61
- package/lib/previewGateway.mjs +4 -3
- package/lib/procs.mjs +73 -2
- package/lib/refusal.mjs +0 -2
- package/lib/registry.mjs +7 -7
- package/lib/repomap.mjs +4 -3
- package/lib/restartPass.mjs +39 -11
- package/lib/rowsAnswers.mjs +52 -69
- package/lib/rowsEvents.mjs +20 -2
- package/lib/runner-health.mjs +29 -5
- package/lib/runner.mjs +161 -1347
- package/lib/runnerAdmission.mjs +6 -12
- package/lib/runnerApi.mjs +20 -11
- package/lib/runnerBeat.mjs +384 -0
- package/lib/runnerCompletion.mjs +5 -2
- package/lib/runnerExecute.mjs +227 -0
- package/lib/runnerGates.mjs +338 -0
- package/lib/runnerLaunch.mjs +351 -0
- package/lib/runnerLease.mjs +31 -9
- package/lib/runnerOps.mjs +217 -0
- package/lib/runnerPace.mjs +10 -6
- package/lib/runnerRecovery.mjs +457 -0
- package/lib/runnerRegister.mjs +29 -8
- package/lib/runnerSettlement.mjs +43 -16
- package/lib/runnerWorkspace.mjs +19 -4
- package/lib/spawn.mjs +0 -5
- package/lib/sync.mjs +28 -16
- package/lib/uninstall-project.mjs +12 -11
- package/lib/uninstall.mjs +32 -25
- package/lib/update.mjs +4 -4
- package/lib/{glytchFolder.mjs → viewableFolder.mjs} +22 -16
- package/lib/worktree.mjs +83 -26
- package/lib/writePolicy.mjs +90 -10
- package/package.json +2 -2
package/lib/runnerSettlement.mjs
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import { mkdir, open, readdir, readFile, rename, unlink } from "node:fs/promises";
|
|
5
5
|
import { join } from "node:path";
|
|
6
|
-
import {
|
|
6
|
+
import { viewableHome } from "./registry.mjs";
|
|
7
7
|
import * as defaultApi from "./runnerApi.mjs";
|
|
8
8
|
|
|
9
9
|
const digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
10
|
-
export const completionDirectory = (project, settings) => join(
|
|
10
|
+
export const completionDirectory = (project, settings) => join(viewableHome(settings.env), "run-completions", digest(`${project.id}\0${project.path}`));
|
|
11
11
|
const memoryReceipts = new Map();
|
|
12
12
|
const terminal = new Set(["done", "error", "stopped"]);
|
|
13
13
|
|
|
@@ -22,13 +22,13 @@ export async function prepareCompletionStore(project, settings) {
|
|
|
22
22
|
return dir;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
async function writeReceipt(project, runId, patch, settings) {
|
|
25
|
+
async function writeReceipt(project, runId, patch, settings, events) {
|
|
26
26
|
const dir = await prepareCompletionStore(project, settings);
|
|
27
|
-
const path = join(dir, `${digest(runId)}.json`);
|
|
27
|
+
const path = join(dir, `${digest(runId)}${events ? `-events-${events[0].seq}` : ""}.json`);
|
|
28
28
|
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
29
29
|
const handle = await open(temporary, "wx", 0o600);
|
|
30
30
|
try {
|
|
31
|
-
await handle.writeFile(JSON.stringify({ projectId: project.id, runId, patch }));
|
|
31
|
+
await handle.writeFile(JSON.stringify({ projectId: project.id, runId, ...(settings.runGeneration ? { generation: settings.runGeneration } : {}), ...(events ? { events } : { patch }) }));
|
|
32
32
|
await handle.sync();
|
|
33
33
|
} finally { await handle.close(); }
|
|
34
34
|
try { await rename(temporary, path); }
|
|
@@ -44,9 +44,12 @@ async function deliver(path, record, settings, log, attempts) {
|
|
|
44
44
|
const options = { env: settings.env, fetchImpl: settings.fetchImpl };
|
|
45
45
|
let last;
|
|
46
46
|
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
47
|
-
try { last =
|
|
47
|
+
try { last = record.events
|
|
48
|
+
? await api.events({ runId: record.runId, events: record.events }, options)
|
|
49
|
+
: await api.update({ runId: record.runId, patch: record.patch, ...(record.generation ? { generation: record.generation } : {}) }, options); }
|
|
48
50
|
catch (error) { last = { ok: false, error: error.message }; }
|
|
49
|
-
if (last?.ok) {
|
|
51
|
+
if (last?.ok || last?.error === "runner ownership lost") {
|
|
52
|
+
if (!last.ok) log(`[${record.runId}] discarded receipt from an older lease generation`);
|
|
50
53
|
await unlink(path).catch(error => { if (error.code !== "ENOENT") log(`[${record.runId}] completion acknowledged; local cleanup will retry: ${error.message}`); });
|
|
51
54
|
return true;
|
|
52
55
|
}
|
|
@@ -59,9 +62,23 @@ async function deliver(path, record, settings, log, attempts) {
|
|
|
59
62
|
try { return await task; } finally { replaying.delete(path); }
|
|
60
63
|
}
|
|
61
64
|
|
|
62
|
-
|
|
65
|
+
/** Persist every queued event before attempting network delivery. Event names
|
|
66
|
+
* retain the server's (run, sequence) idempotency key across process restarts. */
|
|
67
|
+
export async function retainRunEvents(project, runId, events, settings) {
|
|
68
|
+
for (const event of events) await writeReceipt(project, runId, undefined, settings, [event]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function deliverRunEvents(project, runId, events, settings, log = () => {}) {
|
|
72
|
+
for (const event of events) {
|
|
73
|
+
const path = join(completionDirectory(project, settings), `${digest(runId)}-events-${event.seq}.json`);
|
|
74
|
+
if (!await deliver(path, { projectId: project.id, runId, events: [event] }, settings, log, 1)) return { ok: false };
|
|
75
|
+
}
|
|
76
|
+
return { ok: true };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function settleRun(project, runId, patch, settings, log = () => {}, { deferDelivery = false } = {}) {
|
|
63
80
|
if (!terminal.has(patch.status)) throw new Error("A terminal receipt requires a terminal status.");
|
|
64
|
-
const record = { projectId: project.id, runId, patch };
|
|
81
|
+
const record = { projectId: project.id, runId, patch, ...(settings.runGeneration ? { generation: settings.runGeneration } : {}) };
|
|
65
82
|
const memoryKey = join(completionDirectory(project, settings), digest(runId));
|
|
66
83
|
memoryReceipts.set(memoryKey, record);
|
|
67
84
|
let path;
|
|
@@ -69,6 +86,10 @@ export async function settleRun(project, runId, patch, settings, log = () => {})
|
|
|
69
86
|
catch (error) {
|
|
70
87
|
// Never replace a completed result with a generic execution error when
|
|
71
88
|
// local storage fails. Try the server while retaining the original patch.
|
|
89
|
+
if (deferDelivery) {
|
|
90
|
+
log(`[${runId}] completion retained in memory; local storage is unavailable: ${error.message}`);
|
|
91
|
+
return { id: runId, state: "pending-sync", patch };
|
|
92
|
+
}
|
|
72
93
|
const api = settings.runnerApi ?? defaultApi;
|
|
73
94
|
const result = await api.update({ runId, patch }, { env: settings.env, fetchImpl: settings.fetchImpl }).catch(() => null);
|
|
74
95
|
if (result?.ok) {
|
|
@@ -80,6 +101,9 @@ export async function settleRun(project, runId, patch, settings, log = () => {})
|
|
|
80
101
|
|
|
81
102
|
}
|
|
82
103
|
memoryReceipts.delete(memoryKey); // The atomically written disk receipt now owns retries.
|
|
104
|
+
// A canceled preparation must release its pool slot even when the same
|
|
105
|
+
// refresh is blocking delivery. The existing replay path owns this receipt.
|
|
106
|
+
if (deferDelivery) return { id: runId, state: "pending-sync", patch };
|
|
83
107
|
const synced = await deliver(path, record, settings, log, 3);
|
|
84
108
|
return { id: runId, state: synced ? (patch.status === "done" ? "done" : "failed") : "pending-sync", patch };
|
|
85
109
|
}
|
|
@@ -89,17 +113,20 @@ export async function flushCompletions(project, settings, log = () => {}) {
|
|
|
89
113
|
let complete = true;
|
|
90
114
|
for (const [key, record] of [...memoryReceipts]) {
|
|
91
115
|
if (key !== join(dir, digest(record.runId))) continue;
|
|
92
|
-
const result = await settleRun(project, record.runId, record.patch, settings, log);
|
|
116
|
+
const result = await settleRun(project, record.runId, record.patch, { ...settings, runGeneration: record.generation }, log);
|
|
93
117
|
if (result.state === "pending-sync") complete = false;
|
|
94
118
|
}
|
|
95
119
|
let names;
|
|
96
120
|
try { names = await readdir(dir); }
|
|
97
121
|
catch (error) { if (error.code === "ENOENT") return complete; throw error; }
|
|
98
|
-
for (const name of names.filter(name => /^[a-f0-9]{64}
|
|
122
|
+
for (const name of names.filter(name => /^[a-f0-9]{64}(?:-events-[1-9][0-9]*)?\.json$/.test(name)).sort((a, b) => a.localeCompare(b, "en", { numeric: true }))) {
|
|
99
123
|
const path = join(dir, name);
|
|
100
124
|
try {
|
|
101
125
|
const record = JSON.parse(await readFile(path, "utf8"));
|
|
102
|
-
|
|
126
|
+
const event = record.events?.[0];
|
|
127
|
+
const validEvents = Array.isArray(record.events) && record.events.length === 1 && Number.isSafeInteger(event?.seq) && event.seq > 0 && ["log", "cut"].includes(event.kind) && typeof event.text === "string";
|
|
128
|
+
const expected = `${digest(record.runId)}${validEvents ? `-events-${event.seq}` : ""}.json`;
|
|
129
|
+
if (record.projectId !== project.id || typeof record.runId !== "string" || expected !== name || !(validEvents || terminal.has(record.patch?.status))) throw new Error("Invalid saved completion receipt");
|
|
103
130
|
if (!(await deliver(path, record, settings, log, 1))) complete = false;
|
|
104
131
|
} catch (error) {
|
|
105
132
|
if (error.code === "ENOENT") continue;
|
|
@@ -121,18 +148,18 @@ export function isMissingConversation(result) {
|
|
|
121
148
|
return errors.some((e) => typeof e === "string" && e.includes("No conversation found"));
|
|
122
149
|
}
|
|
123
150
|
|
|
124
|
-
export async function settleMeasuredRun(project, id, patch, settings, log, timing, receipt) {
|
|
151
|
+
export async function settleMeasuredRun(project, id, patch, settings, log, timing, receipt, options) {
|
|
125
152
|
const measurement = timing.snapshot();
|
|
126
153
|
try { log(`runner.performance ${JSON.stringify(measurement)}`); } catch { /* Diagnostics never prevent settlement. */ }
|
|
127
154
|
const started = performance.now();
|
|
128
|
-
const result = await settleRun(project, id, { ...patch, sidecar: { ...(patch.sidecar ?? receipt.sidecar), performance: measurement } }, settings, log);
|
|
155
|
+
const result = await settleRun(project, id, { ...patch, sidecar: { ...(patch.sidecar ?? receipt.sidecar), performance: measurement } }, settings, log, options);
|
|
129
156
|
try { log(`runner.delivery ${JSON.stringify({ duration_ms: Math.max(0, Math.round(performance.now() - started)), outcome: result.state === "pending-sync" ? "pending" : "acknowledged" })}`); } catch { /* Optional diagnostics. */ }
|
|
130
157
|
return result;
|
|
131
158
|
}
|
|
132
159
|
|
|
133
|
-
export function settleFailedRun(project, id, error, settings, log, timing, receipt) {
|
|
160
|
+
export function settleFailedRun(project, id, error, settings, log, timing, receipt, options) {
|
|
134
161
|
return settleMeasuredRun(project, id, {
|
|
135
162
|
status: "error", result: `ERROR\n\nThe runner could not complete this run: ${error.message}\n`,
|
|
136
163
|
finished_at: new Date().toISOString(),
|
|
137
|
-
}, settings, log, timing, receipt);
|
|
164
|
+
}, settings, log, timing, receipt, options);
|
|
138
165
|
}
|
package/lib/runnerWorkspace.mjs
CHANGED
|
@@ -46,6 +46,18 @@ export const IN_PLACE_WORKPLACE =
|
|
|
46
46
|
export async function prepareRequestWorkspace(context, services = defaultServices) {
|
|
47
47
|
const { root, id, request, isResume, session, from, log, otherRunningCount, updateSidecarEarly, isChat, chatCwd, claimedAt, ownTreePath } = context;
|
|
48
48
|
const { makeWorktree, reuseWorktree, commentOnAnchor: comment, titleFor: title } = services;
|
|
49
|
+
const { preparation, retainSidecar } = context;
|
|
50
|
+
// Only an operation that has acquired the repo lock can own a mutation.
|
|
51
|
+
// Once started, retain its result before cancellation snapshots the receipt.
|
|
52
|
+
const lifecycle = preparation ? {
|
|
53
|
+
check: preparation.check,
|
|
54
|
+
own: operation => preparation.own(async () => {
|
|
55
|
+
const made = await operation();
|
|
56
|
+
if (made?.isolated && made.path) retainSidecar?.({ worktreePath: made.path, fromId: from });
|
|
57
|
+
return made;
|
|
58
|
+
}),
|
|
59
|
+
} : undefined;
|
|
60
|
+
preparation?.check();
|
|
49
61
|
|
|
50
62
|
// A NAMED cwd STAYS IN THE LINKED FOLDER (#324). A chat turn's was
|
|
51
63
|
// resolved and fenced by the caller (`chatCwd`); every other request's is
|
|
@@ -82,9 +94,9 @@ export async function prepareRequestWorkspace(context, services = defaultService
|
|
|
82
94
|
const wantedRecordedTree = !isChat && !request.cwd && request.useWorktree !== false && Boolean(request.worktreePath);
|
|
83
95
|
const isOwnTree = wantedRecordedTree && typeof ownTreePath === "string" && ownTreePath !== "";
|
|
84
96
|
if (wantedRecordedTree && !isOwnTree) log(`[${id}] the named worktree ${request.worktreePath} is not this idea's own; not reused`);
|
|
85
|
-
const reusedTree = isOwnTree ? await reuseWorktree(root, ownTreePath, log) : null;
|
|
86
|
-
if (request.recovery === true && wantedRecordedTree && !reusedTree) {
|
|
87
|
-
return { ok: false, patch: { status: "error", result: "ERROR\n\
|
|
97
|
+
const reusedTree = isOwnTree ? await reuseWorktree(root, ownTreePath, log, lifecycle) : null;
|
|
98
|
+
if ((request.recovery === true || (request.continues && isResume)) && wantedRecordedTree && !reusedTree) {
|
|
99
|
+
return { ok: false, patch: { status: "error", result: "ERROR\n\nThis session cannot continue because its separate copy is gone. Run again to start a new session.\n", finished_at: new Date().toISOString(), sidecar: { ...(request.recovery === true ? { recoveryFailed: true } : {}) } } };
|
|
88
100
|
}
|
|
89
101
|
if (wantedRecordedTree && !isResume && !reusedTree) log(`[${id}] the kept worktree ${request.worktreePath} is gone; this session gets a new one`);
|
|
90
102
|
const made = isChat
|
|
@@ -104,11 +116,13 @@ export async function prepareRequestWorkspace(context, services = defaultService
|
|
|
104
116
|
? { cwd: namedCwd, isolated: false, detail: `Ran in the cwd the request named, ${namedCwd}.` }
|
|
105
117
|
: request.useWorktree === false
|
|
106
118
|
? { cwd: root, isolated: false, detail: `Ran in the linked folder per idea setting (worktree off).` }
|
|
107
|
-
: await makeWorktree(root, id, log, title(request));
|
|
119
|
+
: await makeWorktree(root, id, log, title(request), lifecycle);
|
|
120
|
+
preparation?.check();
|
|
108
121
|
|
|
109
122
|
const wantedIsolation = !isChat && !request.cwd && request.useWorktree !== false;
|
|
110
123
|
if (wantedIsolation && !made.isolated) {
|
|
111
124
|
const others = typeof otherRunningCount === "function" ? await otherRunningCount() : 0;
|
|
125
|
+
preparation?.check();
|
|
112
126
|
if (others > 0) {
|
|
113
127
|
const detail =
|
|
114
128
|
`NOTHING WAS SPAWNED AND NOTHING WAS BILLED.\n\n` +
|
|
@@ -131,6 +145,7 @@ export async function prepareRequestWorkspace(context, services = defaultService
|
|
|
131
145
|
// claim and the worktree being ready: the hosted-token check, the repo
|
|
132
146
|
// lock, `git worktree add`, the node_modules symlink. One number, so the
|
|
133
147
|
// next silent multi-second gap shows up as a big one rather than nothing.
|
|
148
|
+
preparation?.check();
|
|
134
149
|
const prepSecs = Number.isFinite(claimedAt) ? ((Date.now() - claimedAt) / 1000).toFixed(1) : null;
|
|
135
150
|
log(`[${id}] ${made.isolated ? `worktree ${made.branch}` : "NO worktree"}; spawning${prepSecs !== null ? ` (prep ${prepSecs}s)` : ""}`);
|
|
136
151
|
|
package/lib/spawn.mjs
CHANGED
|
@@ -19,11 +19,6 @@ import { SIGN_IN_AGENTS } from "./signIn.mjs";
|
|
|
19
19
|
// runner's local scratch lives.
|
|
20
20
|
export const SPAWN_DIR = join(...segmentsOf(SPAWN_PATH));
|
|
21
21
|
|
|
22
|
-
/** THE SAME PLACE, SPELLED FOR A PERSON. `SPAWN_DIR` above is `join`ed, so
|
|
23
|
-
* on Windows it is `.glytch\inbox\spawn`; this is the `/`-spelled form for
|
|
24
|
-
* anything that prints the path to a human. */
|
|
25
|
-
export const SPAWN_DIR_IN_WORDS = SPAWN_PATH;
|
|
26
|
-
|
|
27
22
|
// A session left running all night bills all night, so there is a default and
|
|
28
23
|
// a hard cap, and the cap is what a request may ask for.
|
|
29
24
|
//
|
package/lib/sync.mjs
CHANGED
|
@@ -35,13 +35,14 @@ import { join } from "node:path";
|
|
|
35
35
|
import { detectAgents, execProbe } from "./detect.mjs";
|
|
36
36
|
import {
|
|
37
37
|
DAEMON_LABEL,
|
|
38
|
-
|
|
38
|
+
launcherNeedsRepair,
|
|
39
|
+
COMPUTER_REPAIR,
|
|
39
40
|
daemonPackageVersion,
|
|
40
|
-
|
|
41
|
+
viewableScriptPath,
|
|
41
42
|
loginDaemon,
|
|
42
43
|
noDaemonInstall,
|
|
43
44
|
} from "./logindaemon.mjs";
|
|
44
|
-
import { BOARD_MCP_URL,
|
|
45
|
+
import { BOARD_MCP_URL, mergeBoardServer } from "./mcpjson.mjs";
|
|
45
46
|
import { addFolder, readRegistry } from "./registry.mjs";
|
|
46
47
|
import { readAgentSelection, parseAgentSelection } from "./agent-selection.mjs";
|
|
47
48
|
import { syncProjectMcp } from "./project-mcp.mjs";
|
|
@@ -95,12 +96,12 @@ export async function syncMcpJson(root, { write = true, platform = process.platf
|
|
|
95
96
|
".mcp.json",
|
|
96
97
|
false,
|
|
97
98
|
"unreadable",
|
|
98
|
-
`${path}
|
|
99
|
+
`${path} could not be read, so nothing was changed. ${COMPUTER_REPAIR}`,
|
|
99
100
|
);
|
|
100
101
|
}
|
|
101
102
|
if (!write) {
|
|
102
103
|
return merge.kind === "legacy"
|
|
103
|
-
? row("mcp", ".mcp.json", false, "legacy-command", `${path} still
|
|
104
|
+
? row("mcp", ".mcp.json", false, "legacy-command", `${path} still uses an old connection. ${COMPUTER_REPAIR}`)
|
|
104
105
|
: row("mcp", ".mcp.json", false, merge.kind, "missing the Viewable server");
|
|
105
106
|
}
|
|
106
107
|
await writeFile(path, merge.text, "utf8");
|
|
@@ -152,7 +153,7 @@ export async function syncRegistry(root, { env = process.env, write = true } = {
|
|
|
152
153
|
false,
|
|
153
154
|
"could not write",
|
|
154
155
|
`~/.glytch/folders.json could not be written: ${why}`,
|
|
155
|
-
|
|
156
|
+
COMPUTER_REPAIR,
|
|
156
157
|
);
|
|
157
158
|
}
|
|
158
159
|
return row("registry", "folder registered", true, "added", "added to ~/.glytch/folders.json");
|
|
@@ -287,7 +288,7 @@ export async function syncLaunchAgent({
|
|
|
287
288
|
// Ruling 6C: an older WSL with no `systemctl --user` is told the truth and
|
|
288
289
|
// given the fallback, rather than sent to `glytch init` for ever.
|
|
289
290
|
if (result.unavailable) {
|
|
290
|
-
return row("plist", label, true, "no systemd here", `wrote ${result.file};
|
|
291
|
+
return row("plist", label, true, "no systemd here", `wrote ${result.file}; the background connection is unavailable. ${COMPUTER_REPAIR}`);
|
|
291
292
|
}
|
|
292
293
|
return row(
|
|
293
294
|
"plist",
|
|
@@ -317,14 +318,21 @@ export async function syncLaunchAgent({
|
|
|
317
318
|
// unloaded branch is: the running daemon's own multiwatch loop must never
|
|
318
319
|
// unload itself mid-sync, so it leaves this repair to `init` and `doctor`,
|
|
319
320
|
// which both pass daemon:false.
|
|
321
|
+
const brokenLauncher = await launcherNeedsRepair(text, { env, impl });
|
|
322
|
+
if (daemon && brokenLauncher && write) {
|
|
323
|
+
const result = await impl.install({ env, ...call, path: mergePaths(captured, path, impl.pathDelimiter),
|
|
324
|
+
nodePath, scriptPath: impl.programScriptPath(text) ?? scriptPath, force: true, load: false });
|
|
325
|
+
if (!skipped && result.reloaded === false) return row("plist", label, false, "launcher not reloaded", result.why);
|
|
326
|
+
return row("plist", label, true, "launcher repaired", "Your computer will reconnect automatically on its next start.");
|
|
327
|
+
}
|
|
320
328
|
if (!daemon) {
|
|
321
|
-
const currentScriptPath = scriptPath ??
|
|
329
|
+
const currentScriptPath = scriptPath ?? viewableScriptPath();
|
|
322
330
|
const mismatch = await scriptMismatch({
|
|
323
331
|
installedScriptPath: impl.programScriptPath(text),
|
|
324
332
|
currentScriptPath,
|
|
325
333
|
currentVersion: version,
|
|
326
334
|
});
|
|
327
|
-
if (mismatch || restart || replaceLoadedVersion) {
|
|
335
|
+
if (mismatch || restart || replaceLoadedVersion || brokenLauncher) {
|
|
328
336
|
const change = mismatch ?? { oldPath: impl.programScriptPath(text), newPath: currentScriptPath, oldVersion: health?.version ?? null, newVersion: version };
|
|
329
337
|
const oldVersionText = change.oldVersion ?? "unknown";
|
|
330
338
|
if (!write) {
|
|
@@ -332,8 +340,8 @@ export async function syncLaunchAgent({
|
|
|
332
340
|
"plist",
|
|
333
341
|
label,
|
|
334
342
|
false,
|
|
335
|
-
"different script",
|
|
336
|
-
`${file} runs ${change.oldPath} (${oldVersionText}); this install is ${change.newPath} (${change.newVersion})`,
|
|
343
|
+
brokenLauncher ? "broken launcher" : "different script",
|
|
344
|
+
brokenLauncher ? "The background connection needs repair." : `${file} runs ${change.oldPath} (${oldVersionText}); this install is ${change.newPath} (${change.newVersion})`,
|
|
337
345
|
);
|
|
338
346
|
}
|
|
339
347
|
const merged = mergePaths(captured, path, impl.pathDelimiter);
|
|
@@ -348,7 +356,7 @@ export async function syncLaunchAgent({
|
|
|
348
356
|
);
|
|
349
357
|
}
|
|
350
358
|
if (result.unavailable) {
|
|
351
|
-
return row("plist", label, true, "no systemd here", `rewrote ${result.file};
|
|
359
|
+
return row("plist", label, true, "no systemd here", `rewrote ${result.file}; the background connection is unavailable. ${COMPUTER_REPAIR}`);
|
|
352
360
|
}
|
|
353
361
|
return row(
|
|
354
362
|
"plist",
|
|
@@ -382,7 +390,7 @@ export async function syncLaunchAgent({
|
|
|
382
390
|
return row("plist", label, false, "present, cannot be checked", `${file} is on disk; ${impl.tool} refused: ${state.why}`, state.action);
|
|
383
391
|
}
|
|
384
392
|
if (state.unavailable) {
|
|
385
|
-
return row("plist", label, true, "no systemd here", `${file} is on disk;
|
|
393
|
+
return row("plist", label, true, "no systemd here", `${file} is on disk; the background connection is unavailable. ${COMPUTER_REPAIR}`);
|
|
386
394
|
}
|
|
387
395
|
if (!write) {
|
|
388
396
|
return row(
|
|
@@ -390,7 +398,7 @@ export async function syncLaunchAgent({
|
|
|
390
398
|
label,
|
|
391
399
|
false,
|
|
392
400
|
"present, not loaded",
|
|
393
|
-
`${file} is on disk but ${impl.holder} is not holding ${DAEMON_LABEL}
|
|
401
|
+
`${file} is on disk but ${impl.holder} is not holding ${DAEMON_LABEL}. ${COMPUTER_REPAIR}`,
|
|
394
402
|
);
|
|
395
403
|
}
|
|
396
404
|
const result = await impl.install({ env, ...call, path, nodePath, scriptPath, load: true });
|
|
@@ -411,12 +419,16 @@ export async function syncLaunchAgent({
|
|
|
411
419
|
if (!write) {
|
|
412
420
|
return row("plist", label, false, "stale PATH", "the captured PATH is missing entries this shell has");
|
|
413
421
|
}
|
|
414
|
-
const result = await impl.install({ env, ...call, path: merged, nodePath, scriptPath, force: true });
|
|
422
|
+
const result = await impl.install({ env, ...call, path: merged, nodePath, scriptPath, force: true, load: !daemon });
|
|
415
423
|
if (skipped) {
|
|
416
424
|
return row("plist", label, true, "PATH refreshed, not loaded", `rewrote ${result.file}; ${escape} is set, so ${impl.tool} was not run`);
|
|
417
425
|
}
|
|
418
426
|
if (result.unavailable) {
|
|
419
|
-
return row("plist", label, true, "no systemd here", `rewrote ${result.file};
|
|
427
|
+
return row("plist", label, true, "no systemd here", `rewrote ${result.file}; the background connection is unavailable. ${COMPUTER_REPAIR}`);
|
|
428
|
+
}
|
|
429
|
+
if (daemon) {
|
|
430
|
+
if (result.reloaded === false) return row("plist", label, false, "PATH not reloaded", result.why);
|
|
431
|
+
return row("plist", label, true, "PATH refreshed on next start", "Your computer will use the updated connection on its next start.");
|
|
420
432
|
}
|
|
421
433
|
return row(
|
|
422
434
|
"plist",
|
|
@@ -460,8 +460,8 @@ async function projectMcpRows(root, { env, dryRun, log, skip = new Set() }) {
|
|
|
460
460
|
// still holds either is left in place and named in the row detail (there is
|
|
461
461
|
// only one row for this whole step, since both actions describe one fact:
|
|
462
462
|
// what happened to .glytch/agents.json, and what became of the directory).
|
|
463
|
-
async function
|
|
464
|
-
const dir = join(root,
|
|
463
|
+
async function projectDirRow(root, { dryRun, log }, directory = ".glytch") {
|
|
464
|
+
const dir = join(root, directory);
|
|
465
465
|
const agentsPath = join(dir, "agents.json");
|
|
466
466
|
let r;
|
|
467
467
|
try {
|
|
@@ -475,31 +475,31 @@ async function glytchDirRow(root, { dryRun, log }) {
|
|
|
475
475
|
}
|
|
476
476
|
|
|
477
477
|
if (entries === null) {
|
|
478
|
-
r = row("glytchDir"
|
|
478
|
+
r = row(directory === ".glytch" ? "glytchDir" : "viewableDir", `${directory}/`, true, "not present", `no ${directory}/ folder to remove`);
|
|
479
479
|
} else {
|
|
480
480
|
const others = entries.filter((name) => name !== "agents.json");
|
|
481
481
|
const wouldBeEmpty = others.length === 0;
|
|
482
|
-
const othersNote = others.length ? `;
|
|
482
|
+
const othersNote = others.length ? `; ${directory}/ kept (${others.join(", ")} remain)` : "";
|
|
483
483
|
if (!hadAgents) {
|
|
484
|
-
r = row("glytchDir"
|
|
484
|
+
r = row(directory === ".glytch" ? "glytchDir" : "viewableDir", `${directory}/`, true, "not present", `no ${directory}/agents.json to remove${othersNote}`);
|
|
485
485
|
} else if (dryRun) {
|
|
486
486
|
r = wouldBeEmpty
|
|
487
|
-
? row("glytchDir"
|
|
488
|
-
: row("glytchDir"
|
|
487
|
+
? row(directory === ".glytch" ? "glytchDir" : "viewableDir", `${directory}/`, true, "would delete", `would delete ${directory}/agents.json, then ${directory}/ (empty afterward)`)
|
|
488
|
+
: row(directory === ".glytch" ? "glytchDir" : "viewableDir", `${directory}/`, true, "would delete", `would delete ${directory}/agents.json${othersNote}`);
|
|
489
489
|
} else {
|
|
490
490
|
await rm(agentsPath, { force: true });
|
|
491
491
|
if (wouldBeEmpty) {
|
|
492
492
|
await rm(dir, { recursive: true, force: true });
|
|
493
|
-
r = row("glytchDir"
|
|
493
|
+
r = row(directory === ".glytch" ? "glytchDir" : "viewableDir", `${directory}/`, true, "deleted", `deleted ${directory}/agents.json, then ${directory}/ (was empty)`);
|
|
494
494
|
} else {
|
|
495
|
-
r = row("glytchDir"
|
|
495
|
+
r = row(directory === ".glytch" ? "glytchDir" : "viewableDir", `${directory}/`, true, "deleted", `deleted ${directory}/agents.json${othersNote}`);
|
|
496
496
|
}
|
|
497
497
|
}
|
|
498
498
|
}
|
|
499
499
|
} catch (error) {
|
|
500
500
|
// U4: `readOptional(agentsPath)` rethrows anything but ENOENT (EISDIR,
|
|
501
501
|
// EACCES, ...) - one bad folder must not abort the whole run.
|
|
502
|
-
r = row("glytchDir"
|
|
502
|
+
r = row(directory === ".glytch" ? "glytchDir" : "viewableDir", `${directory}/`, false, "error", `${agentsPath}: ${describeError(error)}`);
|
|
503
503
|
}
|
|
504
504
|
log?.(r);
|
|
505
505
|
return r;
|
|
@@ -582,7 +582,8 @@ export async function uninstallProject(root, { agents, exec = execProbe, env = p
|
|
|
582
582
|
// Keep an agent's saved server names until its own logout succeeds, so retries reach the same credential.
|
|
583
583
|
const skip = new Set(Object.keys(LOGOUT_VERBS).filter((key) => rows.some((r) => r.key === `${key}Logout` && !r.ok)));
|
|
584
584
|
rows.push(...(await projectMcpRows(root, { env, dryRun, log, skip })));
|
|
585
|
-
rows.push(await
|
|
585
|
+
rows.push(await projectDirRow(root, { dryRun, log }));
|
|
586
|
+
rows.push(await projectDirRow(root, { dryRun, log }, ".viewable"));
|
|
586
587
|
rows.push(await registryRow(root, { env, dryRun, log, allOk: rows.every((r) => r.ok) }));
|
|
587
588
|
return rows;
|
|
588
589
|
}
|
package/lib/uninstall.mjs
CHANGED
|
@@ -36,7 +36,7 @@ import { join } from "node:path";
|
|
|
36
36
|
import { bold, bullets, colorEnabled, heading, hint, renderRow, row, step, summary, warn, warnRow } from "./cli-output.mjs";
|
|
37
37
|
import { appUrlFrom, logout as hostedLogout, readAuthFile } from "./auth.mjs";
|
|
38
38
|
import { detectAgents, execProbe } from "./detect.mjs";
|
|
39
|
-
import {
|
|
39
|
+
import { viewableHome, readRegistry } from "./registry.mjs";
|
|
40
40
|
import { loginDaemon } from "./logindaemon.mjs";
|
|
41
41
|
import { uninstallProject } from "./uninstall-project.mjs";
|
|
42
42
|
|
|
@@ -103,12 +103,12 @@ export function uninstallPlan(options, { folderCount = 0 } = {}) {
|
|
|
103
103
|
const lines = [];
|
|
104
104
|
if (options.project) {
|
|
105
105
|
lines.push(
|
|
106
|
-
"Disconnect this project folder only: agent sign-outs, its config entries, .glytch/agents.json, and its registry entry.",
|
|
106
|
+
"Disconnect this project folder only: agent sign-outs, its config entries, .viewable/agents.json and legacy .glytch/agents.json, and its registry entry.",
|
|
107
107
|
);
|
|
108
108
|
} else {
|
|
109
109
|
lines.push(
|
|
110
110
|
folderCount > 0
|
|
111
|
-
? `Disconnect ${folderCount} registered project folder${folderCount === 1 ? "" : "s"}: agent sign-outs, config entries, .glytch/agents.json, and each registry entry.`
|
|
111
|
+
? `Disconnect ${folderCount} registered project folder${folderCount === 1 ? "" : "s"}: agent sign-outs, config entries, .viewable/agents.json and legacy .glytch/agents.json, and each registry entry.`
|
|
112
112
|
: "No project folders are registered: nothing to disconnect there.",
|
|
113
113
|
);
|
|
114
114
|
lines.push("Stop watching folders and remove the watcher's file.");
|
|
@@ -247,7 +247,7 @@ export async function revokeRow({ stored, env, fetchImpl, dryRun, keepLogin, log
|
|
|
247
247
|
// whichever one the server happens to still recognise - never a second
|
|
248
248
|
// grant to clean up.
|
|
249
249
|
const tokens = [stored.refreshToken, stored.accessToken].filter((t) => typeof t === "string" && t !== "");
|
|
250
|
-
let networkFailed =
|
|
250
|
+
let networkFailed = tokens.length === 0;
|
|
251
251
|
let badStatus = null;
|
|
252
252
|
for (const token of tokens) {
|
|
253
253
|
try {
|
|
@@ -261,49 +261,57 @@ export async function revokeRow({ stored, env, fetchImpl, dryRun, keepLogin, log
|
|
|
261
261
|
// network-level failure does - so this used to call the row "revoked"
|
|
262
262
|
// and delete the credential even when the board plainly said the
|
|
263
263
|
// revoke did not happen.
|
|
264
|
-
if (response
|
|
264
|
+
if (!response || response.ok !== true || response.status !== 200) {
|
|
265
|
+
if (badStatus === null) badStatus = response?.status ?? "unknown";
|
|
266
|
+
}
|
|
265
267
|
} catch {
|
|
266
268
|
networkFailed = true;
|
|
267
269
|
}
|
|
268
270
|
}
|
|
269
|
-
//
|
|
270
|
-
//
|
|
271
|
-
|
|
271
|
+
// Older servers answered 200 without recognising personal keys. Verify
|
|
272
|
+
// refusal at the board door before discarding our only retry credential.
|
|
273
|
+
if (badStatus === null && !networkFailed) {
|
|
274
|
+
for (const token of tokens.filter((value) => value.startsWith("pmb_"))) {
|
|
275
|
+
try {
|
|
276
|
+
const response = await fetchImpl(`${appUrl}/mcp`, {
|
|
277
|
+
method: "POST",
|
|
278
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
|
|
279
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" }),
|
|
280
|
+
});
|
|
281
|
+
if (response?.status !== 401) badStatus = response?.status ?? "unknown";
|
|
282
|
+
} catch {
|
|
283
|
+
networkFailed = true;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
// A refusal or missing response leaves revocation unconfirmed. The
|
|
288
|
+
// credential is kept rather than deleted here, and the caller
|
|
272
289
|
// (runUninstall) skips deleting ~/.glytch too - the returned
|
|
273
290
|
// `keptCredential` flag is how it knows - so a re-run of `glytch
|
|
274
291
|
// uninstall` still has a token on disk to retry the revoke with. Deleting
|
|
275
292
|
// it now would strand the grant at the board with nothing left on this
|
|
276
293
|
// machine that could ever ask it to revoke again.
|
|
277
|
-
if (badStatus !== null) {
|
|
294
|
+
if (badStatus !== null || networkFailed) {
|
|
278
295
|
return {
|
|
279
296
|
...warnRow(
|
|
280
297
|
"revoke",
|
|
281
298
|
"Board sign-in",
|
|
282
299
|
"could not revoke",
|
|
283
|
-
`could not revoke at ${revokeUrl} (HTTP ${badStatus}); the credential is kept locally so a retry can revoke it - or revoke it in Settings`,
|
|
300
|
+
`could not revoke at ${revokeUrl} (${badStatus !== null ? `HTTP ${badStatus}` : "no confirmed response"}); the credential is kept locally so a retry can revoke it - or revoke it in Settings`,
|
|
284
301
|
),
|
|
285
302
|
keptCredential: true,
|
|
286
303
|
};
|
|
287
304
|
}
|
|
288
|
-
//
|
|
289
|
-
// still end up signed out on its own side, same rule as `logout()`'s own
|
|
290
|
-
// header comment.
|
|
305
|
+
// Only discard our retry credential after a confirmed server response.
|
|
291
306
|
await logout(env);
|
|
292
|
-
return
|
|
293
|
-
? warnRow(
|
|
294
|
-
"revoke",
|
|
295
|
-
"Board sign-in",
|
|
296
|
-
"could not reach the board",
|
|
297
|
-
"could not reach the board to revoke; the credential is deleted locally, revoke it in Settings",
|
|
298
|
-
)
|
|
299
|
-
: row("revoke", "Board sign-in", true, "revoked", `revoked at ${revokeUrl} and removed the local credential`);
|
|
307
|
+
return row("revoke", "Board sign-in", true, "revoked", `revoked at ${revokeUrl} and removed the local credential`);
|
|
300
308
|
}
|
|
301
309
|
|
|
302
310
|
/** Step 2, row 3: delete `~/.glytch` outright - folders.json, auth.json,
|
|
303
311
|
* logs/, the cloudflared cache, and everything else this package ever wrote
|
|
304
|
-
* under it. Never anything outside
|
|
312
|
+
* under it. Never anything outside viewableHome(). */
|
|
305
313
|
export async function deleteHomeRow({ env, dryRun, keepLogin }) {
|
|
306
|
-
const home =
|
|
314
|
+
const home = viewableHome(env);
|
|
307
315
|
if (keepLogin) {
|
|
308
316
|
return warnRow("home", "Delete ~/.glytch", "kept", `kept - the sign-in credential lives at ${join(home, "auth.json")} (--keep-login)`);
|
|
309
317
|
}
|
|
@@ -422,8 +430,7 @@ export async function runUninstall({
|
|
|
422
430
|
for (const line of printedRows([revoke], paint)) log(line);
|
|
423
431
|
allRows.push(revoke);
|
|
424
432
|
|
|
425
|
-
//
|
|
426
|
-
// network failure) kept the credential on disk on purpose - deleting
|
|
433
|
+
// An unconfirmed revoke keeps the credential on disk for retry. Deleting
|
|
427
434
|
// ~/.glytch now would take that credential with it and strand the grant
|
|
428
435
|
// with nothing left able to retry the revoke. U3: a failed project step
|
|
429
436
|
// (checked above, before this section pushed any machine rows) means a
|
package/lib/update.mjs
CHANGED
|
@@ -169,14 +169,14 @@ export async function verifyInstalledCli({
|
|
|
169
169
|
const shell = env.SHELL || "/bin/sh";
|
|
170
170
|
if (platform === "win32") {
|
|
171
171
|
// Read persisted PATH, not just the launching terminal's stale environment.
|
|
172
|
-
const script = '$env:Path=[Environment]::GetEnvironmentVariable("Path","Machine")+";"+[Environment]::GetEnvironmentVariable("Path","User"); $c=(Get-Command glytch.cmd -ErrorAction Stop).Source; Write-Output "
|
|
172
|
+
const script = '$env:Path=[Environment]::GetEnvironmentVariable("Path","Machine")+";"+[Environment]::GetEnvironmentVariable("Path","User"); $c=(Get-Command glytch.cmd -ErrorAction Stop).Source; Write-Output "VIEWABLE_CLI=$c"; & $c -v; exit $LASTEXITCODE';
|
|
173
173
|
result = await exec("powershell.exe", ["-NonInteractive", "-Command", script], { env: cleanEnv });
|
|
174
174
|
} else {
|
|
175
175
|
cleanEnv.PATH = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
|
|
176
|
-
result = await exec(shell, ["-lic", 'printf "
|
|
176
|
+
result = await exec(shell, ["-lic", 'printf "VIEWABLE_CLI=%s\\n" "$(command -v glytch)"; glytch -v'], { env: cleanEnv });
|
|
177
177
|
}
|
|
178
178
|
const output = result?.stdout?.trim() ?? "";
|
|
179
|
-
const command = /^GLYTCH_CLI=(.+)$/m.exec(output)?.[1]?.trim();
|
|
179
|
+
const command = /^(?:VIEWABLE_CLI|GLYTCH_CLI)=(.+)$/m.exec(output)?.[1]?.trim();
|
|
180
180
|
const version = output.split(/\r?\n/).at(-1)?.trim();
|
|
181
181
|
let actualScript;
|
|
182
182
|
let verifiedScriptPath = scriptPath;
|
|
@@ -251,7 +251,7 @@ export async function verifyInstalledCli({
|
|
|
251
251
|
// must be an absolute path to a glytch.mjs, whichever manager named it.
|
|
252
252
|
const runnable = (platform === "win32" ? win32 : posix).isAbsolute(verifiedScriptPath ?? "") && /(^|[\\/])glytch\.mjs$/.test(verifiedScriptPath);
|
|
253
253
|
if (!result?.ok || version !== expectedVersion || !actualScript || !runnable || [scriptPath, command, actualScript, verifiedScriptPath].some((path) => /[\\/]_npx[\\/]/.test(path ?? ""))) {
|
|
254
|
-
return { ok: false, error: "Viewable could not be verified in a new normal terminal. Install with npm i -g viewable-one@latest without sudo, persist the npm bin directory in your shell startup configuration or Windows user PATH, then open a new terminal and check
|
|
254
|
+
return { ok: false, error: "Viewable could not be verified in a new normal terminal. Install with npm i -g viewable-one@latest --force without sudo, persist the npm bin directory in your shell startup configuration or Windows user PATH, then open a new terminal and check viewable -v. Setup is not Connected." };
|
|
255
255
|
}
|
|
256
256
|
return { ok: true, version, scriptPath: verifiedScriptPath };
|
|
257
257
|
}
|
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
// THE
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// visible folder
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
// so every board has somewhere to work before anyone has linked a folder.
|
|
1
|
+
// THE DEFAULT WORKING FOLDER. ~/.glytch remains the runner's private state.
|
|
2
|
+
// A fresh install uses Documents/Viewable (ruling #2884, the same folder
|
|
3
|
+
// public/setup-mac-linux.sh makes), creating Documents if needed.
|
|
4
|
+
// An existing ~/Viewable or ~/Glytch stays accessible in place.
|
|
5
|
+
// The visible folder is a git repository, registered like any linked folder.
|
|
6
|
+
// A chat with no folder picked works in a subfolder named after the board.
|
|
7
|
+
// No existing folder is moved or rewritten by the rename (#2329).
|
|
9
8
|
//
|
|
10
9
|
// Made when the daemon starts watching, and kept: nothing here removes it.
|
|
11
10
|
|
|
11
|
+
import { existsSync } from "node:fs";
|
|
12
12
|
import { lstat, mkdir, realpath, writeFile } from "node:fs/promises";
|
|
13
13
|
import { homedir } from "node:os";
|
|
14
14
|
import { basename, dirname, join, resolve } from "node:path";
|
|
15
15
|
import { addFolder } from "./registry.mjs";
|
|
16
16
|
import { git, isChatWorktreePath, resolveChatCwd } from "./worktree.mjs";
|
|
17
17
|
|
|
18
|
-
/** Where the
|
|
18
|
+
/** Where the default working folder lives, or null when there is none to make.
|
|
19
19
|
*
|
|
20
20
|
* GLYTCH_FOLDER names it, and "off" turns it off. A scratch GLYTCH_HOME (the
|
|
21
21
|
* tests, and every agent that runs glytch for real) gets none unless it names
|
|
22
22
|
* one: a test must never make a folder in the real home. */
|
|
23
|
-
export function
|
|
23
|
+
export function viewableFolderPath(env = process.env, home = homedir()) {
|
|
24
24
|
const named = (env.VIEWABLE_FOLDER ?? env.GLYTCH_FOLDER)?.trim();
|
|
25
25
|
if (named === "off") return null;
|
|
26
26
|
if (named) return resolve(named);
|
|
27
27
|
if ((env.VIEWABLE_HOME ?? env.GLYTCH_HOME)?.trim()) return null;
|
|
28
|
-
|
|
28
|
+
const documents = join(home, "Documents", "Viewable");
|
|
29
|
+
const current = join(home, "Viewable");
|
|
30
|
+
const legacy = join(home, "Glytch");
|
|
31
|
+
if (existsSync(documents)) return documents;
|
|
32
|
+
if (existsSync(current)) return current;
|
|
33
|
+
if (existsSync(legacy)) return legacy;
|
|
34
|
+
return documents;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
const README =
|
|
@@ -37,19 +43,19 @@ const README =
|
|
|
37
43
|
// A first commit needs a name and an email, and a fresh machine may have
|
|
38
44
|
// neither. These apply to this one commit only; signing is off for the same
|
|
39
45
|
// reason (a signing prompt would hang the daemon).
|
|
40
|
-
const COMMITTER = ["-c", "user.name=Viewable", "-c", "user.email=
|
|
46
|
+
const COMMITTER = ["-c", "user.name=Viewable", "-c", "user.email=viewable@localhost", "-c", "commit.gpgsign=false"];
|
|
41
47
|
|
|
42
|
-
/** Make the
|
|
48
|
+
/** Make the default working folder if it is missing, as a git repository with one
|
|
43
49
|
* commit (a chat worktree is cut from a commit), and register it. Returns
|
|
44
50
|
* the path, or null when there is none. Never throws: a daemon that cannot
|
|
45
51
|
* make it still watches every other folder. */
|
|
46
|
-
export async function
|
|
47
|
-
const path =
|
|
52
|
+
export async function ensureViewableFolder(env = process.env, log = () => {}) {
|
|
53
|
+
const path = viewableFolderPath(env);
|
|
48
54
|
if (path === null) return null;
|
|
49
55
|
try {
|
|
50
56
|
await mkdir(path, { recursive: true });
|
|
51
57
|
// Its own repository, not one it happens to sit inside: a home folder
|
|
52
|
-
// kept under git would otherwise lend
|
|
58
|
+
// kept under git would otherwise lend the working folder its history.
|
|
53
59
|
const top = await git(["rev-parse", "--show-toplevel"], path);
|
|
54
60
|
if (!top.ok || (await realpath(top.stdout.trim())) !== (await realpath(path))) {
|
|
55
61
|
const init = await git(["init"], path);
|