kovence-cli 0.0.0-stage → 1.0.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,223 @@
1
+ "use strict";
2
+
3
+ const { SETTINGS_SCHEMA, parseSettingValue } = require("../settings/schema");
4
+ const { stepSettingValue } = require("../settings/store");
5
+ const { displayWidth, clipToWidth, wrapPlain, padRight } = require("./text_width");
6
+
7
+ function formatSettingDisplayValue(meta, value) {
8
+ if (meta.type === "action") return "-> open";
9
+ if (meta.type === "boolean") return value ? "on" : "off";
10
+ if (value === null || value === undefined || value === "") return "(default)";
11
+ if (meta.type === "multilineString") {
12
+ const single = String(value).replace(/\s+/g, " ").trim();
13
+ return single.length > 36 ? `${single.slice(0, 33)}...` : single;
14
+ }
15
+ return String(value);
16
+ }
17
+
18
+ function getFilteredSettings(settings, searchQuery = "") {
19
+ const q = String(searchQuery || "")
20
+ .trim()
21
+ .toLowerCase();
22
+ return SETTINGS_SCHEMA.filter((meta) => {
23
+ if (!q) return true;
24
+ return (
25
+ meta.label.toLowerCase().includes(q) ||
26
+ meta.key.toLowerCase().includes(q) ||
27
+ meta.description.toLowerCase().includes(q)
28
+ );
29
+ }).map((meta) => ({
30
+ meta,
31
+ value: settings?.[meta.key],
32
+ displayValue: formatSettingDisplayValue(meta, settings?.[meta.key]),
33
+ }));
34
+ }
35
+
36
+ function getFilteredPermissions(rules, searchQuery = "") {
37
+ const q = String(searchQuery || "")
38
+ .trim()
39
+ .toLowerCase();
40
+ return (Array.isArray(rules) ? rules : [])
41
+ .map((rule, idx) => ({ ...rule, displayIndex: idx + 1 }))
42
+ .filter((rule) => {
43
+ if (!q) return true;
44
+ const hay = `${rule.origin} ${rule.tool} ${rule.scope} ${rule.pattern} ${rule.action}`.toLowerCase();
45
+ return hay.includes(q);
46
+ });
47
+ }
48
+
49
+ /**
50
+ * Render the full-screen Antigravity-style Settings panel.
51
+ */
52
+ function renderSettingsScreen({ cols, rows, settingsState, settings, ansi }) {
53
+ const out = [ansi.hideCur, "\x1b[H"];
54
+ const items = getFilteredSettings(settings, settingsState.search);
55
+ if (settingsState.selIdx >= items.length) {
56
+ settingsState.selIdx = Math.max(0, items.length - 1);
57
+ }
58
+
59
+ const searchLabel = "Search: ";
60
+ const searchVal = settingsState.search || "";
61
+ const ruleW = Math.min(28, Math.max(12, cols - 4));
62
+
63
+ // Title + Search header (4 rows)
64
+ out.push(`${ansi.bold}${ansi.white}Settings${ansi.reset}\x1b[K\n`);
65
+ out.push(`\x1b[K\n`);
66
+ out.push(` ${ansi.gray}${searchLabel}${ansi.white}${searchVal}${ansi.reset}\x1b[K\n`);
67
+ out.push(` ${ansi.gray}${"─".repeat(ruleW)}${ansi.reset}\x1b[K\n`);
68
+
69
+ const selectedItem = items[settingsState.selIdx] || null;
70
+ const descText = settingsState.editError
71
+ ? `Error: ${settingsState.editError}`
72
+ : selectedItem
73
+ ? selectedItem.meta.description
74
+ : "No settings match your search.";
75
+ const descLines = wrapPlain(descText, Math.max(20, cols - 4)).slice(0, 2);
76
+ const footerRows = 2 + descLines.length; // blank + desc lines + keyboard hints
77
+ const listHeight = Math.max(4, rows - 5 - footerRows);
78
+
79
+ const startIdx = Math.max(
80
+ 0,
81
+ Math.min(settingsState.selIdx - Math.floor(listHeight / 2), Math.max(0, items.length - listHeight))
82
+ );
83
+ const col1W = Math.min(30, Math.max(18, Math.floor(cols * 0.34)));
84
+
85
+ out.push(`\x1b[K\n`);
86
+ for (let r = 0; r < listHeight; r++) {
87
+ const entry = items[startIdx + r];
88
+ if (!entry) {
89
+ out.push(`\x1b[K\n`);
90
+ continue;
91
+ }
92
+ const active = startIdx + r === settingsState.selIdx;
93
+ const accentColor = ansi.accent || ansi.orange;
94
+ const marker = active ? `${accentColor}> ` : " ";
95
+ const namePart = padRight(
96
+ clipToWidth(entry.meta.label, col1W),
97
+ Math.min(displayWidth(entry.meta.label), col1W),
98
+ col1W + 2
99
+ );
100
+ const valMax = Math.max(8, cols - col1W - 6);
101
+ const valText = clipToWidth(entry.displayValue, valMax);
102
+ const nameColor = active ? `${accentColor}${ansi.bold}` : ansi.white;
103
+ const valColor = active ? `${accentColor}` : entry.meta.type === "action" ? ansi.orange : ansi.gray;
104
+ out.push(`${marker}${nameColor}${namePart}${ansi.reset}${valColor}${valText}${ansi.reset}\x1b[K\n`);
105
+ }
106
+
107
+ // Inline edit overlay line OR description bar
108
+ if (settingsState.editing) {
109
+ const edit = settingsState.editing;
110
+ const editLine = `Edit ${edit.label}: ${edit.buf}`;
111
+ const clipped = clipToWidth(editLine, Math.max(12, cols - 4));
112
+ out.push(` ${ansi.orange}${ansi.bold}${clipped}${ansi.reset}\x1b[K\n`);
113
+ } else {
114
+ out.push(`\x1b[K\n`);
115
+ }
116
+
117
+ for (const dl of descLines) {
118
+ const color = settingsState.editError ? ansi.red : ansi.gray;
119
+ out.push(` ${color}${clipToWidth(dl, Math.max(12, cols - 4))}${ansi.reset}\x1b[K\n`);
120
+ }
121
+
122
+ const footerHint = settingsState.editing
123
+ ? "Edit: enter Save · backspace Delete · esc Cancel"
124
+ : "Keyboard: ↑/↓ Navigate, ←/→ Change, enter Select, esc Clear Search/Exit";
125
+ out.push(` ${ansi.gray}${clipToWidth(footerHint, Math.max(12, cols - 4))}${ansi.reset}\x1b[K`);
126
+
127
+ // Cursor position in Search box (or edit prompt)
128
+ if (settingsState.editing) {
129
+ const editCol = Math.min(
130
+ cols,
131
+ 3 +
132
+ displayWidth(
133
+ `Edit ${settingsState.editing.label}: ${settingsState.editing.buf.slice(0, settingsState.editing.cursor)}`
134
+ )
135
+ );
136
+ out.push(`\x1b[${rows - footerRows + 1};${editCol}H`, ansi.showCur);
137
+ } else {
138
+ const searchCol = Math.min(cols, 3 + displayWidth(searchLabel + searchVal));
139
+ out.push(`\x1b[3;${searchCol}H`, ansi.showCur);
140
+ }
141
+
142
+ return out.join("");
143
+ }
144
+
145
+ /**
146
+ * Render the Manage Permissions rule inspector / deleter panel (A3 / A1).
147
+ */
148
+ function renderPermissionsScreen({ cols, rows, permState, rules, ansi }) {
149
+ const out = [ansi.hideCur, "\x1b[H"];
150
+ const filtered = getFilteredPermissions(rules, permState.search);
151
+ if (permState.selIdx >= filtered.length) {
152
+ permState.selIdx = Math.max(0, filtered.length - 1);
153
+ }
154
+
155
+ const searchLabel = "Search: ";
156
+ const searchVal = permState.search || "";
157
+ const ruleW = Math.min(28, Math.max(12, cols - 4));
158
+
159
+ out.push(
160
+ `${ansi.bold}${ansi.white}Manage Permissions${ansi.reset} ${ansi.gray}(project & global rules)${ansi.reset}\x1b[K\n`
161
+ );
162
+ out.push(`\x1b[K\n`);
163
+ out.push(` ${ansi.gray}${searchLabel}${ansi.white}${searchVal}${ansi.reset}\x1b[K\n`);
164
+ out.push(` ${ansi.gray}${"─".repeat(ruleW)}${ansi.reset}\x1b[K\n`);
165
+
166
+ const listHeight = Math.max(4, rows - 8);
167
+ const startIdx = Math.max(
168
+ 0,
169
+ Math.min(permState.selIdx - Math.floor(listHeight / 2), Math.max(0, filtered.length - listHeight))
170
+ );
171
+
172
+ out.push(`\x1b[K\n`);
173
+ if (filtered.length === 0) {
174
+ out.push(
175
+ ` ${ansi.gray}(No permission rules saved yet. Approve with [s] or [A], or use /permissions allow|deny)${ansi.reset}\x1b[K\n`
176
+ );
177
+ for (let r = 1; r < listHeight; r++) out.push(`\x1b[K\n`);
178
+ } else {
179
+ for (let r = 0; r < listHeight; r++) {
180
+ const rule = filtered[startIdx + r];
181
+ if (!rule) {
182
+ out.push(`\x1b[K\n`);
183
+ continue;
184
+ }
185
+ const active = startIdx + r === permState.selIdx;
186
+ const accentColor = ansi.accent || ansi.orange;
187
+ const marker = active ? `${accentColor}> ` : " ";
188
+ const badge = `[${rule.origin}]`.padEnd(10);
189
+ const actionCol = rule.action.toUpperCase().padEnd(6);
190
+ const toolCol = `${rule.tool}`.padEnd(16);
191
+ const scopeCol = `${rule.scope}:${rule.pattern || "*"}`;
192
+ const text = clipToWidth(`${badge} ${actionCol} ${toolCol} ${scopeCol}`, Math.max(16, cols - 6));
193
+ const color = active ? `${accentColor}${ansi.bold}` : rule.action === "deny" ? ansi.red : ansi.white;
194
+ out.push(`${marker}${color}${text}${ansi.reset}\x1b[K\n`);
195
+ }
196
+ }
197
+
198
+ const sel = filtered[permState.selIdx];
199
+ const info = permState.notice
200
+ ? permState.notice
201
+ : sel
202
+ ? `Rule #${sel.displayIndex} · ${sel.origin} · created ${sel.createdAt || "unknown"}`
203
+ : "Use ↑/↓ to browse saved permission rules.";
204
+ out.push(`\x1b[K\n`);
205
+ out.push(` ${ansi.gray}${clipToWidth(info, Math.max(12, cols - 4))}${ansi.reset}\x1b[K\n`);
206
+ out.push(
207
+ ` ${ansi.gray}${clipToWidth("Keyboard: ↑/↓ Navigate, d/Del Delete Rule, esc Clear Search/Back", Math.max(12, cols - 4))}${ansi.reset}\x1b[K`
208
+ );
209
+
210
+ const searchCol = Math.min(cols, 3 + displayWidth(searchLabel + searchVal));
211
+ out.push(`\x1b[3;${searchCol}H`, ansi.showCur);
212
+ return out.join("");
213
+ }
214
+
215
+ module.exports = {
216
+ formatSettingDisplayValue,
217
+ getFilteredSettings,
218
+ getFilteredPermissions,
219
+ renderSettingsScreen,
220
+ renderPermissionsScreen,
221
+ stepSettingValue,
222
+ parseSettingValue,
223
+ };
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+
3
+ const GRAPHEME_SEGMENTER = new Intl.Segmenter(undefined, { granularity: "grapheme" });
4
+ const EMOJI_PICT_RE = /\p{Extended_Pictographic}/u;
5
+ const ZERO_WIDTH_MARK_RE = /^[\p{Mn}\p{Me}\p{Cf}]$/u;
6
+
7
+ /**
8
+ * Strip ANSI CSI and OSC escape sequences cleanly for plain-text width calculations.
9
+ */
10
+ function stripAnsi(str = "") {
11
+ return String(str || "")
12
+ .replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, "")
13
+ .replace(/\x1b\[[0-9;?=<>]*[a-zA-Z~]/g, "");
14
+ }
15
+
16
+ function codePointWidth(cp) {
17
+ if (cp === 0) return 0;
18
+ if (
19
+ (cp >= 0x0300 && cp <= 0x036f) ||
20
+ (cp >= 0x0981 && cp <= 0x0983) ||
21
+ cp === 0x09bc ||
22
+ (cp >= 0x09be && cp <= 0x09cd) ||
23
+ cp === 0x09d7 ||
24
+ (cp >= 0x09e2 && cp <= 0x09e3) ||
25
+ cp === 0x200d ||
26
+ cp === 0x200c ||
27
+ (cp >= 0xfe00 && cp <= 0xfe0f)
28
+ ) {
29
+ return 0;
30
+ }
31
+ if (
32
+ (cp >= 0x1100 && cp <= 0x115f) ||
33
+ (cp >= 0x231a && cp <= 0x23ff) ||
34
+ (cp >= 0x2600 && cp <= 0x27bf) ||
35
+ (cp >= 0x2e80 && cp <= 0xa4cf) ||
36
+ (cp >= 0xac00 && cp <= 0xd7a3) ||
37
+ (cp >= 0xf900 && cp <= 0xfaff) ||
38
+ (cp >= 0x1f300 && cp <= 0x1faff)
39
+ ) {
40
+ return 2;
41
+ }
42
+ return 1;
43
+ }
44
+
45
+ /**
46
+ * Compute visual terminal column width of a single grapheme cluster.
47
+ */
48
+ function graphemeWidth(segment) {
49
+ if (!segment) return 0;
50
+ if (EMOJI_PICT_RE.test(segment)) return 2;
51
+ let w = 0;
52
+ for (const ch of segment) {
53
+ if (ZERO_WIDTH_MARK_RE.test(ch)) continue;
54
+ w += codePointWidth(ch.codePointAt(0));
55
+ }
56
+ return Math.min(2, Math.max(w, segment.length > 0 && !ZERO_WIDTH_MARK_RE.test(segment) ? Math.max(1, w) : w));
57
+ }
58
+
59
+ function segmentGraphemes(str) {
60
+ const out = [];
61
+ for (const part of GRAPHEME_SEGMENTER.segment(String(str || ""))) {
62
+ out.push({
63
+ segment: part.segment,
64
+ index: part.index,
65
+ endIndex: part.index + part.segment.length,
66
+ width: graphemeWidth(part.segment),
67
+ });
68
+ }
69
+ return out;
70
+ }
71
+
72
+ function displayWidth(str) {
73
+ const clean = stripAnsi(str);
74
+ let w = 0;
75
+ for (const g of segmentGraphemes(clean)) w += g.width;
76
+ return w;
77
+ }
78
+
79
+ function prevGraphemeBoundary(str, cursor) {
80
+ if (cursor <= 0) return 0;
81
+ let prev = 0;
82
+ for (const part of GRAPHEME_SEGMENTER.segment(String(str || ""))) {
83
+ if (part.index >= cursor) break;
84
+ prev = part.index;
85
+ }
86
+ return prev;
87
+ }
88
+
89
+ function nextGraphemeBoundary(str, cursor) {
90
+ const s = String(str || "");
91
+ if (cursor >= s.length) return s.length;
92
+ for (const part of GRAPHEME_SEGMENTER.segment(s)) {
93
+ const end = part.index + part.segment.length;
94
+ if (end > cursor) return end;
95
+ }
96
+ return s.length;
97
+ }
98
+
99
+ /**
100
+ * Word- and grapheme-aware plain-text wrapper that never breaks surrogate pairs or combining clusters.
101
+ */
102
+ function wrapPlain(text, width) {
103
+ const w = Math.max(10, width);
104
+ const out = [];
105
+ for (const rawLine of String(text || "").split(/\r?\n/)) {
106
+ if (!rawLine.length) {
107
+ out.push("");
108
+ continue;
109
+ }
110
+ const graphemes = segmentGraphemes(rawLine);
111
+ let startG = 0;
112
+ while (startG < graphemes.length) {
113
+ let curW = 0;
114
+ let endG = startG;
115
+ let lastSpaceG = -1;
116
+ let lastSoftBreakG = -1;
117
+
118
+ while (endG < graphemes.length) {
119
+ const gw = graphemes[endG].width;
120
+ if (curW + gw > w && endG > startG) break;
121
+ curW += gw;
122
+ const ch = graphemes[endG].segment;
123
+ if (ch === " ") lastSpaceG = endG;
124
+ else if (ch === "/" || ch === "?" || ch === "&" || ch === "=") lastSoftBreakG = endG + 1;
125
+ endG += 1;
126
+ }
127
+
128
+ if (endG < graphemes.length && lastSpaceG > startG + Math.floor((endG - startG) * 0.15)) {
129
+ out.push(rawLine.slice(graphemes[startG].index, graphemes[lastSpaceG].index));
130
+ startG = lastSpaceG + 1;
131
+ while (startG < graphemes.length && graphemes[startG].segment === " ") startG += 1;
132
+ } else if (
133
+ endG < graphemes.length &&
134
+ lastSoftBreakG > startG + Math.floor((endG - startG) * 0.4) &&
135
+ lastSoftBreakG < endG
136
+ ) {
137
+ out.push(rawLine.slice(graphemes[startG].index, graphemes[lastSoftBreakG].index));
138
+ startG = lastSoftBreakG;
139
+ } else {
140
+ const startChar = graphemes[startG].index;
141
+ const endChar = endG < graphemes.length ? graphemes[endG].index : rawLine.length;
142
+ out.push(rawLine.slice(startChar, endChar));
143
+ startG = endG;
144
+ }
145
+ }
146
+ }
147
+ return out.length ? out : [""];
148
+ }
149
+
150
+ /**
151
+ * Grapheme-safe string clipper ending cleanly with an ellipsis when exceeding maxW columns.
152
+ */
153
+ function clipToWidth(str, maxW) {
154
+ const text = String(str || "");
155
+ if (maxW <= 0) return "";
156
+ if (displayWidth(text) <= maxW) return text;
157
+ if (maxW === 1) return "…";
158
+
159
+ let out = "";
160
+ let w = 0;
161
+ for (const g of segmentGraphemes(text)) {
162
+ if (w + g.width > maxW - 1) break;
163
+ out += g.segment;
164
+ w += g.width;
165
+ }
166
+ return `${out}…`;
167
+ }
168
+
169
+ function padRight(str, visibleLen, width) {
170
+ return str + " ".repeat(Math.max(0, width - visibleLen));
171
+ }
172
+
173
+ /**
174
+ * Grapheme-safe slice by visual column offsets for mouse selection highlight/extract.
175
+ */
176
+ function sliceByVisualColumns(plainLine, startCol, endCol) {
177
+ const line = String(plainLine || "");
178
+ const graphemes = segmentGraphemes(line);
179
+ let col = 0;
180
+ let charStart = line.length;
181
+ let charEnd = line.length;
182
+ let foundStart = false;
183
+
184
+ for (const g of graphemes) {
185
+ const nextCol = col + g.width;
186
+ if (!foundStart && nextCol > startCol) {
187
+ charStart = g.index;
188
+ foundStart = true;
189
+ }
190
+ if (col >= endCol) {
191
+ charEnd = g.index;
192
+ break;
193
+ }
194
+ col = nextCol;
195
+ if (nextCol >= endCol) {
196
+ charEnd = g.endIndex;
197
+ break;
198
+ }
199
+ }
200
+ return {
201
+ before: line.slice(0, foundStart ? charStart : line.length),
202
+ selected: foundStart ? line.slice(charStart, Math.max(charStart, charEnd)) : "",
203
+ after: foundStart ? line.slice(Math.max(charStart, charEnd)) : "",
204
+ };
205
+ }
206
+
207
+ module.exports = {
208
+ stripAnsi,
209
+ graphemeWidth,
210
+ segmentGraphemes,
211
+ displayWidth,
212
+ prevGraphemeBoundary,
213
+ nextGraphemeBoundary,
214
+ wrapPlain,
215
+ clipToWidth,
216
+ padRight,
217
+ sliceByVisualColumns,
218
+ };
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+
3
+ const CONTROL_SEQ = {
4
+ altOn: "\x1b[?1049h",
5
+ altOff: "\x1b[?1049l",
6
+ mouseOn: "\x1b[?1002h\x1b[?1006h",
7
+ mouseOff: "\x1b[?1006l\x1b[?1002l\x1b[?1000l",
8
+ keysOn: "\x1b[>4;2m\x1b[>1u",
9
+ keysOff: "\x1b[<u\x1b[>4;0m",
10
+ syncStart: "\x1b[?2026h",
11
+ syncEnd: "\x1b[?2026l",
12
+ hideCur: "\x1b[?25l",
13
+ showCur: "\x1b[?25h",
14
+ };
15
+
16
+ const SCHEMES = {
17
+ amber: {
18
+ reset: "\x1b[0m",
19
+ bold: "\x1b[1m",
20
+ dim: "\x1b[2m",
21
+ underline: "\x1b[4m",
22
+ cyan: "\x1b[38;5;39m",
23
+ brightCyan: "\x1b[96m",
24
+ orange: "\x1b[38;5;208m",
25
+ amber: "\x1b[38;5;214m",
26
+ deepOrange: "\x1b[38;5;202m",
27
+ magenta: "\x1b[35m",
28
+ green: "\x1b[32m",
29
+ yellow: "\x1b[33m",
30
+ red: "\x1b[31m",
31
+ white: "\x1b[97m",
32
+ gray: "\x1b[38;5;244m",
33
+ barBg: "\x1b[48;5;235m",
34
+ topBg: "\x1b[48;5;233m",
35
+ selBg: "\x1b[48;5;166m\x1b[97m",
36
+ accent: "\x1b[38;5;208m",
37
+ accentBlue: "\x1b[38;5;208m",
38
+ settingSelBg: "\x1b[48;5;236m",
39
+ },
40
+ dark: {
41
+ reset: "\x1b[0m",
42
+ bold: "\x1b[1m",
43
+ dim: "\x1b[2m",
44
+ underline: "\x1b[4m",
45
+ cyan: "\x1b[38;5;81m",
46
+ brightCyan: "\x1b[96m",
47
+ orange: "\x1b[38;5;75m",
48
+ amber: "\x1b[38;5;111m",
49
+ deepOrange: "\x1b[38;5;39m",
50
+ magenta: "\x1b[35m",
51
+ green: "\x1b[32m",
52
+ yellow: "\x1b[33m",
53
+ red: "\x1b[31m",
54
+ white: "\x1b[97m",
55
+ gray: "\x1b[38;5;244m",
56
+ barBg: "\x1b[48;5;235m",
57
+ topBg: "\x1b[48;5;233m",
58
+ selBg: "\x1b[48;5;25m\x1b[97m",
59
+ accent: "\x1b[38;5;75m",
60
+ accentBlue: "\x1b[38;5;75m",
61
+ settingSelBg: "\x1b[48;5;236m",
62
+ },
63
+ light: {
64
+ reset: "\x1b[0m",
65
+ bold: "\x1b[1m",
66
+ dim: "\x1b[2m",
67
+ underline: "\x1b[4m",
68
+ cyan: "\x1b[34m",
69
+ brightCyan: "\x1b[36m",
70
+ orange: "\x1b[38;5;166m",
71
+ amber: "\x1b[38;5;130m",
72
+ deepOrange: "\x1b[38;5;160m",
73
+ magenta: "\x1b[35m",
74
+ green: "\x1b[32m",
75
+ yellow: "\x1b[33m",
76
+ red: "\x1b[31m",
77
+ white: "\x1b[30m",
78
+ gray: "\x1b[38;5;240m",
79
+ barBg: "\x1b[48;5;254m",
80
+ topBg: "\x1b[48;5;252m",
81
+ selBg: "\x1b[48;5;208m\x1b[97m",
82
+ accent: "\x1b[38;5;166m",
83
+ accentBlue: "\x1b[38;5;166m",
84
+ settingSelBg: "\x1b[48;5;253m",
85
+ },
86
+ terminal: {
87
+ reset: "\x1b[0m",
88
+ bold: "\x1b[1m",
89
+ dim: "\x1b[2m",
90
+ underline: "\x1b[4m",
91
+ cyan: "\x1b[36m",
92
+ brightCyan: "\x1b[96m",
93
+ orange: "\x1b[33m",
94
+ amber: "\x1b[33m",
95
+ deepOrange: "\x1b[31m",
96
+ magenta: "\x1b[35m",
97
+ green: "\x1b[32m",
98
+ yellow: "\x1b[33m",
99
+ red: "\x1b[31m",
100
+ white: "",
101
+ gray: "\x1b[2m",
102
+ barBg: "",
103
+ topBg: "",
104
+ selBg: "\x1b[7m",
105
+ accent: "\x1b[33m",
106
+ accentBlue: "\x1b[33m",
107
+ settingSelBg: "\x1b[7m",
108
+ },
109
+ };
110
+
111
+ function getPalette(schemeName = "amber") {
112
+ if (process.env.NO_COLOR !== undefined && process.env.NO_COLOR !== "") {
113
+ return {
114
+ reset: "",
115
+ bold: "",
116
+ dim: "",
117
+ underline: "",
118
+ cyan: "",
119
+ brightCyan: "",
120
+ orange: "",
121
+ amber: "",
122
+ deepOrange: "",
123
+ magenta: "",
124
+ green: "",
125
+ yellow: "",
126
+ red: "",
127
+ white: "",
128
+ gray: "",
129
+ barBg: "",
130
+ topBg: "",
131
+ selBg: "",
132
+ accentBlue: "",
133
+ settingSelBg: "",
134
+ };
135
+ }
136
+ return SCHEMES[schemeName] || SCHEMES.amber;
137
+ }
138
+
139
+ module.exports = {
140
+ CONTROL_SEQ,
141
+ SCHEMES,
142
+ getPalette,
143
+ };
package/store.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ const pathsMod = require("./src/config/paths");
4
+ const schemaMod = require("./src/settings/schema");
5
+ const settingsMod = require("./src/settings/store");
6
+ const providersMod = require("./src/config/providers");
7
+ const memoryMod = require("./src/config/memory");
8
+ const sessionsMod = require("./src/config/sessions");
9
+ const permStoreMod = require("./src/permissions/store");
10
+ const permEngineMod = require("./src/permissions/engine");
11
+
12
+ let defaultPathsCache = null;
13
+
14
+ function getDefaultPaths(forceRefresh = false) {
15
+ if (!defaultPathsCache || forceRefresh) {
16
+ defaultPathsCache = pathsMod.resolvePaths();
17
+ pathsMod.migrateLegacyAiHarness(defaultPathsCache);
18
+ }
19
+ return defaultPathsCache;
20
+ }
21
+
22
+ module.exports = {
23
+ // Paths & Migration
24
+ get HARNESS_DIR() {
25
+ return getDefaultPaths().projectDir;
26
+ },
27
+ getDefaultPaths,
28
+ resolvePaths: pathsMod.resolvePaths,
29
+ findProjectRoot: pathsMod.findProjectRoot,
30
+ migrateLegacyAiHarness: pathsMod.migrateLegacyAiHarness,
31
+ ensureStorageDirs: pathsMod.ensureStorageDirs,
32
+ safeId: pathsMod.safeId,
33
+
34
+ // Settings schema & persistence
35
+ AGENT_MODES: schemaMod.AGENT_MODES,
36
+ TOOL_PERMISSIONS: schemaMod.TOOL_PERMISSIONS,
37
+ NON_WORKSPACE_MODES: schemaMod.NON_WORKSPACE_MODES,
38
+ DEFAULT_SETTINGS: schemaMod.DEFAULT_SETTINGS,
39
+ SETTINGS_SCHEMA: schemaMod.SETTINGS_SCHEMA,
40
+ SCHEMA_BY_KEY: schemaMod.SCHEMA_BY_KEY,
41
+ canonicalSettingKey: schemaMod.canonicalSettingKey,
42
+ parseSettingValue: schemaMod.parseSettingValue,
43
+ stepSettingValue: settingsMod.stepSettingValue,
44
+ resolveEffectiveSettings: settingsMod.resolveEffectiveSettings,
45
+ resolveEffectiveModel: settingsMod.resolveEffectiveModel,
46
+ loadSettings: (paths = getDefaultPaths()) => settingsMod.loadPersistedSettings(paths),
47
+ saveSettings: (settings, paths = getDefaultPaths()) => settingsMod.savePersistedSettings(settings, paths),
48
+ updatePersistedSetting: (key, value, paths = getDefaultPaths()) =>
49
+ settingsMod.updatePersistedSetting(key, value, paths),
50
+
51
+ // Providers
52
+ redactSecret: providersMod.redactSecret,
53
+ loadProviders: (envFallback, paths = getDefaultPaths()) => providersMod.loadProviders(envFallback, paths),
54
+ saveProviders: (store, paths = getDefaultPaths()) => providersMod.saveProviders(store, paths),
55
+ upsertProvider: (envFallback, cfg, paths = getDefaultPaths()) =>
56
+ providersMod.upsertProvider(envFallback, cfg, paths),
57
+ addProviderModels: (envFallback, name, models, paths = getDefaultPaths()) =>
58
+ providersMod.addProviderModels(envFallback, name, models, paths),
59
+ setActiveProvider: (envFallback, name, paths = getDefaultPaths()) =>
60
+ providersMod.setActiveProvider(envFallback, name, paths),
61
+ removeProvider: (envFallback, name, paths = getDefaultPaths()) =>
62
+ providersMod.removeProvider(envFallback, name, paths),
63
+
64
+ // Memory
65
+ loadGlobalMemory: (paths = getDefaultPaths()) => memoryMod.loadGlobalMemory(paths),
66
+ loadGlobalMemoryEntries: (paths = getDefaultPaths()) => memoryMod.loadGlobalMemoryEntries(paths),
67
+ saveGlobalMemory: (items, paths = getDefaultPaths()) => memoryMod.saveGlobalMemory(items, paths),
68
+ addGlobalMemory: (fact, source = "user", paths = getDefaultPaths()) =>
69
+ memoryMod.addGlobalMemory(fact, source, paths),
70
+ removeGlobalMemoryAt: (idx, paths = getDefaultPaths()) => memoryMod.removeGlobalMemoryAt(idx, paths),
71
+ loadProjectMemoryEntries: (paths = getDefaultPaths()) => memoryMod.loadProjectMemoryEntries(paths),
72
+ saveProjectMemory: (items, paths = getDefaultPaths()) => memoryMod.saveProjectMemory(items, paths),
73
+ addProjectMemory: (fact, source = "user", paths = getDefaultPaths()) =>
74
+ memoryMod.addProjectMemory(fact, source, paths),
75
+ isGlobalMemoryFact: memoryMod.isGlobalMemoryFact,
76
+ classifyMemoryIntent: memoryMod.classifyMemoryIntent,
77
+
78
+ // Sessions
79
+ createEmptySession: sessionsMod.createEmptySession,
80
+ loadSession: (id, defaultModel = "", paths = getDefaultPaths()) => sessionsMod.loadSession(id, defaultModel, paths),
81
+ saveSession: (session, paths = getDefaultPaths()) => sessionsMod.saveSession(session, paths),
82
+ renameSession: (session, newId, paths = getDefaultPaths()) => sessionsMod.renameSession(session, newId, paths),
83
+ forkSession: (session, newId, paths = getDefaultPaths()) => sessionsMod.forkSession(session, newId, paths),
84
+ listSessions: (paths = getDefaultPaths()) => sessionsMod.listSessions(paths),
85
+ groupSessionsByDate: sessionsMod.groupSessionsByDate,
86
+ suggestSessionIdFromPrompt: (promptText, paths = getDefaultPaths()) =>
87
+ sessionsMod.suggestSessionIdFromPrompt(promptText, paths),
88
+ loadInputHistory: (paths = getDefaultPaths()) => sessionsMod.loadInputHistory(paths),
89
+ saveInputHistory: (items, paths = getDefaultPaths()) => sessionsMod.saveInputHistory(items, paths),
90
+ deleteSession: (id, paths = getDefaultPaths()) => sessionsMod.deleteSession(id, paths),
91
+
92
+ // Permissions
93
+ loadPermissionRules: permStoreMod.loadPermissionRules,
94
+ savePermissionRules: permStoreMod.savePermissionRules,
95
+ addPermissionRule: permStoreMod.addPermissionRule,
96
+ listCombinedRules: permStoreMod.listCombinedRules,
97
+ removePermissionRuleByIndex: permStoreMod.removePermissionRuleByIndex,
98
+ resetPermissionRules: permStoreMod.resetPermissionRules,
99
+ evaluatePermission: permEngineMod.evaluatePermission,
100
+ buildSuggestedRules: permEngineMod.buildSuggestedRules,
101
+ parseShellCommand: permEngineMod.parseShellCommand,
102
+ getSegmentPrefix: permEngineMod.getSegmentPrefix,
103
+ isReadOnlyShellCommand: permEngineMod.isReadOnlyShellCommand,
104
+ isPathInsideWorkspace: permEngineMod.isPathInsideWorkspace,
105
+ checkHardDenylist: permEngineMod.checkHardDenylist,
106
+ isSecretFilePath: permEngineMod.isSecretFilePath,
107
+ };