@cueloop/client 0.1.0-alpha.9 → 0.1.0-alpha.90
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/native/build-pty.sh +51 -0
- package/native/build.sh +82 -0
- package/native/darwin-arm64/libcuelooppty.dylib +0 -0
- package/native/darwin-arm64/libcueloopvt.dylib +0 -0
- package/native/src/pty.zig +193 -0
- package/native/src/shim.zig +114 -0
- package/package.json +42 -34
- package/src/App.appearance.test.tsx +53 -0
- package/src/App.autoclose.test.tsx +77 -51
- package/src/App.diff.test.tsx +259 -45
- package/src/App.export.test.tsx +58 -41
- package/src/App.focus.test.ts +89 -0
- package/src/App.identity.test.tsx +78 -0
- package/src/App.plan-render.test.tsx +209 -0
- package/src/App.plan-review.test.tsx +330 -161
- package/src/App.prototype-markdown.test.tsx +128 -0
- package/src/App.prototype.test.tsx +176 -0
- package/src/App.readonly.test.tsx +129 -67
- package/src/App.regression.test.tsx +94 -0
- package/src/App.rendering.test.tsx +61 -35
- package/src/App.share-dialog.test.tsx +172 -0
- package/src/App.submit-confirm.test.tsx +264 -0
- package/src/App.test.tsx +402 -126
- package/src/App.toast.test.tsx +98 -0
- package/src/App.tsx +1402 -1060
- package/src/App.visual.test.tsx +57 -0
- package/src/App.walk.test.tsx +299 -0
- package/src/App.workbench.test.tsx +774 -0
- package/src/__snapshots__/view-plan.regression.test.ts.snap +100 -0
- package/src/annotation-palette.ts +62 -0
- package/src/ansi-screen.test.ts +28 -0
- package/src/ansi-screen.ts +72 -0
- package/src/app-key-state.ts +61 -0
- package/src/app-screens.tsx +577 -0
- package/src/app-view-model.ts +168 -0
- package/src/attribution.test.ts +31 -0
- package/src/attribution.ts +42 -0
- package/src/client-extension-registry.test.tsx +61 -0
- package/src/client-extension-registry.ts +159 -0
- package/src/clipboard.test.ts +23 -0
- package/src/clipboard.ts +33 -0
- package/src/components/AnnotatableFileView.stories.tsx +42 -0
- package/src/components/AnnotatableFileView.test.tsx +102 -0
- package/src/components/AnnotatableFileView.tsx +134 -0
- package/src/components/AnnotationCards.stories.tsx +86 -0
- package/src/components/AnnotationCards.tsx +341 -0
- package/src/components/AnsiScreen.stories.tsx +12 -0
- package/src/components/AnsiScreen.tsx +28 -0
- package/src/components/AppHeader.stories.tsx +50 -0
- package/src/components/AppHeader.tsx +83 -0
- package/src/components/AppShell.brand.test.tsx +58 -0
- package/src/components/AppShell.extensions.test.tsx +191 -0
- package/src/components/AppShell.stories.tsx +89 -0
- package/src/components/AppShell.tsx +362 -0
- package/src/components/AppShell.zoom.test.tsx +135 -0
- package/src/components/BareWorkbenchFileView.stories.tsx +27 -0
- package/src/components/BareWorkbenchFileView.tsx +64 -0
- package/src/components/Breadcrumb.stories.tsx +19 -0
- package/src/components/Breadcrumb.tsx +45 -0
- package/src/components/ChangesColumn.stories.tsx +44 -0
- package/src/components/ChangesColumn.tsx +199 -0
- package/src/components/ChangesFileTree.test.tsx +61 -0
- package/src/components/CodeBlock.stories.tsx +42 -0
- package/src/components/CodeBlock.tsx +84 -0
- package/src/components/CompletionOverlay.stories.tsx +37 -0
- package/src/components/CompletionOverlay.tsx +77 -0
- package/src/components/ConfirmCard.stories.tsx +37 -0
- package/src/components/ConfirmCard.tsx +150 -0
- package/src/components/ConfirmDialog.stories.tsx +21 -0
- package/src/components/ConfirmDialog.tsx +72 -0
- package/src/components/DiffContentView.scroll.test.tsx +149 -0
- package/src/components/DiffContentView.split.test.tsx +140 -0
- package/src/components/DiffContentView.stories.tsx +80 -0
- package/src/components/DiffContentView.syntax.test.tsx +82 -0
- package/src/components/DiffContentView.tsx +906 -0
- package/src/components/DiscussionMarkerRail.stories.tsx +54 -0
- package/src/components/DiscussionMarkerRail.tsx +186 -0
- package/src/components/EditorGrid.stories.tsx +59 -0
- package/src/components/EditorGrid.tabs.test.tsx +118 -0
- package/src/components/EditorGrid.tsx +426 -0
- package/src/components/EditorGrid.zoom.test.tsx +68 -0
- package/src/components/ExtensionZone.stories.tsx +28 -0
- package/src/components/ExtensionZone.tsx +145 -0
- package/src/components/FileContentsView.stories.tsx +16 -0
- package/src/components/FileContentsView.test.tsx +29 -0
- package/src/components/FileContentsView.tsx +98 -0
- package/src/components/GridTabContent.stories.tsx +59 -0
- package/src/components/GridTabContent.tsx +182 -0
- package/src/components/HandleChipsInput.stories.tsx +24 -0
- package/src/components/HandleChipsInput.test.tsx +35 -0
- package/src/components/HandleChipsInput.tsx +145 -0
- package/src/components/KeybindsDialog.stories.tsx +31 -0
- package/src/components/KeybindsDialog.tsx +103 -0
- package/src/components/MarkdownGridBlock.stories.tsx +33 -0
- package/src/components/MarkdownGridBlock.tsx +72 -0
- package/src/components/MarkdownThreadEditor.stories.tsx +15 -0
- package/src/components/MarkdownThreadEditor.test.tsx +98 -0
- package/src/components/MarkdownThreadEditor.tsx +162 -0
- package/src/components/MenuBar.stories.tsx +28 -0
- package/src/components/MenuBar.tsx +44 -0
- package/src/components/NavModeHint.stories.tsx +40 -0
- package/src/components/NavModeHint.tsx +31 -0
- package/src/components/OverlayScrollbar.stories.tsx +33 -0
- package/src/components/OverlayScrollbar.test.tsx +139 -0
- package/src/components/OverlayScrollbar.tsx +129 -0
- package/src/components/PaneGrid.stories.tsx +84 -0
- package/src/components/PaneGrid.tsx +128 -0
- package/src/components/PanelColumn.stories.tsx +25 -0
- package/src/components/PanelColumn.tsx +98 -0
- package/src/components/ProjectTreeView.stories.tsx +25 -0
- package/src/components/ProjectTreeView.test.tsx +75 -0
- package/src/components/ProjectTreeView.tsx +125 -0
- package/src/components/PromptDialog.stories.tsx +36 -0
- package/src/components/PromptDialog.test.tsx +61 -0
- package/src/components/PromptDialog.tsx +99 -0
- package/src/components/PrototypeContentView.stories.tsx +19 -0
- package/src/components/PrototypeContentView.tsx +446 -0
- package/src/components/RootOverlay.stories.tsx +45 -0
- package/src/components/RootOverlay.tsx +48 -0
- package/src/components/ScrollArea.stories.tsx +20 -0
- package/src/components/ScrollArea.tsx +44 -0
- package/src/components/SettingsDialog.stories.tsx +117 -0
- package/src/components/SettingsDialog.tsx +186 -0
- package/src/components/SettingsRows.stories.tsx +18 -0
- package/src/components/SettingsRows.tsx +112 -0
- package/src/components/ShareDialog.stories.tsx +121 -0
- package/src/components/ShareDialog.tsx +552 -0
- package/src/components/ShellHeader.stories.tsx +50 -0
- package/src/components/ShellHeader.tsx +137 -0
- package/src/components/SlashComposer.stories.tsx +37 -0
- package/src/components/SlashComposer.tsx +87 -0
- package/src/components/ThreadFooter.stories.tsx +30 -0
- package/src/components/ThreadFooter.test.tsx +47 -0
- package/src/components/ThreadFooter.tsx +76 -0
- package/src/components/ThreadTree.stories.tsx +46 -0
- package/src/components/ThreadTree.tsx +255 -0
- package/src/components/ThreadView.selection.test.tsx +951 -0
- package/src/components/ThreadView.slash.test.tsx +146 -0
- package/src/components/ThreadView.stories.tsx +26 -0
- package/src/components/ThreadView.tsx +525 -0
- package/src/components/Toast.stories.tsx +19 -0
- package/src/components/Toast.tsx +52 -0
- package/src/components/Tooltip.stories.tsx +26 -0
- package/src/components/Tooltip.tsx +72 -0
- package/src/components/TreePane.stories.tsx +106 -0
- package/src/components/TreePane.tsx +157 -0
- package/src/components/WalkWizard.stories.tsx +100 -0
- package/src/components/WalkWizard.tsx +150 -0
- package/src/components/WelcomePlayground.stories.tsx +12 -0
- package/src/components/WelcomePlayground.test.tsx +49 -0
- package/src/components/WelcomePlayground.tsx +139 -0
- package/src/components/WorkspacePanels.stories.tsx +36 -0
- package/src/components/WorkspacePanels.tsx +116 -0
- package/src/components/__snapshots__/stories.test.tsx.snap +2264 -0
- package/src/components/diff-content-view-layout.test.ts +198 -0
- package/src/components/diff-content-view-layout.ts +84 -0
- package/src/components/editor-grid.test.ts +86 -0
- package/src/components/editor-grid.ts +138 -0
- package/src/components/file-tree.test.ts +60 -0
- package/src/components/file-tree.ts +112 -0
- package/src/components/menu-control.stories.tsx +35 -0
- package/src/components/menu-control.tsx +43 -0
- package/src/components/pages/Workspace.stories.tsx +181 -0
- package/src/components/primitives/Button.stories.tsx +32 -0
- package/src/components/primitives/Button.tsx +59 -0
- package/src/components/primitives/Card.stories.tsx +25 -0
- package/src/components/primitives/Card.tsx +63 -0
- package/src/components/primitives/Dialog.stories.tsx +24 -0
- package/src/components/primitives/Dialog.test.tsx +37 -0
- package/src/components/primitives/Dialog.tsx +71 -0
- package/src/components/primitives/DialogActions.stories.tsx +20 -0
- package/src/components/primitives/DialogActions.tsx +39 -0
- package/src/components/primitives/IconButton.stories.tsx +36 -0
- package/src/components/primitives/IconButton.tsx +62 -0
- package/src/components/primitives/StatusBar.stories.tsx +11 -0
- package/src/components/primitives/StatusBar.tsx +23 -0
- package/src/components/primitives/Switch.stories.tsx +17 -0
- package/src/components/primitives/Switch.tsx +32 -0
- package/src/components/primitives/Tabs.stories.tsx +29 -0
- package/src/components/primitives/Tabs.tsx +102 -0
- package/src/components/primitives/Toolbar.stories.tsx +17 -0
- package/src/components/primitives/Toolbar.tsx +14 -0
- package/src/components/primitives/Tree.stories.tsx +124 -0
- package/src/components/primitives/Tree.tsx +100 -0
- package/src/components/primitives/frame.test.ts +12 -0
- package/src/components/primitives/frame.ts +17 -0
- package/src/components/primitives/icons.ts +61 -0
- package/src/components/primitives/tree-model.test.ts +99 -0
- package/src/components/primitives/tree-model.ts +137 -0
- package/src/components/quick-actions-editor.stories.tsx +58 -0
- package/src/components/quick-actions-editor.test.tsx +117 -0
- package/src/components/quick-actions-editor.tsx +226 -0
- package/src/components/share-dialog-store.ts +58 -0
- package/src/components/stories-app.tsx +193 -0
- package/src/components/stories.test.tsx +74 -0
- package/src/components/story-fixtures.ts +102 -0
- package/src/components/story-tree.test.ts +108 -0
- package/src/components/story.ts +159 -0
- package/src/components/syntax-highlight.ts +133 -0
- package/src/components/terminal-pane.test.tsx +40 -0
- package/src/components/terminal-pane.ts +199 -0
- package/src/components/theme-context.stories.tsx +46 -0
- package/src/components/theme-context.tsx +37 -0
- package/src/components/thread-tree.test.ts +134 -0
- package/src/components/thread-tree.ts +109 -0
- package/src/components/truncate-text.ts +7 -0
- package/src/components/truncate-title.test.ts +31 -0
- package/src/components/truncate-title.ts +15 -0
- package/src/config-identity.test.ts +78 -0
- package/src/config.test.ts +579 -34
- package/src/config.ts +533 -57
- package/src/diff-fold.test.ts +78 -0
- package/src/diff-fold.ts +126 -0
- package/src/diff-hunk-curate.test.ts +315 -0
- package/src/diff-hunk-curate.ts +153 -0
- package/src/diff-intraline.test.ts +238 -0
- package/src/diff-intraline.ts +236 -0
- package/src/diff-syntax.test.ts +112 -0
- package/src/diff-syntax.ts +179 -0
- package/src/discussions.ts +79 -0
- package/src/editor.test.ts +149 -0
- package/src/editor.ts +139 -9
- package/src/ghostty-terminal.test.ts +85 -0
- package/src/ghostty-terminal.ts +199 -0
- package/src/github-identity.test.ts +58 -0
- package/src/github-identity.ts +41 -0
- package/src/herdr.test.ts +9 -34
- package/src/herdr.ts +25 -21
- package/src/index.ts +28 -0
- package/src/integrations.test.ts +41 -0
- package/src/integrations.ts +32 -0
- package/src/intent-dispatch.test.ts +724 -0
- package/src/intent-dispatch.ts +690 -0
- package/src/key-bindings.test.ts +156 -0
- package/src/key-bindings.ts +459 -0
- package/src/keymap.test.ts +456 -115
- package/src/keymap.ts +315 -81
- package/src/kitty-image.test.ts +66 -0
- package/src/kitty-image.ts +138 -0
- package/src/launch-layout.test.ts +67 -0
- package/src/launch-layout.ts +47 -0
- package/src/mark-runs.ts +121 -0
- package/src/markdown-editor-syntax-style.ts +50 -0
- package/src/markdown-grid.test.ts +101 -0
- package/src/markdown-grid.ts +203 -0
- package/src/markdown-highlight.test.ts +61 -0
- package/src/markdown-highlight.ts +122 -0
- package/src/pasted-image.test.ts +67 -0
- package/src/pasted-image.ts +60 -0
- package/src/perf/otlp-trace.test.ts +116 -0
- package/src/perf/otlp-trace.ts +130 -0
- package/src/perf/perf-report.ts +17 -0
- package/src/perf/perf-timings.test.ts +18 -0
- package/src/perf/perf-timings.ts +38 -0
- package/src/prototype-browser.test.ts +81 -0
- package/src/prototype-browser.ts +329 -0
- package/src/prototype-pixels.tsx +35 -0
- package/src/pty.test.ts +81 -0
- package/src/pty.ts +245 -0
- package/src/ready-signal.test.ts +85 -0
- package/src/ready-signal.ts +52 -0
- package/src/run.ts +85 -12
- package/src/serve.test.ts +24 -12
- package/src/serve.ts +52 -10
- package/src/share.ts +237 -0
- package/src/skills.test.ts +74 -0
- package/src/skills.ts +75 -0
- package/src/slash-palette.test.ts +103 -0
- package/src/slash-palette.ts +129 -0
- package/src/split-diff.test.ts +110 -0
- package/src/split-diff.ts +149 -0
- package/src/test-support.test.ts +264 -0
- package/src/test-support.ts +369 -0
- package/src/theme-presets.test.ts +51 -0
- package/src/theme-presets.ts +219 -0
- package/src/theme.ts +88 -19
- package/src/thread-chords.test.ts +79 -0
- package/src/thread-chords.ts +163 -0
- package/src/thread-code-syntax.ts +45 -0
- package/src/thread-controller.curate.test.ts +476 -0
- package/src/thread-controller.derivation.test.ts +62 -0
- package/src/thread-controller.live-diff.test.ts +322 -0
- package/src/thread-controller.optimistic.test.ts +69 -0
- package/src/thread-controller.share.test.ts +561 -0
- package/src/thread-controller.switch-cache.test.ts +176 -0
- package/src/thread-controller.tree.test.ts +261 -0
- package/src/thread-controller.ts +2050 -0
- package/src/thread-selection.test.ts +210 -0
- package/src/thread-selection.ts +243 -0
- package/src/tree-view.test.ts +128 -0
- package/src/tree-view.ts +153 -0
- package/src/use-annotation-surface.tsx +975 -0
- package/src/use-changes-workbench.ts +190 -0
- package/src/use-frame-measure.ts +41 -0
- package/src/use-remember-layout.ts +31 -0
- package/src/use-repo-changes.ts +87 -0
- package/src/use-settings-dialog.tsx +364 -0
- package/src/use-terminal-virtualizer.ts +259 -0
- package/src/use-thread-body-editing.tsx +58 -0
- package/src/version.ts +5 -0
- package/src/view-diff.test.ts +279 -9
- package/src/view-diff.ts +460 -24
- package/src/view-plan.regression.test.ts +60 -0
- package/src/view-plan.test.ts +545 -0
- package/src/view-plan.ts +1019 -0
- package/src/visual/contrast.test.ts +35 -0
- package/src/visual/contrast.ts +33 -0
- package/src/walk.test.ts +121 -0
- package/src/walk.ts +74 -0
- package/src/workbench-snapshot.test.ts +99 -0
- package/src/workbench-snapshot.ts +59 -0
- package/src/session-controller.ts +0 -398
- package/src/syntax.test.ts +0 -41
- package/src/syntax.ts +0 -88
- package/src/view.test.ts +0 -157
- package/src/view.ts +0 -364
package/src/config.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Layered TOML config
|
|
2
|
+
* Layered TOML config: built-in defaults → user config → trusted repo
|
|
3
3
|
* config → env. Sections: [keys] action = "combo" (every action rebindable),
|
|
4
|
-
* [theme] per-token overrides, [
|
|
4
|
+
* [theme] per-token overrides, [ui] auto_close + editor + theme (a named
|
|
5
|
+
* preset) + pins, [integrations.obsidian] notes-vault export.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
8
|
import { existsSync, readFileSync } from "node:fs";
|
|
8
9
|
import { homedir } from "node:os";
|
|
9
10
|
import { join } from "node:path";
|
|
10
11
|
import { OBSIDIAN_DEFAULTS, type ObsidianConfig } from "@cueloop/integration-obsidian";
|
|
12
|
+
import { MESSAGE_OUTCOMES, type MessageOutcome } from "@cueloop/schema";
|
|
11
13
|
import { writeFileSync, mkdirSync } from "node:fs";
|
|
12
14
|
import { dirname } from "node:path";
|
|
15
|
+
import * as v from "valibot";
|
|
13
16
|
import { DARK, type Theme } from "./theme";
|
|
17
|
+
import { DEFAULT_THEME_NAME, isThemeName, themeForName, type ThemeName } from "./theme-presets";
|
|
18
|
+
import type { LaunchLayout } from "./launch-layout";
|
|
14
19
|
|
|
15
20
|
export interface KeymapConfig {
|
|
16
21
|
[action: string]: string | string[];
|
|
@@ -23,127 +28,598 @@ export interface IntegrationsConfig {
|
|
|
23
28
|
/** Post-submit behavior: "off" prompts, 0 closes instantly, N counts down. */
|
|
24
29
|
export type AutoClose = "off" | number;
|
|
25
30
|
|
|
31
|
+
/** How the Changes diff renders when wide: old|new side by side, or one stacked column. A narrow
|
|
32
|
+
* (unzoomed) pane has no room for two columns, so it is always stacked regardless of this choice. */
|
|
33
|
+
export type DiffViewMode = "split" | "stacked";
|
|
34
|
+
|
|
35
|
+
export type ReviewWorkspaceMode = "worktree" | "current";
|
|
36
|
+
|
|
37
|
+
/** Agent review defaults shared by the slash workflow and Settings. */
|
|
38
|
+
export interface ReviewConfig {
|
|
39
|
+
skill: string;
|
|
40
|
+
workspace: ReviewWorkspaceMode;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** One marker-popover quick action: a preset comment body, plus optional extra lines. */
|
|
44
|
+
export interface QuickAction {
|
|
45
|
+
prompt: string;
|
|
46
|
+
metadata?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The built-in quick-actions for the marker popover when no `[[actions]]` are configured. */
|
|
50
|
+
export const DEFAULT_QUICK_ACTIONS: QuickAction[] = [
|
|
51
|
+
{
|
|
52
|
+
prompt: "Zoom out, research in depth",
|
|
53
|
+
metadata: "Research the broader problem, prior art, and alternatives before changing anything.",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
prompt: "Restate simplified",
|
|
57
|
+
metadata: "Restate this as the simplest thing that works and cut the incidental complexity.",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
prompt: "Out of scope",
|
|
61
|
+
metadata:
|
|
62
|
+
"This is out of scope for the task, so capture it as a follow-up instead of doing it now.",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
prompt: "Let's chat about this",
|
|
66
|
+
metadata:
|
|
67
|
+
"Do not implement yet, and surface the open questions and trade-offs so we decide together.",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
prompt: "Prototype this",
|
|
71
|
+
metadata: "Build a throwaway prototype to answer the question, skipping tests and polish.",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
prompt: "Ensure 0 regressions",
|
|
75
|
+
metadata:
|
|
76
|
+
"Characterize the current behavior with tests first, then keep them green through the change.",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
prompt: "Consider existing repo patterns",
|
|
80
|
+
metadata:
|
|
81
|
+
"Follow the nearest existing pattern in this codebase rather than introducing a new one.",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
prompt: "LGTM",
|
|
85
|
+
metadata: "This looks good to me.",
|
|
86
|
+
},
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
/** The comment body a quick action expands to: the prompt, then its system prompt when set. */
|
|
90
|
+
export function quickActionBody(action: QuickAction): string {
|
|
91
|
+
return action.metadata ? `${action.prompt}\n\n${action.metadata}` : action.prompt;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Resolve a quick action by 1-based index or case-insensitive prompt; undefined when no match. */
|
|
95
|
+
export function resolveQuickAction(
|
|
96
|
+
actions: QuickAction[],
|
|
97
|
+
actionRef: string,
|
|
98
|
+
): QuickAction | undefined {
|
|
99
|
+
const index = Number(actionRef);
|
|
100
|
+
|
|
101
|
+
if (Number.isInteger(index) && index >= 1 && index <= actions.length) return actions[index - 1];
|
|
102
|
+
const wanted = actionRef.trim().toLowerCase();
|
|
103
|
+
|
|
104
|
+
return actions.find((action) => action.prompt.toLowerCase() === wanted);
|
|
105
|
+
}
|
|
106
|
+
|
|
26
107
|
export interface CueloopConfig {
|
|
27
108
|
keys: Record<string, string[]>;
|
|
28
109
|
theme: Theme;
|
|
29
|
-
|
|
110
|
+
/** The `[theme]` per-token overrides alone, so a live theme switch can re-compose them onto a new preset. */
|
|
111
|
+
themeOverrides: Partial<Theme>;
|
|
112
|
+
ui: {
|
|
113
|
+
autoClose: AutoClose;
|
|
114
|
+
editor?: string;
|
|
115
|
+
/** The selected theme preset name; its tokens are the base for `theme`, before any `[theme]` overrides. */
|
|
116
|
+
theme: ThemeName;
|
|
117
|
+
/** How the Changes diff renders when wide: old|new side by side or one stacked column. */
|
|
118
|
+
diffView: DiffViewMode;
|
|
119
|
+
defaultMessage: MessageOutcome;
|
|
120
|
+
/** Session ids the user has pinned to the top of the sidebar; client-local view state. */
|
|
121
|
+
pins: string[];
|
|
122
|
+
/** The last pane layout a bare launch restores; unset until the user changes one. */
|
|
123
|
+
layout?: LaunchLayout;
|
|
124
|
+
};
|
|
125
|
+
/** Planner-local author renames: identity id → display name ([authors] table). */
|
|
126
|
+
authors: Record<string, string>;
|
|
127
|
+
/** The local reviewer's own display name, and whether it was typed or synced from GitHub ([identity] table). */
|
|
128
|
+
identity: IdentityConfig;
|
|
129
|
+
/** Marker-popover quick actions ([[actions]] tables); the 5 defaults when unset. */
|
|
130
|
+
actions: QuickAction[];
|
|
131
|
+
/** Directory of user-level skills surfaced in the "/" palette ([skills] path); ~/.agents/skills default. */
|
|
132
|
+
skillsPath: string;
|
|
133
|
+
review: ReviewConfig;
|
|
30
134
|
integrations: IntegrationsConfig;
|
|
135
|
+
/** Opt-in experimental features ([experimental] table); all default off. */
|
|
136
|
+
experimental: ExperimentalConfig;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface ExperimentalConfig {
|
|
140
|
+
/** Render a prototype as a pixel mockup (kitty graphics) instead of the default markdown design doc. */
|
|
141
|
+
prototypePixels: boolean;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** Where a display name came from: typed by the user, or verified from a GitHub login. */
|
|
145
|
+
export type IdentityProvider = "typed" | "github";
|
|
146
|
+
|
|
147
|
+
export interface IdentityConfig {
|
|
148
|
+
/** The reviewer's own display name; absent until they set or sync one. */
|
|
149
|
+
name?: string;
|
|
150
|
+
provider: IdentityProvider;
|
|
31
151
|
}
|
|
32
152
|
|
|
33
153
|
/** Every action in the grammar, with its default binding(s). */
|
|
34
|
-
export const DEFAULT_KEYS:
|
|
154
|
+
export const DEFAULT_KEYS: CueloopConfig["keys"] = {
|
|
35
155
|
down: ["j", "down"],
|
|
36
156
|
up: ["k", "up"],
|
|
37
157
|
top: ["g"],
|
|
38
158
|
bottom: ["G"],
|
|
39
159
|
span: ["v"],
|
|
40
160
|
comment: ["c"],
|
|
41
|
-
suggest: ["s"],
|
|
42
161
|
cut: ["x"],
|
|
162
|
+
reject_hunk: ["X"],
|
|
163
|
+
restore_curation: ["u"],
|
|
164
|
+
collapse_file: ["right"],
|
|
165
|
+
expand_file: ["left"],
|
|
166
|
+
split_diff: ["s"],
|
|
43
167
|
edit: ["e"],
|
|
44
168
|
next_annotation: ["n"],
|
|
45
169
|
prev_annotation: ["p"],
|
|
46
170
|
delete_annotation: ["backspace"],
|
|
171
|
+
rename: ["r"],
|
|
47
172
|
submit: ["return", "enter"],
|
|
173
|
+
share: ["S"],
|
|
48
174
|
quit: ["q"],
|
|
175
|
+
walk: ["w"],
|
|
49
176
|
};
|
|
50
177
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
178
|
+
const SkillsSectionSchema = v.object({ path: v.optional(v.string()) });
|
|
179
|
+
|
|
180
|
+
function skillsPathFrom(
|
|
181
|
+
raw: v.InferOutput<typeof SkillsSectionSchema> | undefined,
|
|
182
|
+
fallback: string,
|
|
183
|
+
): string {
|
|
184
|
+
return raw?.path?.trim() ? raw.path.trim() : fallback;
|
|
54
185
|
}
|
|
55
186
|
|
|
56
|
-
|
|
187
|
+
const ConfigDocumentSchema = v.object({
|
|
188
|
+
actions: v.optional(v.array(v.unknown())),
|
|
189
|
+
authors: v.optional(v.unknown()),
|
|
190
|
+
identity: v.optional(v.unknown()),
|
|
191
|
+
integrations: v.optional(v.unknown()),
|
|
192
|
+
keys: v.optional(v.unknown()),
|
|
193
|
+
theme: v.optional(v.unknown()),
|
|
194
|
+
ui: v.optional(v.unknown()),
|
|
195
|
+
experimental: v.optional(v.unknown()),
|
|
196
|
+
skills: v.fallback(v.optional(SkillsSectionSchema), undefined),
|
|
197
|
+
review: v.optional(v.unknown()),
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const IdentitySchema = v.object({
|
|
201
|
+
name: v.fallback(v.optional(v.string()), undefined),
|
|
202
|
+
provider: v.fallback(v.optional(v.picklist(["typed", "github"])), undefined),
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
const QuickActionSchema = v.object({
|
|
206
|
+
prompt: v.pipe(
|
|
207
|
+
v.string(),
|
|
208
|
+
v.check((prompt) => Boolean(prompt.trim())),
|
|
209
|
+
),
|
|
210
|
+
metadata: v.optional(v.string()),
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const AuthorsSchema = v.record(v.string(), v.unknown());
|
|
214
|
+
const KeysSchema = v.record(v.string(), v.unknown());
|
|
215
|
+
const KeyComboSchema = v.union([v.string(), v.array(v.string())]);
|
|
216
|
+
// Every field falls back to undefined on its own, so one bad value in a
|
|
217
|
+
// section never discards the section's other settings.
|
|
218
|
+
const UiSchema = v.object({
|
|
219
|
+
auto_close: v.fallback(
|
|
220
|
+
v.optional(v.union([v.literal("off"), v.pipe(v.number(), v.minValue(0))])),
|
|
221
|
+
undefined,
|
|
222
|
+
),
|
|
223
|
+
editor: v.fallback(v.optional(v.string()), undefined),
|
|
224
|
+
theme: v.fallback(v.optional(v.string()), undefined),
|
|
225
|
+
diff_view: v.fallback(v.optional(v.picklist(["split", "stacked", "unified"])), undefined),
|
|
226
|
+
default_message: v.fallback(v.optional(v.picklist(MESSAGE_OUTCOMES)), undefined),
|
|
227
|
+
pins: v.fallback(v.optional(v.array(v.string())), undefined),
|
|
228
|
+
layout: v.fallback(
|
|
229
|
+
v.optional(
|
|
230
|
+
v.object({
|
|
231
|
+
threads: v.fallback(v.optional(v.boolean()), undefined),
|
|
232
|
+
right_sidebar: v.fallback(v.optional(v.picklist(["changes", "project", "off"])), undefined),
|
|
233
|
+
zoom_changes: v.fallback(v.optional(v.boolean()), undefined),
|
|
234
|
+
}),
|
|
235
|
+
),
|
|
236
|
+
undefined,
|
|
237
|
+
),
|
|
238
|
+
});
|
|
239
|
+
const ObsidianSchema = v.object({
|
|
240
|
+
vault: v.fallback(v.optional(v.string()), undefined),
|
|
241
|
+
folder: v.fallback(v.optional(v.string()), undefined),
|
|
242
|
+
filenameFormat: v.fallback(v.optional(v.string()), undefined),
|
|
243
|
+
separator: v.fallback(v.optional(v.picklist(["space", "dash", "underscore"])), undefined),
|
|
244
|
+
exportOn: v.fallback(v.optional(v.picklist(["approved", "message", "manual"])), undefined),
|
|
245
|
+
});
|
|
246
|
+
const IntegrationsSchema = v.object({ obsidian: v.optional(ObsidianSchema) });
|
|
247
|
+
const ExperimentalSchema = v.object({
|
|
248
|
+
prototype_pixels: v.fallback(v.optional(v.boolean()), undefined),
|
|
249
|
+
});
|
|
250
|
+
const ReviewSchema = v.object({
|
|
251
|
+
skill: v.fallback(v.optional(v.string()), undefined),
|
|
252
|
+
workspace: v.fallback(v.optional(v.picklist(["worktree", "current"])), undefined),
|
|
253
|
+
});
|
|
254
|
+
const ThemeOverridesSchema = v.record(v.string(), v.unknown());
|
|
255
|
+
|
|
256
|
+
function isThemeToken(token: string): token is keyof Theme {
|
|
257
|
+
return token in DARK;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function parseToml(text: string) {
|
|
261
|
+
return v.parse(ConfigDocumentSchema, Bun.TOML.parse(text));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function parseActions(entries: readonly unknown[] | undefined): QuickAction[] | undefined {
|
|
265
|
+
if (!entries) return undefined;
|
|
266
|
+
const actions: QuickAction[] = [];
|
|
267
|
+
|
|
268
|
+
for (const entry of entries) {
|
|
269
|
+
const result = v.safeParse(QuickActionSchema, entry);
|
|
270
|
+
|
|
271
|
+
if (!result.success) continue;
|
|
272
|
+
const { prompt, metadata } = result.output;
|
|
273
|
+
|
|
274
|
+
actions.push(metadata?.trim() ? { prompt, metadata } : { prompt });
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return actions.length ? actions : undefined;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function mergeObsidian(
|
|
281
|
+
target: ObsidianConfig,
|
|
282
|
+
obsidian: v.InferOutput<typeof ObsidianSchema>,
|
|
283
|
+
): void {
|
|
284
|
+
if (obsidian.vault !== undefined) target.vault = obsidian.vault;
|
|
285
|
+
if (obsidian.folder !== undefined) target.folder = obsidian.folder;
|
|
286
|
+
if (obsidian.filenameFormat !== undefined) target.filenameFormat = obsidian.filenameFormat;
|
|
287
|
+
if (obsidian.separator !== undefined) target.separator = obsidian.separator;
|
|
288
|
+
if (obsidian.exportOn !== undefined) target.exportOn = obsidian.exportOn;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Fold a parsed `[ui]` table onto the accumulated ui config, field by present field. */
|
|
292
|
+
function applyUi(ui: CueloopConfig["ui"], parsed: v.InferOutput<typeof UiSchema>): void {
|
|
293
|
+
if (parsed.auto_close !== undefined) ui.autoClose = parsed.auto_close;
|
|
294
|
+
if (parsed.editor?.trim()) ui.editor = parsed.editor.trim();
|
|
295
|
+
// "unified" is the pre-rename spelling of "stacked"; keep loading it so an upgrade never flips the layout
|
|
296
|
+
if (parsed.diff_view !== undefined)
|
|
297
|
+
ui.diffView = parsed.diff_view === "unified" ? "stacked" : parsed.diff_view;
|
|
298
|
+
if (parsed.default_message !== undefined) ui.defaultMessage = parsed.default_message;
|
|
299
|
+
if (parsed.pins !== undefined) ui.pins = parsed.pins;
|
|
300
|
+
if (parsed.layout !== undefined) {
|
|
301
|
+
ui.layout = {
|
|
302
|
+
threads: parsed.layout.threads ?? true,
|
|
303
|
+
rightSidebar: parsed.layout.right_sidebar ?? "changes",
|
|
304
|
+
zoomChanges: parsed.layout.zoom_changes ?? false,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function applyReview(review: ReviewConfig, parsed: v.InferOutput<typeof ReviewSchema>): void {
|
|
310
|
+
if (parsed.skill?.trim()) review.skill = parsed.skill.trim();
|
|
311
|
+
if (parsed.workspace !== undefined) review.workspace = parsed.workspace;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function layer(
|
|
315
|
+
base: CueloopConfig,
|
|
316
|
+
raw: v.InferOutput<typeof ConfigDocumentSchema>,
|
|
317
|
+
allowIdentity: boolean,
|
|
318
|
+
): CueloopConfig {
|
|
57
319
|
const out: CueloopConfig = {
|
|
58
320
|
keys: { ...base.keys },
|
|
59
321
|
theme: { ...base.theme },
|
|
322
|
+
themeOverrides: { ...base.themeOverrides },
|
|
60
323
|
ui: { ...base.ui },
|
|
324
|
+
authors: { ...base.authors },
|
|
325
|
+
identity: { ...base.identity },
|
|
326
|
+
actions: [...base.actions],
|
|
327
|
+
skillsPath: base.skillsPath,
|
|
328
|
+
review: { ...base.review },
|
|
61
329
|
integrations: { obsidian: { ...base.integrations.obsidian } },
|
|
330
|
+
experimental: { ...base.experimental },
|
|
62
331
|
};
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
332
|
+
const actions = parseActions(raw.actions);
|
|
333
|
+
const authors = v.safeParse(AuthorsSchema, raw.authors);
|
|
334
|
+
const identity = v.safeParse(IdentitySchema, raw.identity);
|
|
335
|
+
const keys = v.safeParse(KeysSchema, raw.keys);
|
|
336
|
+
const ui = v.safeParse(UiSchema, raw.ui);
|
|
337
|
+
const integrations = v.safeParse(IntegrationsSchema, raw.integrations);
|
|
338
|
+
const experimental = v.safeParse(ExperimentalSchema, raw.experimental);
|
|
339
|
+
const review = v.safeParse(ReviewSchema, raw.review);
|
|
340
|
+
|
|
341
|
+
if (actions) out.actions = actions;
|
|
342
|
+
out.skillsPath = skillsPathFrom(raw.skills, base.skillsPath);
|
|
343
|
+
if (authors.success) {
|
|
344
|
+
for (const [id, value] of Object.entries(authors.output)) {
|
|
345
|
+
const name = v.safeParse(v.string(), value);
|
|
346
|
+
|
|
347
|
+
if (name.success) out.authors[id] = name.output;
|
|
67
348
|
}
|
|
68
349
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (theme) {
|
|
76
|
-
for (const [token, value] of Object.entries(theme)) {
|
|
77
|
-
if (token in out.theme && typeof value === "string") {
|
|
78
|
-
(out.theme as unknown as Record<string, string>)[token] = value;
|
|
79
|
-
}
|
|
350
|
+
if (keys.success) {
|
|
351
|
+
for (const [action, value] of Object.entries(keys.output)) {
|
|
352
|
+
const combo = v.safeParse(KeyComboSchema, value);
|
|
353
|
+
|
|
354
|
+
if (combo.success)
|
|
355
|
+
out.keys[action] = Array.isArray(combo.output) ? combo.output : [combo.output];
|
|
80
356
|
}
|
|
81
357
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (sep === "space" || sep === "dash" || sep === "underscore") o.separator = sep;
|
|
91
|
-
const on = obsidian["exportOn"];
|
|
92
|
-
if (on === "approve" || on === "resolve" || on === "manual") o.exportOn = on;
|
|
358
|
+
// The reviewer identity is a personal credential; a repo must never forge a verified name.
|
|
359
|
+
if (allowIdentity && identity.success) {
|
|
360
|
+
if (identity.output.name !== undefined) out.identity.name = identity.output.name;
|
|
361
|
+
if (identity.output.provider !== undefined) out.identity.provider = identity.output.provider;
|
|
362
|
+
}
|
|
363
|
+
if (ui.success) applyUi(out.ui, ui.output);
|
|
364
|
+
if (integrations.success && integrations.output.obsidian) {
|
|
365
|
+
mergeObsidian(out.integrations.obsidian, integrations.output.obsidian);
|
|
93
366
|
}
|
|
367
|
+
if (experimental.success && experimental.output.prototype_pixels !== undefined) {
|
|
368
|
+
out.experimental.prototypePixels = experimental.output.prototype_pixels;
|
|
369
|
+
}
|
|
370
|
+
if (review.success) applyReview(out.review, review.output);
|
|
371
|
+
|
|
94
372
|
return out;
|
|
95
373
|
}
|
|
96
374
|
|
|
97
|
-
export function loadConfig(
|
|
375
|
+
export function loadConfig(
|
|
376
|
+
options: { repoRoot?: string; userConfigPath?: string } = {},
|
|
377
|
+
): CueloopConfig {
|
|
98
378
|
let config: CueloopConfig = {
|
|
99
379
|
keys: { ...DEFAULT_KEYS },
|
|
100
380
|
theme: { ...DARK },
|
|
101
|
-
|
|
381
|
+
themeOverrides: {},
|
|
382
|
+
ui: {
|
|
383
|
+
autoClose: "off",
|
|
384
|
+
theme: DEFAULT_THEME_NAME,
|
|
385
|
+
diffView: "split",
|
|
386
|
+
defaultMessage: "approved",
|
|
387
|
+
pins: [],
|
|
388
|
+
},
|
|
389
|
+
authors: {},
|
|
390
|
+
identity: { provider: "typed" },
|
|
391
|
+
actions: [...DEFAULT_QUICK_ACTIONS],
|
|
392
|
+
skillsPath: join(homedir(), ".agents", "skills"),
|
|
393
|
+
review: { skill: "code-review", workspace: "worktree" },
|
|
102
394
|
integrations: { obsidian: { ...OBSIDIAN_DEFAULTS } },
|
|
395
|
+
experimental: { prototypePixels: false },
|
|
103
396
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
397
|
+
// Theme name and per-token overrides are separate concerns, composed once
|
|
398
|
+
// after all layers: the last file to set [ui] theme wins, and every [theme]
|
|
399
|
+
// override from every file lands on top - so a later preset never discards an
|
|
400
|
+
// earlier file's token overrides.
|
|
401
|
+
let themeName = DEFAULT_THEME_NAME;
|
|
402
|
+
const themeOverrides: Partial<Record<keyof Theme, string>> = {};
|
|
403
|
+
const userPath = userConfigPathFrom(options.userConfigPath);
|
|
404
|
+
|
|
405
|
+
for (const path of [
|
|
406
|
+
userPath,
|
|
407
|
+
options.repoRoot ? join(options.repoRoot, ".cueloop", "config.toml") : undefined,
|
|
408
|
+
]) {
|
|
109
409
|
if (!path || !existsSync(path)) continue;
|
|
110
410
|
try {
|
|
111
|
-
|
|
411
|
+
const raw = parseToml(readFileSync(path, "utf8"));
|
|
412
|
+
|
|
413
|
+
config = layer(config, raw, path === userPath);
|
|
414
|
+
const ui = v.safeParse(UiSchema, raw.ui);
|
|
415
|
+
const rawTheme = ui.success ? ui.output.theme : undefined;
|
|
416
|
+
const parsedThemeOverrides = v.safeParse(ThemeOverridesSchema, raw.theme);
|
|
417
|
+
|
|
418
|
+
if (rawTheme && isThemeName(rawTheme)) themeName = rawTheme;
|
|
419
|
+
if (parsedThemeOverrides.success) {
|
|
420
|
+
for (const [token, value] of Object.entries(parsedThemeOverrides.output)) {
|
|
421
|
+
const override = v.safeParse(v.string(), value);
|
|
422
|
+
|
|
423
|
+
if (override.success && isThemeToken(token)) themeOverrides[token] = override.output;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
112
426
|
} catch {
|
|
113
427
|
// a broken config never blocks a review; defaults win
|
|
114
428
|
}
|
|
115
429
|
}
|
|
430
|
+
config.ui.theme = themeName;
|
|
431
|
+
config.themeOverrides = themeOverrides;
|
|
432
|
+
config.theme = { ...themeForName(themeName), ...themeOverrides };
|
|
433
|
+
|
|
116
434
|
return config;
|
|
117
435
|
}
|
|
118
436
|
|
|
119
437
|
/** Reverse lookup: key name (+shift) → action, per the loaded keymap. */
|
|
120
|
-
export function actionFor(
|
|
438
|
+
export function actionFor(
|
|
439
|
+
keys: Record<string, string[]>,
|
|
440
|
+
name: string,
|
|
441
|
+
shift: boolean,
|
|
442
|
+
): string | undefined {
|
|
121
443
|
const wanted = shift && name.length === 1 ? name.toUpperCase() : name;
|
|
444
|
+
|
|
122
445
|
for (const [action, combos] of Object.entries(keys)) {
|
|
123
446
|
if (combos.includes(wanted)) return action;
|
|
124
447
|
}
|
|
448
|
+
|
|
125
449
|
return undefined;
|
|
126
450
|
}
|
|
127
451
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
* surgery on the one key we own: replace an existing `auto_close`, or append
|
|
131
|
-
* an `[ui]` section - a full TOML writer is not worth its weight here.
|
|
132
|
-
*/
|
|
133
|
-
export function persistAutoClose(value: AutoClose, userConfigPath?: string): void {
|
|
134
|
-
const path =
|
|
452
|
+
function userConfigPathFrom(userConfigPath?: string): string {
|
|
453
|
+
return (
|
|
135
454
|
userConfigPath ??
|
|
136
455
|
process.env.CUELOOP_CONFIG ??
|
|
137
|
-
join(process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "cueloop", "config.toml")
|
|
138
|
-
|
|
456
|
+
join(process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "cueloop", "config.toml")
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Persist one `[ui]` key into the user config file. Line-level TOML surgery on
|
|
462
|
+
* the keys we own: replace the existing assignment, or drop it under an `[ui]`
|
|
463
|
+
* section (appending the section when absent) - a full TOML writer is not worth
|
|
464
|
+
* its weight here.
|
|
465
|
+
*/
|
|
466
|
+
function persistUiSetting(key: string, rendered: string, userConfigPath?: string): void {
|
|
467
|
+
const path = userConfigPathFrom(userConfigPath);
|
|
139
468
|
let text = "";
|
|
469
|
+
|
|
140
470
|
if (existsSync(path)) text = readFileSync(path, "utf8");
|
|
141
|
-
|
|
142
|
-
|
|
471
|
+
const assignment = new RegExp(`^(\\s*)${key}\\s*=.*$`, "m");
|
|
472
|
+
|
|
473
|
+
if (assignment.test(text)) {
|
|
474
|
+
text = text.replace(assignment, `$1${key} = ${rendered}`);
|
|
143
475
|
} else if (/^\[ui\]/m.test(text)) {
|
|
144
|
-
text = text.replace(/^\[ui\]\s*$/m, `[ui]\
|
|
476
|
+
text = text.replace(/^\[ui\]\s*$/m, `[ui]\n${key} = ${rendered}`);
|
|
477
|
+
} else {
|
|
478
|
+
text = text.trimEnd() + (text.trim() ? "\n\n" : "") + `[ui]\n${key} = ${rendered}\n`;
|
|
479
|
+
}
|
|
480
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
481
|
+
writeFileSync(path, text);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
function persistTableSetting(
|
|
485
|
+
table: string,
|
|
486
|
+
key: string,
|
|
487
|
+
rendered: string,
|
|
488
|
+
userConfigPath?: string,
|
|
489
|
+
): void {
|
|
490
|
+
const path = userConfigPathFrom(userConfigPath);
|
|
491
|
+
let text = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
492
|
+
const escapedTable = escapeRegExp(table);
|
|
493
|
+
const block = new RegExp(
|
|
494
|
+
`(^\\[${escapedTable}\\][ \\t]*(?:#[^\\r\\n]*)?\\r?$)([\\s\\S]*?)(?=^\\[|(?![\\s\\S]))`,
|
|
495
|
+
"m",
|
|
496
|
+
);
|
|
497
|
+
const match = block.exec(text);
|
|
498
|
+
|
|
499
|
+
if (match) {
|
|
500
|
+
const assignment = new RegExp(`^(\\s*)${escapeRegExp(key)}\\s*=.*$`, "m");
|
|
501
|
+
const body = assignment.test(match[2]!)
|
|
502
|
+
? match[2]!.replace(assignment, `$1${key} = ${rendered}`)
|
|
503
|
+
: `\n${key} = ${rendered}${match[2]!}`;
|
|
504
|
+
|
|
505
|
+
text =
|
|
506
|
+
text.slice(0, match.index) + match[1]! + body + text.slice(match.index + match[0].length);
|
|
507
|
+
} else {
|
|
508
|
+
text = `${text.trimEnd()}${text.trim() ? "\n\n" : ""}[${table}]\n${key} = ${rendered}\n`;
|
|
509
|
+
}
|
|
510
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
511
|
+
writeFileSync(path, text);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/** A double-quoted TOML basic string with the quote-breaking characters escaped. */
|
|
515
|
+
function tomlString(value: string): string {
|
|
516
|
+
return `"${value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n")}"`;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Persist the whole quick-action set as `[[actions]]` tables, replacing any
|
|
521
|
+
* existing ones. The set is the user's entire vocabulary (not merged), so the
|
|
522
|
+
* old blocks are stripped and the new ones appended. An empty set clears them.
|
|
523
|
+
*/
|
|
524
|
+
export function persistActions(actions: QuickAction[], userConfigPath?: string): void {
|
|
525
|
+
const path = userConfigPathFrom(userConfigPath);
|
|
526
|
+
let text = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
527
|
+
|
|
528
|
+
// strip every existing [[actions]] block (header through its key lines)
|
|
529
|
+
text = text.replace(/^\[\[actions\]\][^[]*/gm, "").trimEnd();
|
|
530
|
+
const blocks = actions
|
|
531
|
+
.map((action) => {
|
|
532
|
+
const lines = [`[[actions]]`, `prompt = ${tomlString(action.prompt)}`];
|
|
533
|
+
|
|
534
|
+
if (action.metadata) lines.push(`metadata = ${tomlString(action.metadata)}`);
|
|
535
|
+
|
|
536
|
+
return lines.join("\n");
|
|
537
|
+
})
|
|
538
|
+
.join("\n\n");
|
|
539
|
+
|
|
540
|
+
text = blocks ? `${text ? `${text}\n\n` : ""}${blocks}\n` : `${text}\n`;
|
|
541
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
542
|
+
writeFileSync(path, text);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/** Persist the reviewer's own display name and its provider (`[identity]`) into the user config. */
|
|
546
|
+
export function persistIdentity(identity: IdentityConfig, userConfigPath?: string): void {
|
|
547
|
+
const path = userConfigPathFrom(userConfigPath);
|
|
548
|
+
let text = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
549
|
+
const nameLine = identity.name === undefined ? "" : `name = ${tomlString(identity.name)}\n`;
|
|
550
|
+
const block = `[identity]\n${nameLine}provider = ${tomlString(identity.provider)}\n`;
|
|
551
|
+
|
|
552
|
+
if (/^\[identity\]/m.test(text)) {
|
|
553
|
+
// Consume the header and its assignment lines only, so a bracket in a quoted name cannot truncate the block.
|
|
554
|
+
text = text.replace(/^\[identity\].*(?:\n(?![[\n]).*)*\n?/m, block);
|
|
555
|
+
} else {
|
|
556
|
+
text = text.trimEnd() + (text.trim() ? "\n\n" : "") + block;
|
|
557
|
+
}
|
|
558
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
559
|
+
writeFileSync(path, text);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/** Persist the auto-close choice (`[ui] auto_close`) into the user config. */
|
|
563
|
+
export function persistAutoClose(value: AutoClose, userConfigPath?: string): void {
|
|
564
|
+
persistUiSetting("auto_close", value === "off" ? '"off"' : String(value), userConfigPath);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/** Persist the selected theme preset (`[ui] theme`) into the user config. */
|
|
568
|
+
export function persistTheme(name: ThemeName, userConfigPath?: string): void {
|
|
569
|
+
persistUiSetting("theme", `"${name}"`, userConfigPath);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/** Persist the diff-view choice (`[ui] diff_view`) into the user config. */
|
|
573
|
+
export function persistDiffView(mode: DiffViewMode, userConfigPath?: string): void {
|
|
574
|
+
persistUiSetting("diff_view", `"${mode}"`, userConfigPath);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/** Persist the configured agent review skill (`[review] skill`). */
|
|
578
|
+
export function persistReviewSkill(skill: string, userConfigPath?: string): void {
|
|
579
|
+
persistTableSetting("review", "skill", tomlString(skill), userConfigPath);
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
/** Persist where agent review work runs (`[review] workspace`). */
|
|
583
|
+
export function persistReviewWorkspace(
|
|
584
|
+
workspace: ReviewWorkspaceMode,
|
|
585
|
+
userConfigPath?: string,
|
|
586
|
+
): void {
|
|
587
|
+
persistTableSetting("review", "workspace", tomlString(workspace), userConfigPath);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/** Persist the pinned-thread ids (`[ui] pins`) into the user config. */
|
|
591
|
+
export function persistPins(ids: readonly string[], userConfigPath?: string): void {
|
|
592
|
+
persistUiSetting("pins", `[${ids.map(tomlString).join(", ")}]`, userConfigPath);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/** Persist the last pane layout (`[ui] layout`) so a bare launch restores it. */
|
|
596
|
+
export function persistLayout(layout: LaunchLayout, userConfigPath?: string): void {
|
|
597
|
+
const table = `{ threads = ${layout.threads}, right_sidebar = "${layout.rightSidebar}", zoom_changes = ${layout.zoomChanges} }`;
|
|
598
|
+
|
|
599
|
+
persistUiSetting("layout", table, userConfigPath);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function escapeRegExp(text: string): string {
|
|
603
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* Persist an author rename into the `[authors]` table. The identity id (an SSH
|
|
608
|
+
* fingerprint) is not a bare TOML key, so it is written quoted.
|
|
609
|
+
*/
|
|
610
|
+
export function persistAuthorName(id: string, name: string, userConfigPath?: string): void {
|
|
611
|
+
const path = userConfigPathFrom(userConfigPath);
|
|
612
|
+
let text = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
613
|
+
const key = `"${id.replace(/"/g, '\\"')}"`;
|
|
614
|
+
const value = `"${name.replace(/"/g, '\\"')}"`;
|
|
615
|
+
const assignment = new RegExp(`^(\\s*)${escapeRegExp(key)}\\s*=.*$`, "m");
|
|
616
|
+
|
|
617
|
+
if (assignment.test(text)) {
|
|
618
|
+
text = text.replace(assignment, `$1${key} = ${value}`);
|
|
619
|
+
} else if (/^\[authors\]/m.test(text)) {
|
|
620
|
+
text = text.replace(/^\[authors\]\s*$/m, `[authors]\n${key} = ${value}`);
|
|
145
621
|
} else {
|
|
146
|
-
text = text.trimEnd() + (text.trim() ? "\n\n" : "") + `[
|
|
622
|
+
text = text.trimEnd() + (text.trim() ? "\n\n" : "") + `[authors]\n${key} = ${value}\n`;
|
|
147
623
|
}
|
|
148
624
|
mkdirSync(dirname(path), { recursive: true });
|
|
149
625
|
writeFileSync(path, text);
|