djournal 0.10.0 → 0.12.0

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.
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+
3
+ const { stripVTControlCharacters } = require("node:util");
4
+
5
+ // Two offset journal pages, with a bookmark on the front page.
6
+ const JOURNAL_MARK = [
7
+ " ┌────┬─┐",
8
+ "┌──┤ │ │",
9
+ "│ │ ▾ │",
10
+ "│ └──────┘",
11
+ "└──────┘",
12
+ ];
13
+ const ASCII_MARK = [
14
+ " +----+-+",
15
+ "+--| | |",
16
+ "| | v |",
17
+ "| +------+",
18
+ "+------+",
19
+ ];
20
+
21
+ function wrap(text, width) {
22
+ return String(text).split("\n").flatMap((line) => {
23
+ const lines = [];
24
+ let chars = Array.from(line);
25
+ while (chars.length > width) {
26
+ let end = chars.slice(0, width + 1).lastIndexOf(" ");
27
+ if (end < width / 2) end = width;
28
+ lines.push(chars.slice(0, end).join(""));
29
+ chars = chars.slice(end);
30
+ if (chars[0] === " ") chars.shift();
31
+ }
32
+ return [...lines, chars.join("")];
33
+ }).join("\n");
34
+ }
35
+
36
+ function presentation(output, env = process.env) {
37
+ const color = env.NO_COLOR === undefined && env.TERM !== "dumb" && env.FORCE_COLOR !== "0" &&
38
+ (Boolean(env.FORCE_COLOR) || (output.getColorDepth?.() || 1) >= 4);
39
+ const paint = (code) => (text) => color ? `\x1b[${code}m${text}\x1b[0m` : String(text);
40
+ const accent = paint("36"), bold = paint("1"), muted = paint("2");
41
+ const plainTerminal = env.TERM === "dumb";
42
+ const width = () => Math.max(12, (output.columns || 80) - 4);
43
+ const rows = () => output.rows || 24;
44
+ const indent = (text) => String(text).split("\n").map((line) => ` ${line}`).join("\n");
45
+ const fit = (text) => wrap(stripVTControlCharacters(String(text)), width());
46
+
47
+ const clipped = (text, count) => {
48
+ const lines = fit(text).split("\n");
49
+ if (lines.length > count) lines[count - 1] = lines[count - 1].slice(0, Math.max(0, width() - 3)) + "...";
50
+ return indent(lines.slice(0, count).join("\n"));
51
+ };
52
+
53
+ function banner(compact) {
54
+ if (compact) return `${accent(plainTerminal ? "[=]" : "▤")} ${bold("djournal")}`;
55
+ return (plainTerminal ? ASCII_MARK : JOURNAL_MARK).map((line, index) => accent(line) +
56
+ (index === 2 ? ` ${bold("djournal")}` : "")).join("\n");
57
+ }
58
+
59
+ function frame(header, messages, type, question = "", choices = []) {
60
+ const context = messages.join("\n").trim();
61
+ const contextLines = context ? fit(context).split("\n").length + 1 : 0;
62
+ const lines = [];
63
+ if (typeof header === "object" && header) {
64
+ const compact = type === "search" || type === "filters" || width() < 32 || rows() < 24 || contextLines >= 4;
65
+ lines.push(indent(banner(compact)));
66
+ lines.push(type === "search" || type === "filters" ? clipped(`Project: ${header.project}`, 1) : indent(fit(`Project: ${header.project}`)));
67
+ } else if (header) lines.push(indent(fit(header)));
68
+ lines.push(indent(muted("-".repeat(Math.min(60, width())))));
69
+ const controls = type === "checkbox"
70
+ ? "Up/Down move Space toggle Enter continue"
71
+ : type === "search" ? "Up/Down select Enter open Tab filters"
72
+ : type === "filters" ? "Up/Down field Left/Right change"
73
+ : type === "select" ? "Up/Down move Enter select" : "Enter accept";
74
+ const navigation = type === "search"
75
+ ? "Up/Down select Enter open\nTab filters Esc back Ctrl-C exit"
76
+ : type === "filters"
77
+ ? `${controls}\nEnter apply Esc discard\nCtrl-R reset Ctrl-C exit`
78
+ : `${controls} Esc back Ctrl-C exit`;
79
+ const hints = type === "search" || type === "filters" || navigation.length <= width() ? navigation : `${controls}\nEsc back Ctrl-C exit`;
80
+ lines.push(indent(muted(fit(hints))), "");
81
+ if (context) {
82
+ for (const line of fit(context).split("\n")) {
83
+ const style = /^(?:[A-Z_]+:|fail\b)/.test(line) ? paint("31") : /^ok\b|^Configuration saved/.test(line) ? paint("32") : (text) => text;
84
+ lines.push(indent(style(line)));
85
+ }
86
+ lines.push("");
87
+ }
88
+ const text = lines.join("\n") + "\n";
89
+ const used = text.split("\n").length + fit(question).split("\n").length;
90
+ const descriptionLines = Math.max(1, ...choices.map((choice) => choice.description ? fit(choice.description).split("\n").length : 0));
91
+ if (type === "search" || type === "filters") return { text, pageSize: Math.max(1, Math.min(8, rows() - used - (type === "search" ? 6 : 4))) };
92
+ return { text, pageSize: Math.max(3, Math.min(10, rows() - used - descriptionLines - 3)) };
93
+ }
94
+
95
+ function choices(items) {
96
+ return items.map(([value, label, detail]) => {
97
+ const full = stripVTControlCharacters(String(label));
98
+ const limit = width() - 2;
99
+ const long = Array.from(full).length > limit;
100
+ return {
101
+ value,
102
+ name: long ? Array.from(full).slice(0, limit - 3).join("") + "..." : full,
103
+ description: [long ? full : "", detail].filter(Boolean).join("\n") || undefined,
104
+ };
105
+ });
106
+ }
107
+
108
+ const theme = {
109
+ prefix: { idle: "", done: "" },
110
+ icon: { cursor: ">", checked: "[x]", unchecked: "[ ]" },
111
+ helpMode: "never",
112
+ style: {
113
+ message: (text) => indent(bold(fit(text))) + "\n",
114
+ highlight: (text) => accent(bold(text)),
115
+ answer: accent,
116
+ description: (text) => indent(muted(fit(text))),
117
+ line: (text) => clipped(text, 1),
118
+ detail: (text) => muted(clipped(text, 2)),
119
+ error: (text) => indent(paint("31")(fit(`Error: ${text}`))),
120
+ defaultAnswer: (text) => muted(`(${text})`),
121
+ help: muted,
122
+ key: bold,
123
+ disabled: muted,
124
+ disabledChoice: muted,
125
+ keysHelpTip: () => "",
126
+ },
127
+ };
128
+ return {
129
+ frame, choices,
130
+ theme: (type) => ({
131
+ ...theme,
132
+ style: {
133
+ ...theme.style,
134
+ message: (text) => type === "input" || type === "confirm"
135
+ ? ` ${bold(fit(text))}\n >`
136
+ : theme.style.message(text),
137
+ },
138
+ }),
139
+ };
140
+ }
141
+
142
+ module.exports = { presentation };
package/lib/setup.js ADDED
@@ -0,0 +1,396 @@
1
+ "use strict";
2
+
3
+ const path = require("node:path");
4
+ const installer = require("./installer/index.js");
5
+ const entries = require("./setup-entries.js");
6
+ const recall = require("./recall/index.js");
7
+ const { filterFields, filterSummary } = require("./setup-filters.js");
8
+ const { presentation } = require("./setup-style.js");
9
+
10
+ class Cancelled extends Error {}
11
+ class Back extends Error {}
12
+
13
+ // Keep the flow independent of the prompt library so operations remain testable.
14
+ function terminal(input = process.stdin, output = process.stdout, env = process.env) {
15
+ if (!input.isTTY || !output.isTTY) {
16
+ throw new installer.InstallerError("The wizard requires an interactive terminal; use djournal --help for commands, or djournal status --json for automation", "INTERACTIVE_REQUIRED");
17
+ }
18
+ const prompts = { ...require("@inquirer/prompts"), search: require("./setup-search.js").searchPrompt, filters: require("./setup-filters.js").filterPrompt };
19
+ const style = presentation(output, env);
20
+ const clearScreen = "\x1b[2J\x1b[H";
21
+ let header = "";
22
+ let messages = [];
23
+ function frame(type, question, choices) {
24
+ output.write(clearScreen);
25
+ const layout = style.frame(header, messages, type, question, choices);
26
+ output.write(layout.text);
27
+ messages = [];
28
+ return layout;
29
+ }
30
+ const controller = new AbortController();
31
+ let activePrompt;
32
+ const cancel = () => controller.abort();
33
+ const onKey = (_value, key) => {
34
+ if (key?.ctrl && key.name === "d") cancel();
35
+ else if (key?.name === "escape") activePrompt?.abort(new Back());
36
+ };
37
+ input.on("end", cancel);
38
+ input.on("close", cancel);
39
+ input.on("keypress", onKey);
40
+ if (input.readableEnded || input.destroyed) cancel();
41
+ async function prompt(type, config) {
42
+ if (controller.signal.aborted) throw new Cancelled();
43
+ const layout = frame(type, config.message, config.choices);
44
+ const current = new AbortController();
45
+ activePrompt = current;
46
+ const abort = () => current.abort();
47
+ controller.signal.addEventListener("abort", abort, { once: true });
48
+ try { return await prompts[type]({ ...config, pageSize: layout.pageSize, theme: style.theme(type) }, {
49
+ input, output, signal: current.signal, clearPromptOnDone: true,
50
+ }); }
51
+ catch (error) {
52
+ if (current.signal.reason instanceof Back && !controller.signal.aborted) throw current.signal.reason;
53
+ if (["ExitPromptError", "AbortPromptError"].includes(error.name) || controller.signal.aborted) throw new Cancelled();
54
+ throw error;
55
+ } finally {
56
+ controller.signal.removeEventListener("abort", abort);
57
+ activePrompt = undefined;
58
+ }
59
+ }
60
+ const choicesFor = style.choices;
61
+ return {
62
+ header: (message) => { header = message; },
63
+ // Messages belong to the next frame, so clearing never hides a new result.
64
+ write: (message) => { messages.push(message); },
65
+ choose: (message, choices, defaultValue) => prompt("select", {
66
+ message, choices: choicesFor(choices), default: defaultValue, pageSize: 10, loop: false,
67
+ }),
68
+ search: (message, source, { query = "", scope = "All work / all types" } = {}) => prompt("search", {
69
+ message, query, scope,
70
+ source: async (term, context) => {
71
+ const result = await source(term, context);
72
+ return { ...result, choices: choicesFor(result.choices) };
73
+ },
74
+ }),
75
+ filters: (filters, fields) => prompt("filters", { message: "Search filters", filters, fields }),
76
+ multiple: (message, choices, defaults = []) => prompt("checkbox", {
77
+ message,
78
+ choices: choicesFor(choices).map((choice) => ({ ...choice, checked: defaults.includes(choice.value) })),
79
+ pageSize: 10, loop: false,
80
+ }),
81
+ text: async (message, defaultValue = "", validate = () => true) => {
82
+ const answer = await prompt("input", {
83
+ message, default: defaultValue,
84
+ validate: (value) => (value.trim() && validate(value.trim())) || "Enter a valid value.",
85
+ });
86
+ return answer.trim();
87
+ },
88
+ confirm: (message, defaultValue = false) => prompt("confirm", { message, default: defaultValue }),
89
+ external: async (operation) => {
90
+ output.write(clearScreen);
91
+ const raw = input.isRaw;
92
+ const flowing = input.readableFlowing;
93
+ input.removeListener("keypress", onKey);
94
+ input.pause();
95
+ if (input.isTTY && input.setRawMode) input.setRawMode(false);
96
+ try { return await operation(); }
97
+ finally {
98
+ if (input.isTTY && input.setRawMode) input.setRawMode(!!raw);
99
+ input.on("keypress", onKey);
100
+ if (flowing) input.resume();
101
+ }
102
+ },
103
+ close: () => {
104
+ cancel();
105
+ input.removeListener("end", cancel);
106
+ input.removeListener("close", cancel);
107
+ input.removeListener("keypress", onKey);
108
+ output.write(clearScreen);
109
+ if (messages.length) output.write(`${messages.join("\n")}\n`);
110
+ messages = [];
111
+ },
112
+ };
113
+ }
114
+
115
+ async function setup(options, dependencies = {}) {
116
+ const ui = dependencies.ui || terminal();
117
+ const api = { ...installer, ...entries, ...recall, ...dependencies.api };
118
+ const print = dependencies.print || ((result) => ui.write(JSON.stringify(result, null, 2)));
119
+ const base = { target: path.resolve(options.target || process.cwd()), sourceRoot: options.sourceRoot, interactive: false };
120
+ let failed = false;
121
+ async function menu(message, choices) {
122
+ try { return await ui.choose(message, choices); }
123
+ catch (error) { if (error instanceof Back) return "back"; throw error; }
124
+ }
125
+ async function backToMenu(operation) {
126
+ try { return await operation(); }
127
+ catch (error) { if (error instanceof Back) return false; throw error; }
128
+ }
129
+ async function run(name, extra = {}) {
130
+ const result = await api[name]({ ...base, ...extra });
131
+ print(result, false, { write: (text) => ui.write(text.replace(/\n$/, "")) });
132
+ if (result.ok === false || result.clean === false || result.installed === false || result.conflicts?.length) failed = true;
133
+ return result;
134
+ }
135
+
136
+ const configuration = () => backToMenu(configureProject);
137
+ async function configureProject() {
138
+ const { config } = await api.configure(base);
139
+ const changes = [];
140
+ ui.write("\nConfigure this project. Enter keeps the displayed setting; nothing is saved until you confirm.");
141
+ const mode = await ui.choose("Where should selected work items be shared?", [
142
+ ["local", "Keep work local", "Disable synchronization for this project."],
143
+ ["colocated", "Use this project's Git repository", "Share selected work through this project's journal projection."],
144
+ ["standalone", "Use a separate Git repository", "Keep shared journal history in an existing journal repository."],
145
+ ["back", "Back"],
146
+ ], config.sync?.enabled ? config.sync.mode : "local");
147
+ if (mode === "back") return false;
148
+ if (mode === "local") changes.push(["sync.enabled", "false"]);
149
+ else {
150
+ changes.push(["sync.mode", mode]);
151
+ const location = mode === "colocated" ? base.target : path.resolve(base.target, await ui.text(
152
+ "Path to the existing journal Git repository",
153
+ config.sync?.mode === "standalone" ? config.sync.path : "",
154
+ ));
155
+ changes.push(["sync.path", location]);
156
+ const auto = mode === "standalone" && await ui.confirm(
157
+ "Automatically sync shared work after journal closure (may commit and push)?",
158
+ config.sync?.mode === "standalone" && !!config.sync.auto,
159
+ );
160
+ changes.push(["sync.auto", String(auto)], ["sync.enabled", "true"]);
161
+ ui.write("Sharing is opt-in per work item. Use List to select work to share.");
162
+ }
163
+ const updates = await ui.confirm("Check periodically for djournal updates?", config.updates?.enabled !== false);
164
+ changes.push(["updates.enabled", String(updates)]);
165
+ if (updates) {
166
+ const interval = await ui.text("Hours between update checks", String(config.updates?.intervalHours || 24),
167
+ (value) => Number.isFinite(Number(value)) && Number(value) > 0);
168
+ changes.push(["updates.intervalHours", String(Number(interval))]);
169
+ }
170
+ const pending = changes.filter(([key, value]) => {
171
+ const current = key.split(".").reduce((object, part) => object?.[part], config);
172
+ return String(current) !== value;
173
+ });
174
+ if (!pending.length) { ui.write("Configuration is already up to date."); return true; }
175
+ ui.write(`\nConfiguration changes for ${base.target}:`);
176
+ for (const [key, value] of pending) ui.write(` ${key}: ${value}`);
177
+ if (!await ui.confirm("Save these settings?")) return false;
178
+ for (const [key, value] of pending) await api.configure({ ...base, key, value });
179
+ ui.write("Configuration saved.");
180
+ return true;
181
+ }
182
+
183
+ async function installation() {
184
+ const detected = api.detectHarnesses(base.target);
185
+ ui.write(`\nDetected integrations: ${detected.supported.join(", ") || "none"}.`);
186
+ const choice = await ui.choose("Which coding-agent integrations should be installed?", [
187
+ ...installer.SUPPORTED_HARNESSES.map((name) => [name, name]),
188
+ ["all", "All supported integrations"],
189
+ ["custom", "Choose multiple integrations"],
190
+ ["instructions", "Instructions only (no hooks)"],
191
+ ["back", "Back"],
192
+ ]);
193
+ if (choice === "back") return;
194
+ let harnesses = [];
195
+ if (choice === "custom") {
196
+ harnesses = await ui.multiple("Choose integrations (Space to toggle, Enter to continue)",
197
+ installer.SUPPORTED_HARNESSES.map((name) => [name, name]), detected.supported);
198
+ } else if (choice === "all") harnesses = [...installer.SUPPORTED_HARNESSES];
199
+ else if (choice !== "instructions") harnesses = [choice];
200
+ ui.write("Existing integrations are retained when installing into an installed project.");
201
+ if (!await ui.confirm(`Install ${harnesses.join(", ") || "instructions only"} in ${base.target}?`)) return;
202
+ await run("install", { harnesses, instructionsOnly: !harnesses.length });
203
+ await configuration();
204
+ }
205
+
206
+ async function workItems() {
207
+ while (true) {
208
+ let result;
209
+ try { result = await api.listWork(base); }
210
+ catch (error) {
211
+ if (error.code !== "NO_ACTIVE_WORK") throw error;
212
+ ui.write("No work items yet. Ask your coding agent to start a new work item with init-work.");
213
+ return;
214
+ }
215
+ const selected = await menu("Choose a work item", [
216
+ ...result.workItems.map((item) => [item.slug, `${item.title} [${item.status}]${item.selected ? " *" : ""}`,
217
+ `${item.slug}\nVisibility: ${item.visibility || "unknown"}${item.selected ? " | Selected work" : ""}`]),
218
+ ["back", "Back"],
219
+ ]);
220
+ if (selected === "back") return;
221
+ const item = result.workItems.find((candidate) => candidate.slug === selected);
222
+ while (true) {
223
+ ui.write(`\n${item.title}\n${item.slug}\nStatus: ${item.status}; visibility: ${item.visibility}`);
224
+ const action = await menu("What would you like to do with this work item?", [
225
+ ["entries", "Open entry in editor", "Browse this work's journal, research, docs, and decisions."],
226
+ ["share", "Share", "Mark this work for Git synchronization."],
227
+ ["pull", "Pull", "Import changes from the journal projection."],
228
+ ["sync", "Sync", "Import and export shared work."],
229
+ ...(item.status === "active" ? [["bindWork", "Bind to a session", "Select this work for an agent session."]] : []),
230
+ ["back", "Back to work items"],
231
+ ]);
232
+ if (action === "back") break;
233
+ if (action === "entries") { await browseEntries(item); continue; }
234
+ await backToMenu(async () => {
235
+ if (action === "bindWork") {
236
+ const session = await ui.text("Agent session ID", process.env.DJOURNAL_SESSION_ID || "");
237
+ if (await ui.confirm(`Bind ${item.slug} to this session?`)) await run(action, { work: item.slug, session });
238
+ return;
239
+ }
240
+ const { config } = await api.configure(base);
241
+ if (!config.sync?.enabled) {
242
+ ui.write("Synchronization is disabled for this project.");
243
+ if (!await ui.confirm("Configure synchronization now?")) return;
244
+ await configuration();
245
+ const updated = await api.configure(base);
246
+ if (!updated.config.sync?.enabled) return;
247
+ }
248
+ const warning = action === "sync" ? " This may commit and push in standalone mode." : "";
249
+ if (!await ui.confirm(`${action} ${item.slug}?${warning}`)) return;
250
+ await run(action, { work: item.slug });
251
+ if (action === "share") ui.write("Work marked for sharing. Use Sync to copy it to the Git projection.");
252
+ });
253
+ }
254
+ }
255
+ }
256
+
257
+ async function browseEntries(item) {
258
+ while (true) {
259
+ const records = await api.listEntries({ ...base, work: item.slug });
260
+ if (!records.length) { ui.write("No journal entries yet for this work item."); return; }
261
+ const selected = await menu("Open an entry (close the editor to return)", [
262
+ ...records.map((entry) => [entry.relative, entry.title,
263
+ `${entry.date?.slice(0, 10) || "Undated"} | ${entry.entryType}\n${entry.relative.split("/").slice(2).join("/")}`]),
264
+ ["back", "Back to work item"],
265
+ ]);
266
+ if (selected === "back") return;
267
+ const entry = records.find((record) => record.relative === selected);
268
+ await openInEditor(() => entry);
269
+ }
270
+ }
271
+
272
+ async function openInEditor(resolveEntry) {
273
+ try {
274
+ const entry = await resolveEntry();
275
+ const open = () => api.openEntry(entry, { cwd: base.target });
276
+ if (ui.external) await ui.external(open);
277
+ else await open();
278
+ } catch (error) {
279
+ if (error instanceof Cancelled) throw error;
280
+ failed = true;
281
+ ui.write(`${error.code || "EDITOR_ERROR"}: ${error.message}`);
282
+ }
283
+ }
284
+
285
+ async function recallMenu() {
286
+ let filters = { limit: 10 };
287
+ async function editFilters() {
288
+ let workItems = [];
289
+ try { ({ workItems } = await api.listWork(base)); }
290
+ catch (error) { if (error.code !== "NO_ACTIVE_WORK") throw error; }
291
+ filters = await ui.filters(filters, filterFields(workItems));
292
+ }
293
+ async function search() {
294
+ let query = "";
295
+ while (true) {
296
+ const selected = await ui.search("Search journal", async (term, { signal }) => {
297
+ let result;
298
+ try { result = await api.searchRecall(term, { ...base, ...filters }); }
299
+ catch (error) { if (!signal.aborted) failed = true; throw error; }
300
+ const matches = [...result.workItems, ...result.entries].sort((a, b) => b.score - a.score);
301
+ const message = [matches.length ? `${matches.length} results (up to ${filters.limit} per kind).` : "No matches. Edit query or Tab for filters."];
302
+ for (const warning of (result.warnings || []).slice(0, 3)) message.push(`Warning: ${warning.code}${warning.path ? ` - ${warning.path}` : ""}`);
303
+ if (result.warnings?.length > 3) message.push(`${result.warnings.length - 3} more warnings; use djournal recall index --json for details.`);
304
+ return {
305
+ choices: matches.map((item) => [item, item.title, [item.entryType, item.summary, item.path].filter(Boolean).join("\n")]),
306
+ message: message.filter(Boolean).join("\n"),
307
+ };
308
+ }, { query, scope: filterSummary(filters) });
309
+ query = selected.query;
310
+ if (selected.value === "back") return;
311
+ if (selected.value === "filters") await backToMenu(editFilters);
312
+ else await openInEditor(() => api.recallEntry(selected.value, base));
313
+ }
314
+ }
315
+
316
+ while (true) {
317
+ const action = await menu("Recall", [
318
+ ["search", "Search journal", "Find entries and work items, then open their canonical Markdown."],
319
+ ["index", "Refresh index", "Update the search cache from the current journal."],
320
+ ["rebuild", "Rebuild index", "Recreate the disposable search cache. Journal entries are kept."],
321
+ ["back", "Back"],
322
+ ]);
323
+ if (action === "back") return;
324
+ await backToMenu(async () => {
325
+ if (action === "search") await search();
326
+ else if (action === "index" || await ui.confirm("Rebuild the recall index?")) {
327
+ await run("buildRecallIndex", { rebuild: action === "rebuild" });
328
+ }
329
+ });
330
+ }
331
+ }
332
+
333
+ async function uninstallation() {
334
+ const manifest = await api.loadManifest(base.target);
335
+ if (!manifest) throw new installer.InstallerError("djournal is not installed in this project", "NOT_INSTALLED");
336
+ const choice = await menu("Remove which integrations?", [
337
+ ["all", "All integrations and installed assets"],
338
+ ...manifest.harnesses.map((name) => [name, name]), ["back", "Back"],
339
+ ]);
340
+ if (choice === "back") return;
341
+ ui.write("Journal entries are kept. Modified installed files are preserved and reported as conflicts.");
342
+ if (await ui.confirm(`Uninstall ${choice === "all" ? "all integrations" : choice} from ${base.target}?`)) {
343
+ await run("uninstall", choice === "all" ? { all: true } : { harnesses: [choice] });
344
+ }
345
+ }
346
+
347
+ try {
348
+ const heading = `djournal\nProject: ${base.target}\nUse ↑/↓ to navigate and Enter to select. Esc goes back; Ctrl-C exits. Completed actions are kept.`;
349
+ if (ui.header) ui.header({ project: base.target });
350
+ else ui.write(heading);
351
+ while (true) {
352
+ const action = await menu("What would you like to do?", [
353
+ ["list", "List", "Browse work items, open entries, and manage sharing."],
354
+ ["recall", "Recall", "Search journal knowledge and manage its search index."],
355
+ ["status", "Status", "View installation, integration, and version status."],
356
+ ["install", "Install", "Add djournal integrations and configure this project."],
357
+ ["configure", "Configure", "Set sharing and update preferences."],
358
+ ["upgrade", "Upgrade", "Refresh this project's installed journal assets."],
359
+ ["update", "Update", "Check for a newer CLI release."],
360
+ ["doctor", "Doctor", "Check this project's journal installation."],
361
+ ["uninstall", "Uninstall", "Remove installed integrations while keeping journal history."],
362
+ ["exit", "Exit", "Return to your shell. Completed actions are kept."],
363
+ ]);
364
+ if (action === "exit") return { failed };
365
+ if (action === "back") continue;
366
+ try {
367
+ if (action === "list") await workItems();
368
+ else if (action === "recall") await recallMenu();
369
+ else if (action === "status") await run("status");
370
+ else if (action === "uninstall") await uninstallation();
371
+ else if (action === "install") await installation();
372
+ else if (action === "configure") await configuration();
373
+ else if (action === "upgrade") {
374
+ if (await ui.confirm(`Upgrade installed assets in ${base.target}?`)) await run("upgrade");
375
+ } else if (action === "update") {
376
+ const result = await run("checkUpdates");
377
+ if (result.updateAvailable) ui.write("To update the CLI, run: npm install -g djournal@latest\nThen use Upgrade to refresh this project's assets.");
378
+ } else if (action === "doctor") await run("doctor");
379
+ } catch (error) {
380
+ if (error instanceof Back) continue;
381
+ if (error instanceof Cancelled) throw error;
382
+ failed = true;
383
+ ui.write(`${error.code || "ERROR"}: ${error.message}`);
384
+ if (error.code === "NOT_INSTALLED") ui.write("Choose Install from the main menu to initialize this project.");
385
+ }
386
+ }
387
+ } catch (error) {
388
+ if (!(error instanceof Cancelled)) throw error;
389
+ ui.write("\nWizard cancelled. Completed actions have been kept.");
390
+ return { cancelled: true, failed };
391
+ } finally {
392
+ ui.close();
393
+ }
394
+ }
395
+
396
+ module.exports = { Back, Cancelled, setup, terminal };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "djournal",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "Durable project memory for coding agents, stored as linked Markdown",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -11,7 +11,9 @@
11
11
  ".agents/",
12
12
  ".claude/",
13
13
  ".codex/",
14
+ ".grokbot/",
14
15
  ".pi/",
16
+ "integrations/",
15
17
  "AGENTS.md",
16
18
  "CLAUDE.md",
17
19
  "LICENSE",
@@ -27,7 +29,7 @@
27
29
  "benchmark:recall": "node scripts/benchmark-recall.cjs",
28
30
  "link:global": "npm link",
29
31
  "release": "semantic-release",
30
- "test": "node tests/update-checker.test.js && node tests/journal-hook.test.js && node tests/pi-adapter.test.js && node tests/recall.test.js && node tests/recall-files.test.js && node tests/installer/installer.test.js && node tests/release-policy.test.js && node tests/skill-instructions.test.js && npm run check:package",
32
+ "test": "node tests/setup.test.js && node tests/update-checker.test.js && node tests/journal-hook.test.js && node tests/pi-adapter.test.js && node tests/recall.test.js && node tests/recall-files.test.js && node tests/installer/installer.test.js && node tests/release-policy.test.js && node tests/skill-instructions.test.js && npm run check:package",
31
33
  "prepublishOnly": "npm test"
32
34
  },
33
35
  "repository": {
@@ -57,6 +59,8 @@
57
59
  "semantic-release": "25.0.3"
58
60
  },
59
61
  "dependencies": {
62
+ "@inquirer/core": "10.3.2",
63
+ "@inquirer/prompts": "7.10.1",
60
64
  "minisearch": "7.2.0",
61
65
  "semver": "7.8.5",
62
66
  "yaml": "2.9.0"