geneseed 3.1.1 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +68 -1
- package/DESIGN.md +15 -15
- package/README.md +1 -1
- package/SETUP.md +1 -1
- package/SHIPPED.md +1 -1
- package/bin/{geneseed.mjs → build-driver.mjs} +39 -42
- package/bin/geneseed-cli.mjs +33 -32
- package/bin/geneseed-hook.mjs +7 -7
- package/docs/design-history.md +40 -40
- package/docs/extending.md +111 -83
- package/harness.config.json +1 -1
- package/js/README.md +203 -0
- package/js/build/bundle.mjs +231 -0
- package/js/{catalog.mjs → build/catalog.mjs} +7 -7
- package/js/build/emit-claude.mjs +287 -0
- package/js/build/emit-common.mjs +255 -0
- package/js/build/emit-opencode.mjs +214 -0
- package/js/{generate.mjs → build/generate.mjs} +27 -28
- package/js/{render.mjs → build/render.mjs} +13 -9
- package/js/{checkout.mjs → build/source.mjs} +9 -9
- package/js/build/stubs.mjs +256 -0
- package/js/{themes.mjs → build/themes.mjs} +24 -24
- package/js/build/version.mjs +155 -0
- package/js/{hooks.mjs → hosts/hooks.mjs} +47 -44
- package/js/{hosts.mjs → hosts/hosts.mjs} +30 -28
- package/js/{installs.mjs → hosts/installs.mjs} +18 -16
- package/js/{link.mjs → hosts/link.mjs} +29 -28
- package/js/{mcp.mjs → hosts/mcp.mjs} +10 -9
- package/js/{native.mjs → hosts/native.mjs} +24 -22
- package/js/{opencode.mjs → hosts/opencode.mjs} +12 -7
- package/js/{settings.mjs → hosts/settings.mjs} +63 -55
- package/js/inspect/checks-authoring.mjs +761 -0
- package/js/inspect/checks-build.mjs +231 -0
- package/js/inspect/checks-repo.mjs +308 -0
- package/js/{diff.mjs → inspect/diff.mjs} +34 -31
- package/js/inspect/doctor.mjs +286 -0
- package/js/{excludes.mjs → inspect/excludes.mjs} +30 -33
- package/js/{inventory.mjs → inspect/inventory.mjs} +20 -17
- package/js/{registry.mjs → inspect/registry.mjs} +12 -10
- package/js/inspect/scan.mjs +125 -0
- package/js/{status.mjs → inspect/status.mjs} +27 -25
- package/js/inspect/validate.mjs +199 -0
- package/js/lib/fs.mjs +37 -759
- package/js/lib/json.mjs +344 -0
- package/js/lib/paths.mjs +242 -0
- package/js/lib/proc.mjs +3 -3
- package/js/lib/text.mjs +181 -0
- package/js/lib/udiff.mjs +1 -1
- package/js/{memory.mjs → maintain/memory.mjs} +10 -10
- package/js/{migrate.mjs → maintain/migrate.mjs} +28 -26
- package/js/{setup.mjs → maintain/setup.mjs} +34 -32
- package/js/{uninstall.mjs → maintain/uninstall.mjs} +55 -56
- package/js/{update.mjs → maintain/update.mjs} +51 -51
- package/js/{anim.mjs → ui/anim.mjs} +30 -28
- package/js/{cli.mjs → ui/cli.mjs} +10 -10
- package/js/{menu.mjs → ui/menu.mjs} +10 -9
- package/js/{tui.mjs → ui/tui.mjs} +36 -34
- package/js/web/actions.mjs +84 -85
- package/js/web/activity.mjs +22 -21
- package/js/web/api.mjs +72 -50
- package/js/web/daemon.mjs +319 -0
- package/js/web/docs.mjs +24 -21
- package/js/web/graph.mjs +0 -0
- package/js/web/handler.mjs +442 -0
- package/js/web/jobs.mjs +21 -19
- package/js/web/routes.mjs +223 -0
- package/js/web/server.mjs +56 -987
- package/package.json +11 -3
- package/src/doctrines/README.md +1 -1
- package/themes/opencode/README.md +1 -1
- package/web/dist/assets/{About-DyK7yRy7.js → About-CPvIFZGh.js} +1 -1
- package/web/dist/assets/{Activity-D_sYBlW-.js → Activity-z0uXdS7J.js} +1 -1
- package/web/dist/assets/{ActivityDetail-BomKcMhy.js → ActivityDetail-CEj5IJpF.js} +1 -1
- package/web/dist/assets/{Diff-BSvi1WUg.js → Diff-BMR8fPuG.js} +1 -1
- package/web/dist/assets/{Doctor-Cz1s-y1n.js → Doctor-Bz5qE4r9.js} +1 -1
- package/web/dist/assets/{Graph-CuntzFJ0.js → Graph-BV6a6t2l.js} +1 -1
- package/web/dist/assets/{Harnesses-DgRyOviS.js → Harnesses-C5Ag5PaQ.js} +1 -1
- package/web/dist/assets/{Laws-CWk3Mpri.js → Laws-BK07NKw9.js} +1 -1
- package/web/dist/assets/{Library-DXhTN9ju.js → Library-CiXN9sC3.js} +1 -1
- package/web/dist/assets/{Markdown-BoiZcdUl.js → Markdown-DG6FjUz-.js} +1 -1
- package/web/dist/assets/{Profile-DfCHlZ03.js → Profile-B2oSvdxH.js} +1 -1
- package/web/dist/assets/{Rules-eND7hJv9.js → Rules-DobVPd80.js} +1 -1
- package/web/dist/assets/{Skills-CDl9opZO.js → Skills-DQPsvsn9.js} +1 -1
- package/web/dist/assets/{StatusBadge-DSDtcArX.js → StatusBadge-BhJ3HhdI.js} +1 -1
- package/web/dist/assets/{Themes-CoAWuIeM.js → Themes-BP38FBU9.js} +1 -1
- package/web/dist/assets/{activity-Dmb0FTAx.js → activity-D9mfv7pY.js} +1 -1
- package/web/dist/assets/index-BE226Gv6.css +1 -0
- package/web/dist/assets/{index-jrY4m9jP.js → index-BZ7cPLMI.js} +1 -1
- package/web/dist/assets/index-BgIs5eIa.js +12 -0
- package/web/dist/assets/{index-Dg58ScBe.js → index-DGM5j2hB.js} +1 -1
- package/web/dist/index.html +2 -2
- package/web/src/pages/Laws.jsx +1 -1
- package/docs/declined.md +0 -200
- package/docs/limits.md +0 -329
- package/js/doctor.mjs +0 -1750
- package/js/emit.mjs +0 -1411
- package/web/dist/assets/index-B-mXquBZ.css +0 -1
- package/web/dist/assets/index-CH_Z725C.js +0 -12
package/js/web/actions.mjs
CHANGED
|
@@ -7,15 +7,15 @@
|
|
|
7
7
|
* of magnitude:
|
|
8
8
|
*
|
|
9
9
|
* * `_memory_drop_index` — "check whether P5's `learn` ported it". It did not; nothing in
|
|
10
|
-
* `js/` referenced it. It lands in `js/hooks.mjs`, beside the other memory-store
|
|
10
|
+
* `js/` referenced it. It lands in `js/hosts/hooks.mjs`, beside the other memory-store
|
|
11
11
|
* primitives, because that is where its Python siblings' twins already live.
|
|
12
12
|
* * `_mcp_load` — "already in js/ (P6c)". What crossed in P6c is `readJsonc` and a
|
|
13
13
|
* five-line no-host reader inside `js/web/api.mjs` for `wiki.jsonc`. The host fork and
|
|
14
|
-
* the other twelve MCP functions are 168 lines of new `js/mcp.mjs`.
|
|
14
|
+
* the other twelve MCP functions are 168 lines of new `js/hosts/mcp.mjs`.
|
|
15
15
|
* * `settings.mjs`'s atomic write — a DIFFERENT Python function from `_mcp_save`, with a
|
|
16
|
-
* different temp suffix and no parent-directory creation. See `js/mcp.mjs`.
|
|
16
|
+
* different temp suffix and no parent-directory creation. See `js/hosts/mcp.mjs`.
|
|
17
17
|
* * `api_install_toggle` — "~25 new; `_move_tree`, `_prune_empty_ancestors` and the stash
|
|
18
|
-
* ARE in `js/uninstall.mjs` (P5h)". `DISABLED_STASH`, `installKind` and `installState`
|
|
18
|
+
* ARE in `js/maintain/uninstall.mjs` (P5h)". `DISABLED_STASH`, `installKind` and `installState`
|
|
19
19
|
* are. `_move_tree`, `_prune_empty_ancestors`, `_install_move_list`, `_install_relive`,
|
|
20
20
|
* `_install_readd_entry`, `_install_deactivate`, `_install_reactivate`,
|
|
21
21
|
* `_claude_deactivate` and `_claude_reactivate` are not — 293 lines of unported
|
|
@@ -57,15 +57,13 @@
|
|
|
57
57
|
*
|
|
58
58
|
* `web/dist` therefore does NOT need rebuilding, and it was not rebuilt.
|
|
59
59
|
*
|
|
60
|
-
* WHAT GATES IT, since no cell can. The value never reaches a response, so
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* That is the absolute-assertion-per-side discipline a tolerant comparison owes, applied to
|
|
68
|
-
* a value the byte gate cannot reach.
|
|
60
|
+
* WHAT GATES IT, since no cell can. The value never reaches a response, so a request-level
|
|
61
|
+
* corpus is structurally blind to it — exactly the shape a function-level gate answers and a
|
|
62
|
+
* cell cannot. That gate is `tests/unit/web_jobs.test.mjs`: it asserts the argv HEAD
|
|
63
|
+
* absolutely — `process.execPath` plus `bin/build-driver.mjs`, and no interpreter name
|
|
64
|
+
* anywhere in it — and pins the TAIL, every argument after the head, against a frozen
|
|
65
|
+
* literal. The tail is where a real bug would live, and asserting it absolutely rather than
|
|
66
|
+
* by comparison is what let it outlive the implementation it was once compared against.
|
|
69
67
|
*
|
|
70
68
|
* THE CODE IS P6g's, THE DECISION IS THIS PHASE's. `api_install_cmd`, `api_deploy_cmd` and
|
|
71
69
|
* `api_restore` all sit behind `/api/actions/<x>`, which needs the `JobManager` to route at
|
|
@@ -86,16 +84,17 @@
|
|
|
86
84
|
* behaviour a 501 produces.
|
|
87
85
|
*
|
|
88
86
|
* ---------------------------------------------------------------------------------------
|
|
89
|
-
* `api_install_toggle`
|
|
90
|
-
*
|
|
91
|
-
* The endpoint is 27 lines over three engine calls
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
* file-move fixture
|
|
97
|
-
*
|
|
98
|
-
*
|
|
87
|
+
* `api_install_toggle` CROSSED IN P6i, AND THE ENGINE CAME WITH IT.
|
|
88
|
+
*
|
|
89
|
+
* The endpoint is 27 lines over three engine calls, and the reason it waited is worth
|
|
90
|
+
* keeping: two of the three pull in 293 lines of all-or-nothing tree moves with rollback, a
|
|
91
|
+
* stash layout, an `instructions`-entry unmerge, a re-emit-while-disabled guard and a host
|
|
92
|
+
* fork. None of that is web code, and porting it inside a web phase would have put the
|
|
93
|
+
* largest engine block behind the weakest available gate — a request script rather than a
|
|
94
|
+
* file-move fixture. So it landed where it belongs: `installDeactivate` and
|
|
95
|
+
* `installReactivate` live in `js/maintain/uninstall.mjs` beside `installUninstall`, the
|
|
96
|
+
* reversible siblings of the same owned-file walk, and `apiInstallToggle` below is the thin
|
|
97
|
+
* endpoint over them.
|
|
99
98
|
*/
|
|
100
99
|
import {
|
|
101
100
|
accessSync, constants, copyFileSync, mkdirSync, mkdtempSync, rmSync, statSync, unlinkSync,
|
|
@@ -103,31 +102,31 @@ import {
|
|
|
103
102
|
import os from 'node:os';
|
|
104
103
|
import path from 'node:path';
|
|
105
104
|
|
|
106
|
-
import { emitGlobalInto } from '../../bin/
|
|
105
|
+
import { emitGlobalInto } from '../../bin/build-driver.mjs';
|
|
107
106
|
import {
|
|
108
107
|
ROOT, discoverNames, knownRuleIds, PACK_ORDER,
|
|
109
|
-
} from '../
|
|
110
|
-
import { withStdoutSwallowed } from '../diff.mjs';
|
|
111
|
-
import { excludeAdd, excludeRemove } from '../excludes.mjs';
|
|
112
|
-
import { setupBuildArgs } from '../generate.mjs';
|
|
113
|
-
import { frontmatter, memoryDropIndex } from '../hooks.mjs';
|
|
108
|
+
} from '../build/source.mjs';
|
|
109
|
+
import { withStdoutSwallowed } from '../inspect/diff.mjs';
|
|
110
|
+
import { excludeAdd, excludeRemove } from '../inspect/excludes.mjs';
|
|
111
|
+
import { setupBuildArgs } from '../build/generate.mjs';
|
|
112
|
+
import { frontmatter, memoryDropIndex } from '../hosts/hooks.mjs';
|
|
114
113
|
import {
|
|
115
114
|
HOSTS, bobConfigDir, claudeConfigDir, copilotConfigDir, expanduser, opencodeConfigDir,
|
|
116
|
-
|
|
117
|
-
} from '../hosts.mjs';
|
|
115
|
+
resolvePath,
|
|
116
|
+
} from '../hosts/hosts.mjs';
|
|
118
117
|
import {
|
|
119
118
|
EMIT_HOST_SCOPE, doctrinesForBuild, excludedRulesOfDir, footprintOfDir, installState,
|
|
120
119
|
installTargets, modeOfDir, postureOfDir, readMaybe,
|
|
121
|
-
} from '../installs.mjs';
|
|
120
|
+
} from '../hosts/installs.mjs';
|
|
122
121
|
import {
|
|
123
122
|
MCP_PRESETS, isDict, mcpApply, mcpCommented, mcpInstallTargets, mcpKnownNames, mcpLoad,
|
|
124
123
|
mcpMeta, mcpPresetBlock, mcpSave, mcpSetEnabled, mcpState,
|
|
125
|
-
} from '../mcp.mjs';
|
|
126
|
-
import {
|
|
127
|
-
|
|
128
|
-
} from '../lib/
|
|
129
|
-
import { installDeactivate, installReactivate, installUninstall } from '../uninstall.mjs';
|
|
130
|
-
import {
|
|
124
|
+
} from '../hosts/mcp.mjs';
|
|
125
|
+
import { readText, writeText } from '../lib/fs.mjs';
|
|
126
|
+
import { parseJson, formatRepr, formatValue, isTruthy } from '../lib/json.mjs';
|
|
127
|
+
import { WHITESPACE, codePointLength, stripWhitespace } from '../lib/text.mjs';
|
|
128
|
+
import { installDeactivate, installReactivate, installUninstall } from '../maintain/uninstall.mjs';
|
|
129
|
+
import { splitLines } from '../lib/udiff.mjs';
|
|
131
130
|
import {
|
|
132
131
|
NotFound, deployed, emitChoices, fingerprint, themeChoices, viewCfg, within,
|
|
133
132
|
} from './api.mjs';
|
|
@@ -140,7 +139,7 @@ const bget = (body, key, dflt = null) => (isDict(body) && Object.hasOwn(body, ke
|
|
|
140
139
|
? body[key] : dflt);
|
|
141
140
|
|
|
142
141
|
/** `str(x or "")` — Python's truthiness, then Python's `str`. */
|
|
143
|
-
const strOr = (v) => (
|
|
142
|
+
const strOr = (v) => (isTruthy(v) ? formatValue(v) : '');
|
|
144
143
|
|
|
145
144
|
/**
|
|
146
145
|
* A request body's `doctrines` -> a normalised pack list, or `null` for "said nothing usable".
|
|
@@ -199,7 +198,7 @@ function bodyExcludeRules(body) {
|
|
|
199
198
|
}
|
|
200
199
|
|
|
201
200
|
/** `str.split()` with no argument — runs of PYTHON whitespace, no empties. */
|
|
202
|
-
const
|
|
201
|
+
const splitWords = (s) => s.split(new RegExp(`[${WHITESPACE}]+`)).filter(Boolean);
|
|
203
202
|
|
|
204
203
|
/** `datetime.date.today().isoformat()` — LOCAL, as the reference's naive `date.today()` is. */
|
|
205
204
|
export function todayIso(d = new Date()) {
|
|
@@ -241,7 +240,7 @@ const rulesPath = (state) => path.join(state.target, RULES_FILE);
|
|
|
241
240
|
* `_web_catalog.RULE_HEAD_RE` — `## R<n> — Title`, anchored at column 0 so a rule body's
|
|
242
241
|
* fenced code and the stub's indented format example never parse as rules.
|
|
243
242
|
*
|
|
244
|
-
* The whitespace classes are `
|
|
243
|
+
* The whitespace classes are `WHITESPACE`, not `\s`: P6d measured the two apart and this
|
|
245
244
|
* pattern runs over a HAND-EDITED file, which is where a non-breaking space actually turns
|
|
246
245
|
* up. `\S` is its complement for the same reason.
|
|
247
246
|
*
|
|
@@ -253,26 +252,26 @@ const rulesPath = (state) => path.join(state.target, RULES_FILE);
|
|
|
253
252
|
* and the web editor cannot produce (it writes `R<n>` itself from `max(ids) + 1`).
|
|
254
253
|
*/
|
|
255
254
|
export const RULE_HEAD_RE = new RegExp(
|
|
256
|
-
`^##[${
|
|
257
|
-
+ `([^${
|
|
255
|
+
`^##[${WHITESPACE}]+R(\\d+)[${WHITESPACE}]*[—–-]+[${WHITESPACE}]*`
|
|
256
|
+
+ `([^${WHITESPACE}].*?)[${WHITESPACE}]*$`,
|
|
258
257
|
);
|
|
259
258
|
|
|
260
259
|
/** `_web_catalog.RULES_BUDGET` — advisory; nothing blocks past it. */
|
|
261
260
|
export const RULES_BUDGET = { max_rules: 15, max_tokens: 1500 };
|
|
262
261
|
|
|
263
|
-
const META_RE = new RegExp(`^\\((.+)\\)[${
|
|
262
|
+
const META_RE = new RegExp(`^\\((.+)\\)[${WHITESPACE}]*$`);
|
|
264
263
|
|
|
265
264
|
/** `_web_catalog._parse_rule_meta` — `{}` when the line is body rather than metadata. */
|
|
266
265
|
function parseRuleMeta(line) {
|
|
267
|
-
const m = META_RE.exec(
|
|
266
|
+
const m = META_RE.exec(stripWhitespace(line));
|
|
268
267
|
if (!m) return {};
|
|
269
268
|
const meta = {};
|
|
270
269
|
for (const part of m[1].split('|')) {
|
|
271
270
|
const at = part.indexOf(':');
|
|
272
271
|
if (at < 0) continue; // `partition` with no separator — not a pair
|
|
273
|
-
const key =
|
|
272
|
+
const key = stripWhitespace(part.slice(0, at)).toLowerCase().replaceAll(' ', '_');
|
|
274
273
|
if (['scope', 'source', 'trial_until'].includes(key)) {
|
|
275
|
-
meta[key] =
|
|
274
|
+
meta[key] = stripWhitespace(part.slice(at + 1));
|
|
276
275
|
}
|
|
277
276
|
}
|
|
278
277
|
return meta;
|
|
@@ -286,7 +285,7 @@ function parseRuleMeta(line) {
|
|
|
286
285
|
* formatting, hand-written sections — untouched.
|
|
287
286
|
*/
|
|
288
287
|
export function parseRules(text) {
|
|
289
|
-
const lines =
|
|
288
|
+
const lines = splitLines(text);
|
|
290
289
|
const rules = [];
|
|
291
290
|
const warnings = [];
|
|
292
291
|
const seen = new Set();
|
|
@@ -301,7 +300,7 @@ export function parseRules(text) {
|
|
|
301
300
|
if (seen.has(rid)) warnings.push(`duplicate rule id R${rid}`);
|
|
302
301
|
seen.add(rid);
|
|
303
302
|
let k = idx + 1;
|
|
304
|
-
while (k < end && !
|
|
303
|
+
while (k < end && !stripWhitespace(lines[k])) k += 1;
|
|
305
304
|
const meta = k < end ? parseRuleMeta(lines[k]) : {};
|
|
306
305
|
if (Object.keys(meta).length) k += 1;
|
|
307
306
|
rules.push({
|
|
@@ -310,7 +309,7 @@ export function parseRules(text) {
|
|
|
310
309
|
scope: Object.hasOwn(meta, 'scope') ? meta.scope : 'project',
|
|
311
310
|
source: Object.hasOwn(meta, 'source') ? meta.source : '',
|
|
312
311
|
trial_until: Object.hasOwn(meta, 'trial_until') ? meta.trial_until : '',
|
|
313
|
-
body:
|
|
312
|
+
body: stripWhitespace(lines.slice(k, end).join('\n')),
|
|
314
313
|
start: idx,
|
|
315
314
|
end,
|
|
316
315
|
});
|
|
@@ -338,8 +337,8 @@ export function apiRules(state) {
|
|
|
338
337
|
return { exists: true, path: p, rules: out, warnings, fingerprint: fingerprint(text),
|
|
339
338
|
// `len(text) // 4` — CODE POINTS. `String.length` counts UTF-16 units, so an emoji in a
|
|
340
339
|
// rule body would put the two token estimates two apart.
|
|
341
|
-
stats: { rules: rules.length, lines:
|
|
342
|
-
tokens: Math.floor(
|
|
340
|
+
stats: { rules: rules.length, lines: splitLines(text).length,
|
|
341
|
+
tokens: Math.floor(codePointLength(text) / 4), ...RULES_BUDGET } };
|
|
343
342
|
}
|
|
344
343
|
|
|
345
344
|
/** `_web_actions._rules_read`. */
|
|
@@ -353,7 +352,7 @@ function ruleBlock(rid, title, scope, source, trialUntil, body) {
|
|
|
353
352
|
const meta = [`scope: ${scope}`];
|
|
354
353
|
if (source) meta.push(`source: ${source}`);
|
|
355
354
|
if (trialUntil) meta.push(`trial until: ${trialUntil}`);
|
|
356
|
-
return `## R${rid} — ${title}\n(${meta.join(' | ')})\n${
|
|
355
|
+
return `## R${rid} — ${title}\n(${meta.join(' | ')})\n${stripWhitespace(body)}\n`;
|
|
357
356
|
}
|
|
358
357
|
|
|
359
358
|
/**
|
|
@@ -365,14 +364,14 @@ function ruleBlock(rid, title, scope, source, trialUntil, body) {
|
|
|
365
364
|
* `int()`.
|
|
366
365
|
*/
|
|
367
366
|
function ruleFields(body) {
|
|
368
|
-
const title =
|
|
369
|
-
const text =
|
|
367
|
+
const title = splitWords(strOr(bget(body, 'title'))).join(' ');
|
|
368
|
+
const text = stripWhitespace(strOr(bget(body, 'body')));
|
|
370
369
|
if (!title) throw new Error('a rule needs a title');
|
|
371
370
|
if (!text) throw new Error('a rule needs body text');
|
|
372
371
|
let scope = bget(body, 'scope');
|
|
373
372
|
if (scope !== 'user' && scope !== 'project') scope = 'project';
|
|
374
|
-
const source =
|
|
375
|
-
const trial =
|
|
373
|
+
const source = splitWords(strOr(bget(body, 'source'))).join(' ');
|
|
374
|
+
const trial = stripWhitespace(strOr(bget(body, 'trial_until')));
|
|
376
375
|
if (trial && !/^\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}$/u.test(trial)) {
|
|
377
376
|
throw new Error('trial until must be YYYY-MM-DD');
|
|
378
377
|
}
|
|
@@ -388,7 +387,7 @@ function ruleFields(body) {
|
|
|
388
387
|
*/
|
|
389
388
|
function ruleId(v) {
|
|
390
389
|
if (typeof v === 'string') {
|
|
391
|
-
const s =
|
|
390
|
+
const s = stripWhitespace(v);
|
|
392
391
|
if (!/^[+-]?\d+$/.test(s)) throw new NotFound('rule id');
|
|
393
392
|
return Number(s);
|
|
394
393
|
}
|
|
@@ -412,7 +411,7 @@ function ruleId(v) {
|
|
|
412
411
|
export function apiRulesMutate(state, body) {
|
|
413
412
|
const op = bget(body, 'op');
|
|
414
413
|
if (op !== 'add' && op !== 'update' && op !== 'delete') {
|
|
415
|
-
throw new NotFound(`rules op ${
|
|
414
|
+
throw new NotFound(`rules op ${formatRepr(op)}`);
|
|
416
415
|
}
|
|
417
416
|
const [p, original] = rulesRead(state);
|
|
418
417
|
let text = original;
|
|
@@ -432,17 +431,17 @@ export function apiRulesMutate(state, body) {
|
|
|
432
431
|
rid = ruleId(bget(body, 'id'));
|
|
433
432
|
const target = rules.find((r) => r.id === rid);
|
|
434
433
|
if (target === undefined) throw new NotFound(`rule R${rid}`);
|
|
435
|
-
const lines =
|
|
434
|
+
const lines = splitLines(text);
|
|
436
435
|
if (op === 'update') {
|
|
437
436
|
const [title, rtext, scope, source, trial] = ruleFields(body);
|
|
438
437
|
const block = ruleBlock(rid, title, scope, source, trial, rtext);
|
|
439
438
|
lines.splice(target.start, target.end - target.start,
|
|
440
|
-
...
|
|
439
|
+
...splitLines(block.replace(/\n+$/, '')));
|
|
441
440
|
} else {
|
|
442
441
|
// delete — also swallow ONE preceding blank separator line, or repeated deletes leave
|
|
443
442
|
// a growing run of blank lines in the user's file.
|
|
444
443
|
let start = target.start;
|
|
445
|
-
if (start > 0 && !
|
|
444
|
+
if (start > 0 && !stripWhitespace(lines[start - 1])) start -= 1;
|
|
446
445
|
lines.splice(start, target.end - start);
|
|
447
446
|
}
|
|
448
447
|
next = `${lines.join('\n').replace(/\n+$/, '')}\n`;
|
|
@@ -475,14 +474,14 @@ export function apiRulesPromote(state, body) {
|
|
|
475
474
|
const res = apiRulesMutate(state, {
|
|
476
475
|
op: 'add',
|
|
477
476
|
fingerprint: bget(body, 'fingerprint', ''),
|
|
478
|
-
title:
|
|
479
|
-
body:
|
|
480
|
-
: (
|
|
477
|
+
title: isTruthy(bget(body, 'title')) ? bget(body, 'title') : fmName,
|
|
478
|
+
body: isTruthy(bget(body, 'body')) ? bget(body, 'body')
|
|
479
|
+
: (stripWhitespace(memBody) || fmDesc),
|
|
481
480
|
scope: bget(body, 'scope'),
|
|
482
481
|
source: `memory ${name}, promoted ${today}`,
|
|
483
482
|
trial_until: trial,
|
|
484
483
|
});
|
|
485
|
-
if (
|
|
484
|
+
if (isTruthy(res.ok) && isTruthy(bget(body, 'delete_memory'))) {
|
|
486
485
|
apiMemoryDelete(state, name);
|
|
487
486
|
res.deleted_memory = name;
|
|
488
487
|
}
|
|
@@ -548,7 +547,7 @@ export function apiMemoryDelete(state, name) {
|
|
|
548
547
|
*/
|
|
549
548
|
export function apiExcludesMutate(state, body) {
|
|
550
549
|
const action = bget(body, 'action');
|
|
551
|
-
const p =
|
|
550
|
+
const p = stripWhitespace(strOr(bget(body, 'path')));
|
|
552
551
|
if ((action !== 'add' && action !== 'remove') || !p) {
|
|
553
552
|
return { ok: false, path: p,
|
|
554
553
|
messages: ['body must be {action: add|remove, path: <folder>}'] };
|
|
@@ -613,7 +612,7 @@ export function mcpTargetPaths() {
|
|
|
613
612
|
|
|
614
613
|
export function apiMcpToggle(state, body) {
|
|
615
614
|
const name = strOr(bget(body, 'name'));
|
|
616
|
-
const want =
|
|
615
|
+
const want = isTruthy(bget(body, 'enabled'));
|
|
617
616
|
const pathArg = strOr(bget(body, 'path'));
|
|
618
617
|
const known = mcpTargetPaths();
|
|
619
618
|
const hit = known.get(pathArg);
|
|
@@ -708,7 +707,7 @@ export function buildOverride(state, body) {
|
|
|
708
707
|
* `.geneseed-emit`, so the EXPECTED render uses the install's own host dialect.
|
|
709
708
|
*
|
|
710
709
|
* Returns the HOST rather than a function, because `emitGlobalInto(host, …)` is how the twin
|
|
711
|
-
* of `build.HOSTS[host]["emit_global"]` is already spelt (`js/diff.mjs` calls it that way).
|
|
710
|
+
* of `build.HOSTS[host]["emit_global"]` is already spelt (`js/inspect/diff.mjs` calls it that way).
|
|
712
711
|
* An unknown or missing marker falls back to OpenCode, exactly as the reference's two
|
|
713
712
|
* `.get(..., default)` calls do.
|
|
714
713
|
*/
|
|
@@ -749,10 +748,10 @@ export function apiRestore(state, files) {
|
|
|
749
748
|
const restored = [];
|
|
750
749
|
const deleted = [];
|
|
751
750
|
const errors = [];
|
|
752
|
-
const target =
|
|
751
|
+
const target = resolvePath(state.target);
|
|
753
752
|
const tmp = mkdtempSync(path.join(os.tmpdir(), 'geneseed-restore-'));
|
|
754
753
|
try {
|
|
755
|
-
const expected =
|
|
754
|
+
const expected = resolvePath(path.join(tmp, 'expected'));
|
|
756
755
|
withStdoutSwallowed(() => emitGlobalInto(globalEmitHostFor(state.emit), {
|
|
757
756
|
theme: state.theme,
|
|
758
757
|
out: path.join(tmp, 'bundle'),
|
|
@@ -768,10 +767,10 @@ export function apiRestore(state, files) {
|
|
|
768
767
|
// read-side hole `diffCollect` had (and the reason the panel offered the file at all).
|
|
769
768
|
doctrines: doctrinesForBuild(target),
|
|
770
769
|
}));
|
|
771
|
-
for (const raw of (
|
|
772
|
-
const rel =
|
|
773
|
-
const dst =
|
|
774
|
-
const src =
|
|
770
|
+
for (const raw of (isTruthy(files) ? files : [])) {
|
|
771
|
+
const rel = stripWhitespace(formatValue(raw).replace(/\\/g, '/')).replace(/^\/+/, '');
|
|
772
|
+
const dst = resolvePath(path.join(target, rel));
|
|
773
|
+
const src = resolvePath(path.join(expected, rel));
|
|
775
774
|
if (!rel || !within(dst, target) || !within(src, expected)) {
|
|
776
775
|
errors.push(`${rel}: outside the deployed tree`);
|
|
777
776
|
} else if (isFile(src)) {
|
|
@@ -817,7 +816,7 @@ const EMIT_FOR = new Map([
|
|
|
817
816
|
* `{cmd: [...]}` IS A RETURN TYPE, NOT A RESPONSE. `_post_routes` hands it straight to the job
|
|
818
817
|
* runner in the same process; it never reaches the wire. That is what collapsed P6f's
|
|
819
818
|
* "argv-in-a-response-body" question — see this file's header — and why the twin's head is
|
|
820
|
-
* `process.execPath` + `bin/
|
|
819
|
+
* `process.execPath` + `bin/build-driver.mjs` rather than a Python argv it would then have to
|
|
821
820
|
* pretend to run.
|
|
822
821
|
*/
|
|
823
822
|
export function apiInstallCmd(state, body) {
|
|
@@ -861,7 +860,7 @@ export function apiInstallCmd(state, body) {
|
|
|
861
860
|
const out = scope === 'global' ? null : String(root);
|
|
862
861
|
const argv = setupBuildArgs(theme || 'neutral', emit, out, out, fp, pos, mode, doctrines,
|
|
863
862
|
PACK_ORDER, excludeRules);
|
|
864
|
-
return { cmd: [process.execPath, path.join(ROOT, 'bin', '
|
|
863
|
+
return { cmd: [process.execPath, path.join(ROOT, 'bin', 'build-driver.mjs'), ...argv] };
|
|
865
864
|
}
|
|
866
865
|
|
|
867
866
|
/**
|
|
@@ -882,7 +881,7 @@ export function apiInstallCmd(state, body) {
|
|
|
882
881
|
* and this endpoint moves and deletes whole trees, so the root is never built from raw body
|
|
883
882
|
* input. An unknown pair is a `NotFound`, which the shell answers 404.
|
|
884
883
|
*
|
|
885
|
-
* THE ENGINE IS `js/uninstall.mjs`'s, and P6i is what brought it. `installDeactivate` /
|
|
884
|
+
* THE ENGINE IS `js/maintain/uninstall.mjs`'s, and P6i is what brought it. `installDeactivate` /
|
|
886
885
|
* `installReactivate` are the reversible siblings of `installUninstall` — the same owned-file
|
|
887
886
|
* walk and ancestor prune with `move` where the reversal has `unlink` — which is why they live
|
|
888
887
|
* beside it rather than in the web tree. `remove` is `installUninstall`, which crossed in P5h
|
|
@@ -909,26 +908,26 @@ export function apiInstallToggle(state, body) {
|
|
|
909
908
|
// is validated IN THE ENGINE — an unknown value falls back to `keep`, never a surprise
|
|
910
909
|
// delete, which is why a bogus body value is passed through rather than rejected here.
|
|
911
910
|
const mem = bget(body, 'memory');
|
|
912
|
-
res = installUninstall(root, host, scope,
|
|
911
|
+
res = installUninstall(root, host, scope, isTruthy(mem) ? mem : 'keep');
|
|
913
912
|
} else {
|
|
914
913
|
// `{action!r}` — Python's repr, SINGLE-quoted. `JSON.stringify` would double-quote it
|
|
915
914
|
// inside a JSON string body and the two sides would differ on every typo.
|
|
916
|
-
res = { ok: false, error: `unknown action ${
|
|
915
|
+
res = { ok: false, error: `unknown action ${formatRepr(action)}` };
|
|
917
916
|
}
|
|
918
917
|
state.refresh();
|
|
919
918
|
return res;
|
|
920
919
|
}
|
|
921
920
|
|
|
922
921
|
export function apiDeployCmd(state, body) {
|
|
923
|
-
const host =
|
|
922
|
+
const host = stripWhitespace(strOr(bget(body, 'host')));
|
|
924
923
|
if (!HOSTS.some((h) => h.host === host)) {
|
|
925
924
|
return { error: `unknown host: ${host || '(none)'}` };
|
|
926
925
|
}
|
|
927
|
-
const raw =
|
|
926
|
+
const raw = stripWhitespace(strOr(bget(body, 'path')));
|
|
928
927
|
if (!raw) return { error: 'no folder given' };
|
|
929
928
|
let root;
|
|
930
929
|
try {
|
|
931
|
-
root =
|
|
930
|
+
root = resolvePath(expanduser(raw));
|
|
932
931
|
} catch {
|
|
933
932
|
return { error: `bad path: ${raw}` };
|
|
934
933
|
}
|
|
@@ -941,7 +940,7 @@ export function apiDeployCmd(state, body) {
|
|
|
941
940
|
const cfgdirs = new Set();
|
|
942
941
|
for (const fn of [opencodeConfigDir, claudeConfigDir, bobConfigDir, copilotConfigDir]) {
|
|
943
942
|
try {
|
|
944
|
-
cfgdirs.add(
|
|
943
|
+
cfgdirs.add(resolvePath(fn()));
|
|
945
944
|
} catch { /* the reference's bare `except: pass` */ }
|
|
946
945
|
}
|
|
947
946
|
if (cfgdirs.has(root)) {
|
|
@@ -967,5 +966,5 @@ export function apiDeployCmd(state, body) {
|
|
|
967
966
|
// project-scope emit name == host name (opencode / claude / bob / copilot)
|
|
968
967
|
const argv = setupBuildArgs(theme || 'neutral', host, root, root, fp, pos, mode, doctrines,
|
|
969
968
|
PACK_ORDER, excludeRules);
|
|
970
|
-
return { cmd: [process.execPath, path.join(ROOT, 'bin', '
|
|
969
|
+
return { cmd: [process.execPath, path.join(ROOT, 'bin', 'build-driver.mjs'), ...argv] };
|
|
971
970
|
}
|
package/js/web/activity.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* The live-activity surface — the one web endpoint that
|
|
3
3
|
* DELETES.
|
|
4
4
|
*
|
|
5
5
|
* It reads the per-session JSON files the `geneseed-activity` OpenCode plugin writes into
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* directory self-cleans), and returns what is left. Writer and reader share only that
|
|
8
8
|
* directory: no RPC, crash-isolated, and cross-tool by construction.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
* `
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* BOTH VERBS CROSS. `/api/activity` answers a GET through `apiActivity` and a POST through
|
|
11
|
+
* `apiActivityToggle` at the bottom of this file; `NOT_PORTED_POST` is empty and still
|
|
12
|
+
* declared. It is also the one POST route whose result is sent at 200 whatever `ok` says,
|
|
13
|
+
* which is why `POST_ROUTES` in `js/web/routes.mjs` carries a 409 COLUMN rather than a rule —
|
|
14
|
+
* and giving this row the 409 treatment is mutation M22.
|
|
15
15
|
*
|
|
16
16
|
* THE PLAN GUESSED `tasklist` AND THE SOURCE SAYS OTHERWISE. `_win_pid_alive` shells
|
|
17
17
|
* nothing: it goes through `ctypes` to `OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION)` and
|
|
@@ -33,16 +33,17 @@
|
|
|
33
33
|
* a third party and carry `cost` — a float. Python's `json.loads` types `1.0` a float and
|
|
34
34
|
* `json.dumps` writes it back `1.0`; `JSON.parse` gives a bare `1` that `bareInts` then
|
|
35
35
|
* renders `1`. `parseJson`'s wrapper is the only thing that survives the round trip, and
|
|
36
|
-
* `s-live`'s `"cost": 1.0` is the cell that says so. Its companion is `
|
|
36
|
+
* `s-live`'s `"cost": 1.0` is the cell that says so. Its companion is `isTruthy`: an
|
|
37
37
|
* `entry.get("cost") or 0` over a wrapper object is TRUE for a wrapped zero, where Python's
|
|
38
38
|
* `0.0 or 0` is the int `0` — so `s-older`'s `"cost": 0.0` must come back `0` and not `0.0`.
|
|
39
39
|
*/
|
|
40
40
|
import { mkdirSync, readdirSync, statSync, unlinkSync } from 'node:fs';
|
|
41
41
|
import path from 'node:path';
|
|
42
42
|
|
|
43
|
-
import {
|
|
44
|
-
|
|
45
|
-
} from '../lib/
|
|
43
|
+
import { readText, writeText } from '../lib/fs.mjs';
|
|
44
|
+
import { parseJson, isTruthy } from '../lib/json.mjs';
|
|
45
|
+
import { normcase } from '../lib/paths.mjs';
|
|
46
|
+
import { parseIntStrict, stripWhitespace } from '../lib/text.mjs';
|
|
46
47
|
import { NotFound } from './api.mjs';
|
|
47
48
|
|
|
48
49
|
/**
|
|
@@ -86,7 +87,7 @@ export function activityEnabled(state) {
|
|
|
86
87
|
} catch {
|
|
87
88
|
return true;
|
|
88
89
|
}
|
|
89
|
-
return !['off', '0', 'false', 'no'].includes(
|
|
90
|
+
return !['off', '0', 'false', 'no'].includes(stripWhitespace(raw).toLowerCase());
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
/**
|
|
@@ -99,10 +100,10 @@ export function activityEnabled(state) {
|
|
|
99
100
|
* what `int({})` and `int([])` raising looks like from here. `int(1.9)` truncates and
|
|
100
101
|
* `int(True)` is 1, both of which a hand-edited snapshot can produce.
|
|
101
102
|
*/
|
|
102
|
-
function
|
|
103
|
+
function toIntOr(raw) {
|
|
103
104
|
if (raw === true) return 1;
|
|
104
105
|
if (raw === false) return 0;
|
|
105
|
-
if (typeof raw === 'string') return
|
|
106
|
+
if (typeof raw === 'string') return parseIntStrict(stripWhitespace(raw));
|
|
106
107
|
const n = (raw !== null && typeof raw === 'object' && !Array.isArray(raw))
|
|
107
108
|
? raw.valueOf() : raw;
|
|
108
109
|
if (typeof n !== 'number' || !Number.isFinite(n)) return null;
|
|
@@ -111,7 +112,7 @@ function pyIntOf(raw) {
|
|
|
111
112
|
|
|
112
113
|
/** `_pid_alive` — best-effort liveness for the writer process. See this file's header. */
|
|
113
114
|
export function pidAlive(raw) {
|
|
114
|
-
const pid =
|
|
115
|
+
const pid = toIntOr(raw);
|
|
115
116
|
if (pid === null || pid <= 0) return false;
|
|
116
117
|
try {
|
|
117
118
|
process.kill(pid, 0);
|
|
@@ -131,7 +132,7 @@ export function pidAlive(raw) {
|
|
|
131
132
|
*/
|
|
132
133
|
function normalizeEntry(entry, stem) {
|
|
133
134
|
const g = (k) => (Object.hasOwn(entry, k) ? entry[k] : null);
|
|
134
|
-
const or = (k, dflt) => (
|
|
135
|
+
const or = (k, dflt) => (isTruthy(g(k)) ? g(k) : dflt);
|
|
135
136
|
return {
|
|
136
137
|
session_id: or('session_id', stem),
|
|
137
138
|
agent: g('agent'),
|
|
@@ -164,7 +165,7 @@ function readEntry(p) {
|
|
|
164
165
|
|
|
165
166
|
/** `_is_live` — the writer's pid is alive AND the snapshot is not stale. */
|
|
166
167
|
function isLive(entry, now) {
|
|
167
|
-
const updated =
|
|
168
|
+
const updated = isTruthy(Object.hasOwn(entry, 'updated_at') ? entry.updated_at : null)
|
|
168
169
|
? entry.updated_at : 0;
|
|
169
170
|
return (now - Number(updated)) <= ACTIVITY_STALE_SECONDS && pidAlive(
|
|
170
171
|
Object.hasOwn(entry, 'pid') ? entry.pid : null);
|
|
@@ -236,7 +237,7 @@ export function apiActivityDetail(state, sid) {
|
|
|
236
237
|
let timeline = [];
|
|
237
238
|
let full = {};
|
|
238
239
|
const det = readEntry(path.join(d, `${stem}.detail.json`));
|
|
239
|
-
if (
|
|
240
|
+
if (isTruthy(det)) {
|
|
240
241
|
const tl = Object.hasOwn(det, 'timeline') ? det.timeline : null;
|
|
241
242
|
timeline = Array.isArray(tl) ? tl : [];
|
|
242
243
|
full = det;
|
|
@@ -245,14 +246,14 @@ export function apiActivityDetail(state, sid) {
|
|
|
245
246
|
// The detail file carries the uncapped lists; fall back to the snapshot's capped ones.
|
|
246
247
|
// Assigning over an existing key keeps its POSITION in both languages, which is what lets
|
|
247
248
|
// the response stay byte-comparable.
|
|
248
|
-
session.files =
|
|
249
|
-
session.todos =
|
|
249
|
+
session.files = isTruthy(fg('files')) ? fg('files') : session.files;
|
|
250
|
+
session.todos = isTruthy(fg('todos')) ? fg('todos') : session.todos;
|
|
250
251
|
// The compact transcript: an ordered list of {role, text, t} turns. Empty falls back to
|
|
251
252
|
// the title as the opening user turn, because OpenCode derives the title from the first
|
|
252
253
|
// prompt.
|
|
253
254
|
const conv = fg('conversation');
|
|
254
255
|
let conversation = Array.isArray(conv) ? conv : [];
|
|
255
|
-
if (conversation.length === 0 &&
|
|
256
|
+
if (conversation.length === 0 && isTruthy(session.title)) {
|
|
256
257
|
conversation = [{ role: 'user', text: session.title }];
|
|
257
258
|
}
|
|
258
259
|
return { session, timeline, conversation };
|
|
@@ -272,7 +273,7 @@ export function apiActivityDetail(state, sid) {
|
|
|
272
273
|
*/
|
|
273
274
|
export function apiActivityToggle(state, body) {
|
|
274
275
|
const raw = (body && Object.hasOwn(body, 'enabled')) ? body.enabled : true;
|
|
275
|
-
const enabled =
|
|
276
|
+
const enabled = isTruthy(raw);
|
|
276
277
|
const p = activityFlag(state);
|
|
277
278
|
try {
|
|
278
279
|
mkdirSync(path.dirname(p), { recursive: true });
|