@tiens.nguyen/gu-cli 1.0.901 → 1.0.902
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/coding-provider-setup.mjs +17 -0
- package/gu-repl.mjs +55 -12
- package/gu_mcp.py +13 -1
- package/model-doctor.mjs +15 -5
- package/package.json +4 -2
- package/skills/core/gu-session-memory-orchestration/SKILL.md +55 -0
- package/skills.mjs +47 -6
|
@@ -449,6 +449,23 @@ export const MAX_BACKENDS = 8;
|
|
|
449
449
|
* MAX_MODELS_PER_SERVER in api/src/store/settingsTypes.ts, which refuses a row that grows past it. */
|
|
450
450
|
export const MAX_MODELS_PER_SERVER = 3;
|
|
451
451
|
|
|
452
|
+
/** The models one saved server row offers, its main (default) model first, no repeats (GH #412). */
|
|
453
|
+
export function rowModels(row) {
|
|
454
|
+
const all = [row?.defaultModel, ...(Array.isArray(row?.models) ? row.models : [])];
|
|
455
|
+
return [...new Set(all.map((m) => String(m ?? "").trim()).filter(Boolean))];
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* The row with `model` in place of `drop` (GH #412): a server already offering
|
|
460
|
+
* MAX_MODELS_PER_SERVER models cannot grow, so a new pick takes a slot. Replacing the main model
|
|
461
|
+
* makes the new pick the main one. Pure — the caller saves it.
|
|
462
|
+
*/
|
|
463
|
+
export function replaceRowModel(row, drop, model) {
|
|
464
|
+
const extras = (Array.isArray(row?.models) ? row.models : []).filter((m) => m !== model);
|
|
465
|
+
if (String(row?.defaultModel ?? "").trim() === drop) return { ...row, defaultModel: model, models: extras.filter((m) => m !== drop) };
|
|
466
|
+
return { ...row, models: extras.map((m) => (m === drop ? model : m)) };
|
|
467
|
+
}
|
|
468
|
+
|
|
452
469
|
/**
|
|
453
470
|
* The backend rows an account ALREADY has, in the shape a save must preserve.
|
|
454
471
|
*
|
package/gu-repl.mjs
CHANGED
|
@@ -1672,11 +1672,15 @@ function applyMouseReport(report) {
|
|
|
1672
1672
|
* making, and a press that turns out to be a drag spends none of them.
|
|
1673
1673
|
*/
|
|
1674
1674
|
function applyClick({ row, col }) {
|
|
1675
|
-
// Scrolled back:
|
|
1676
|
-
//
|
|
1675
|
+
// Scrolled back: a click on the jump affordance brings the view home; a click on a thought or
|
|
1676
|
+
// look-up group opens/closes it IN PLACE (GH #195 — a long answer pushes the thought off the
|
|
1677
|
+
// screen, the reader scrolls up to its "(+19 more — click to expand)", and the click used to be
|
|
1678
|
+
// swallowed here); anywhere else, with no jump affordance showing, also goes home as before.
|
|
1677
1679
|
if (scrolledBack()) {
|
|
1678
1680
|
const t = jumpRowTarget;
|
|
1679
|
-
if (
|
|
1681
|
+
if (t && row === t.row) jumpToBottom();
|
|
1682
|
+
else if (toggleThoughtAtRow(row)) return;
|
|
1683
|
+
else if (!t) jumpToBottom();
|
|
1680
1684
|
return;
|
|
1681
1685
|
}
|
|
1682
1686
|
// The update control (task #181), if it is showing and the click landed ON it. Checked by
|
|
@@ -4227,6 +4231,7 @@ function hoverThoughtAtRow(row) {
|
|
|
4227
4231
|
/** Swap one recorded block for its other form and repaint from the transcript. */
|
|
4228
4232
|
function toggleThoughtBlock(block) {
|
|
4229
4233
|
const painted = paintThoughtRows(block, false, !block.collapsed);
|
|
4234
|
+
const rowsBefore = screenRows().length;
|
|
4230
4235
|
const newEnd = transcript.replaceRange(block.from, block.to, painted);
|
|
4231
4236
|
if (newEnd === null) {
|
|
4232
4237
|
// Scrolled out of the buffer — the block is gone, and so is the thing to toggle.
|
|
@@ -4237,7 +4242,10 @@ function toggleThoughtBlock(block) {
|
|
|
4237
4242
|
// that arithmetic lives so a test can run it against real thoughts.
|
|
4238
4243
|
applyToggleShift(thoughtBlocks, block, newEnd);
|
|
4239
4244
|
hoverCtl.reset(); // the rows moved under the pointer — re-resolve on the next report
|
|
4240
|
-
paintLiveTail()
|
|
4245
|
+
// At the live tail this is paintLiveTail, as before. Scrolled back (GH #195), it keeps the same
|
|
4246
|
+
// lines at the top of the view so the block opens under the pointer instead of the view
|
|
4247
|
+
// jumping to the bottom.
|
|
4248
|
+
repaintTailOrHoldView(rowsBefore);
|
|
4241
4249
|
// #204: the Yes/No rows are in-place UI, not transcript — the repaint above wiped them, so the
|
|
4242
4250
|
// open picker draws them again right under the (re-sized) command block.
|
|
4243
4251
|
if (approvalActive) drawApprovalOptions(false);
|
|
@@ -7451,17 +7459,46 @@ async function pickModelOnCoderServer(active, def) {
|
|
|
7451
7459
|
}
|
|
7452
7460
|
const row = rows.find((b) => (b.id ?? b.kind) === p.id);
|
|
7453
7461
|
const extras = Array.isArray(row?.models) ? row.models : [];
|
|
7462
|
+
let replacedActive = false; // the swap removed the very model this session is on (GH #412)
|
|
7454
7463
|
if (model !== p.model && !extras.includes(model)) {
|
|
7464
|
+
let nextRow = { ...row, models: [...extras, model] };
|
|
7465
|
+
let dropped = "";
|
|
7466
|
+
// GH #412: a server keeps at most MAX_MODELS_PER_SERVER models (the API refuses a 4th), so a
|
|
7467
|
+
// full one cannot just grow — every pick here failed with "couldn't save that". Ask which
|
|
7468
|
+
// saved extra the new pick replaces. The main model is never offered: it may be the account
|
|
7469
|
+
// default other settings point at.
|
|
7470
|
+
if (row && ps.rowModels(row).length >= ps.MAX_MODELS_PER_SERVER) {
|
|
7471
|
+
const swappable = extras.filter((m) => String(m).trim() && m !== p.model);
|
|
7472
|
+
if (!swappable.length) {
|
|
7473
|
+
console.log(yellow(` ${p.host} already offers ${ps.MAX_MODELS_PER_SERVER} models — remove one in /model → manage providers first.\n`));
|
|
7474
|
+
return;
|
|
7475
|
+
}
|
|
7476
|
+
// Two short lines, not one: a wrapped row breaks the picker's erase (and 80 columns is common).
|
|
7477
|
+
console.log(dim(` ${p.host} keeps ${ps.MAX_MODELS_PER_SERVER} models (main: ${p.model}).`));
|
|
7478
|
+
console.log(dim(` Which one should ${model} replace?`));
|
|
7479
|
+
// Default to a model that is NOT the one in use, so Enter keeps the current coder's slot.
|
|
7480
|
+
const first = Math.max(0, swappable.findIndex((m) => m !== active.model));
|
|
7481
|
+
const idx = await pickFromList(swappable, first);
|
|
7482
|
+
if (idx < 0) {
|
|
7483
|
+
console.log(dim(" (nothing changed)\n"));
|
|
7484
|
+
return;
|
|
7485
|
+
}
|
|
7486
|
+
dropped = swappable[idx];
|
|
7487
|
+
nextRow = ps.replaceRowModel(row, dropped, model);
|
|
7488
|
+
}
|
|
7455
7489
|
const md = await import("./model-doctor.mjs");
|
|
7456
|
-
const
|
|
7457
|
-
md.
|
|
7458
|
-
agentCodingBackends: rows.map((b) => ((b.id ?? b.kind) === p.id ?
|
|
7490
|
+
const result = await withPendingStatus("saving", () =>
|
|
7491
|
+
md.saveWorkerSettingsDetailed(apiBase, workerKey, {
|
|
7492
|
+
agentCodingBackends: rows.map((b) => ((b.id ?? b.kind) === p.id ? nextRow : b)),
|
|
7459
7493
|
})
|
|
7460
7494
|
);
|
|
7461
|
-
if (!
|
|
7462
|
-
|
|
7495
|
+
if (!result.ok) {
|
|
7496
|
+
// The API's own reason, when it gave one — "couldn't save that" alone hid the cap (GH #412).
|
|
7497
|
+
console.log(red(` couldn't save that${result.error ? ` (${result.error})` : ""} — nothing changed.\n`));
|
|
7463
7498
|
return;
|
|
7464
|
-
}
|
|
7499
|
+
} // Say what the swap did — the ✓ line below only names the model now in use (GH #412).
|
|
7500
|
+
if (dropped) console.log(dim(` ${model} replaced ${dropped} on ${p.host}.`));
|
|
7501
|
+
replacedActive = dropped !== "" && dropped === active.model;
|
|
7465
7502
|
}
|
|
7466
7503
|
// The choice as the API now lists it — its id is the API's to make, not this side's.
|
|
7467
7504
|
const probe = await withPendingStatus("loading models", () => fetchAgentPayload([{ role: "user", content: "ping" }])).catch(() => null);
|
|
@@ -7470,6 +7507,8 @@ async function pickModelOnCoderServer(active, def) {
|
|
|
7470
7507
|
);
|
|
7471
7508
|
if (!chosen) {
|
|
7472
7509
|
console.log(accent(` ✓ ${model} added to ${p.host}`) + dim(" · pick it in /model\n"));
|
|
7510
|
+
// The model in use was just taken off the list: say so, or the next turn runs on a coder that is gone.
|
|
7511
|
+
if (replacedActive) console.log(yellow(` ${active.model} was replaced — pick a model in /model now.\n`));
|
|
7473
7512
|
return;
|
|
7474
7513
|
}
|
|
7475
7514
|
await applyChosenCoder(chosen, { def: String(probe?.codingDefault ?? def ?? "").trim() });
|
|
@@ -11510,6 +11549,8 @@ const MCPTOOL_PREFIX = "__MCPTOOL__::";
|
|
|
11510
11549
|
// The agent's first use of the browser in a turn (#150): "<folder>\t<what it is about to do>".
|
|
11511
11550
|
// "Always" puts the folder on ~/.gonext/browser-allow.json, which the agent reads before asking.
|
|
11512
11551
|
const BROWSER_PREFIX = "__BROWSER__::";
|
|
11552
|
+
// How long the browser question waits before "Yes, this time" (GH #411).
|
|
11553
|
+
const BROWSER_APPROVAL_MS = 10_000;
|
|
11513
11554
|
async function approvalPrompt(command) {
|
|
11514
11555
|
// Wipe the live "thinking" status block BEFORE any picker draws, and stop the ticker from
|
|
11515
11556
|
// redrawing it (the tick early-returns while a picker is active) — otherwise the block
|
|
@@ -11571,14 +11612,16 @@ async function approvalPrompt(command) {
|
|
|
11571
11612
|
const [folder = "", what = ""] = command.slice(BROWSER_PREFIX.length).split("\t");
|
|
11572
11613
|
if (!process.stdin.isTTY) return { allow: false, dontAsk: false };
|
|
11573
11614
|
process.stdout.write(
|
|
11574
|
-
"\n" + yellow("🌐 Allow gu to use a web browser?") + dim(
|
|
11615
|
+
"\n" + yellow("🌐 Allow gu to use a web browser?") + dim(` (no answer in ${BROWSER_APPROVAL_MS / 1000}s = Yes, this time)`) + "\n" +
|
|
11575
11616
|
indentBlock(`It wants to: ${what || "open a page"}`, { indent: GUTTER, paint: dim }) + "\n" +
|
|
11576
11617
|
dim(" In your Chrome if the gu extension is there, else in gu's own Chrome window.") + "\n"
|
|
11577
11618
|
);
|
|
11578
11619
|
// "Yes, this time" is THE default (#380, GitHub #167): highlighted, so Enter allows it once, and
|
|
11579
11620
|
// also what an unanswered question becomes — the countdown used to sit on "No", which read as
|
|
11580
11621
|
// the default. Remembering the folder is never automatic; it takes an explicit choice.
|
|
11581
|
-
|
|
11622
|
+
// 10 s, not ~3 min (GH #411: "opening browser is not that serious"). Silence still means once
|
|
11623
|
+
// only — never the remembered "always".
|
|
11624
|
+
const idx = await pickFromList(["Yes, this time", "Yes, always in this folder", "No"], 0, { timeoutMs: BROWSER_APPROVAL_MS, timeoutIndex: 0 });
|
|
11582
11625
|
if (idx === 1) {
|
|
11583
11626
|
try {
|
|
11584
11627
|
allowIn(folder || resolve(process.cwd()), true);
|
package/gu_mcp.py
CHANGED
|
@@ -88,7 +88,8 @@ class StdioMcpClient:
|
|
|
88
88
|
except OSError as e:
|
|
89
89
|
raise McpError(f'could not start "{self.command}": {e.strerror or e}') from None
|
|
90
90
|
threading.Thread(target=self._read_stdout, daemon=True).start()
|
|
91
|
-
threading.Thread(target=self._read_stderr, daemon=True)
|
|
91
|
+
self._stderr_thread = threading.Thread(target=self._read_stderr, daemon=True)
|
|
92
|
+
self._stderr_thread.start()
|
|
92
93
|
|
|
93
94
|
def _read_stdout(self) -> None:
|
|
94
95
|
try:
|
|
@@ -147,6 +148,17 @@ class StdioMcpClient:
|
|
|
147
148
|
raise McpError(self._exit_reason()) from None
|
|
148
149
|
|
|
149
150
|
def _exit_reason(self) -> str:
|
|
151
|
+
# Called the moment the server's pipe closes: the child may not be reaped yet and its
|
|
152
|
+
# last stderr line may still be in flight. Give both a moment, or the message flips
|
|
153
|
+
# between "exited (code N)" and "stopped answering" from run to run (GH #410).
|
|
154
|
+
if self.proc:
|
|
155
|
+
try:
|
|
156
|
+
self.proc.wait(timeout=1.5)
|
|
157
|
+
except subprocess.TimeoutExpired:
|
|
158
|
+
pass
|
|
159
|
+
t = getattr(self, "_stderr_thread", None)
|
|
160
|
+
if t and self.proc.poll() is not None:
|
|
161
|
+
t.join(timeout=1.5)
|
|
150
162
|
code = self.proc.poll() if self.proc else None
|
|
151
163
|
tail = next((l for l in reversed(self._stderr_tail) if l.strip()), "")
|
|
152
164
|
why = f"the server exited (code {code})" if code is not None else "the server stopped answering"
|
package/model-doctor.mjs
CHANGED
|
@@ -581,8 +581,12 @@ export function resolveConfiguredModels(settings) {
|
|
|
581
581
|
* the CLI setup flow asks about. Returns true on success; never throws (a failed save must
|
|
582
582
|
* not abort setup — the model still gets served from the chosen folder this session).
|
|
583
583
|
*/
|
|
584
|
-
|
|
585
|
-
|
|
584
|
+
/**
|
|
585
|
+
* saveWorkerSettings, but with the API's reason when it refuses (GH #412): → { ok, error }.
|
|
586
|
+
* `error` is the body's `error` text on an HTTP failure, the network message on no answer.
|
|
587
|
+
*/
|
|
588
|
+
export async function saveWorkerSettingsDetailed(apiBase, workerKey, patch, { timeoutMs = 6000 } = {}) {
|
|
589
|
+
if (!apiBase || !workerKey || !patch || !Object.keys(patch).length) return { ok: false, error: "" };
|
|
586
590
|
try {
|
|
587
591
|
const res = await fetch(`${String(apiBase).replace(/\/+$/, "")}/api/worker/settings`, {
|
|
588
592
|
method: "POST",
|
|
@@ -590,12 +594,18 @@ export async function saveWorkerSettings(apiBase, workerKey, patch, { timeoutMs
|
|
|
590
594
|
body: JSON.stringify(patch),
|
|
591
595
|
signal: AbortSignal.timeout(timeoutMs),
|
|
592
596
|
});
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
return false;
|
|
597
|
+
if (res.ok) return { ok: true, error: "" };
|
|
598
|
+
const body = await res.json().catch(() => null);
|
|
599
|
+
return { ok: false, error: String(body?.error ?? `HTTP ${res.status}`).slice(0, 200) };
|
|
600
|
+
} catch (e) {
|
|
601
|
+
return { ok: false, error: String(e?.message ?? e).slice(0, 200) };
|
|
596
602
|
}
|
|
597
603
|
}
|
|
598
604
|
|
|
605
|
+
export async function saveWorkerSettings(apiBase, workerKey, patch, opts = {}) {
|
|
606
|
+
return (await saveWorkerSettingsDetailed(apiBase, workerKey, patch, opts)).ok;
|
|
607
|
+
}
|
|
608
|
+
|
|
599
609
|
/**
|
|
600
610
|
* Is an OpenAI-compatible model endpoint REACHABLE from this machine?
|
|
601
611
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiens.nguyen/gu-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.902",
|
|
4
4
|
"description": "gu: the coding agent in your terminal. It reads your repo, makes the change and runs the tests, with your own models (Ollama or any OpenAI-compatible provider). Free installs keep the agent, its API and its database on your machine. macOS, Linux and Windows.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
"test:skills": "python3 scripts/py-tap.py tests/test_skills_mcp_turn.py tests/test_hooks_turn.py tests/test_claude_hooks.py tests/test_mcp_client.py && node --test tests/skills.test.mjs tests/mcp-config.test.mjs tests/hooks-config.test.mjs tests/switch-skill.test.mjs tests/slash-menu.test.mjs tests/conversation-archive.test.mjs",
|
|
59
59
|
"capture:turn": "GONEXT_OLLAMA1_LIVE=1 node scripts/capture-turn-fixture.mjs",
|
|
60
60
|
"test:bearer": "node --test tests/bearer-routing.test.mjs tests/bearer-verify.test.mjs",
|
|
61
|
-
"test:bearer-e2e": "bash scripts/bearer-e2e.sh"
|
|
61
|
+
"test:bearer-e2e": "bash scripts/bearer-e2e.sh",
|
|
62
|
+
"test:pack": "node scripts/pack-smoke.mjs"
|
|
62
63
|
},
|
|
63
64
|
"files": [
|
|
64
65
|
"accent.mjs",
|
|
@@ -147,6 +148,7 @@
|
|
|
147
148
|
"install-path.mjs",
|
|
148
149
|
"update-verify.mjs",
|
|
149
150
|
"skills.mjs",
|
|
151
|
+
"skills/",
|
|
150
152
|
"skill-source.mjs",
|
|
151
153
|
"skills-copy.mjs",
|
|
152
154
|
"skill-package.mjs",
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: gu-session-memory-orchestration
|
|
3
|
+
description: Project memory shared by gu and Claude Code. Use when a "Resume" block or memory snapshot appears, when the user says continue or resume, and before a wide repository search.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Session memory
|
|
7
|
+
|
|
8
|
+
Hooks save your work as it happens, in both gu and Claude Code: each request, your plan, every
|
|
9
|
+
command with its result, every edit (scripted ones too), and whether the turn finished or was cut
|
|
10
|
+
off. **You do not save steps, edits or checkpoints yourself.** Your part is below.
|
|
11
|
+
|
|
12
|
+
## What you will see
|
|
13
|
+
|
|
14
|
+
- **`## Resume - task #N (tool, state time)`** at the start of a session, and again when the user
|
|
15
|
+
says "continue" or "resume": the latest unfinished work in this project, from either tool. It
|
|
16
|
+
lists the task, goal, plan (done, in progress, not started), last command and its result, files
|
|
17
|
+
touched, and the next step. `interrupted` = the turn was cut off; `unfinished` = still running
|
|
18
|
+
elsewhere or closed without finishing.
|
|
19
|
+
- **`## Memory snapshot`**: tasks in progress, requirements that match the request, recent edits.
|
|
20
|
+
|
|
21
|
+
## Rules
|
|
22
|
+
|
|
23
|
+
1. **Resume block.** If the request carries on that work, or the user says continue/resume, start
|
|
24
|
+
from **Next** (the first step not done) and say so in one line, e.g. *Continuing task #446 from
|
|
25
|
+
"gu commands".* Look at the files it lists before changing them, do not redo finished steps, and
|
|
26
|
+
if the last command failed, start by understanding why. If the request is about something else,
|
|
27
|
+
ignore the block and do not mention it.
|
|
28
|
+
2. **Keep a plan for work with three or more steps**, and update it as each step starts and
|
|
29
|
+
finishes; that plan is what a resume continues from. If you have a to-do tool, use it. If you do
|
|
30
|
+
not, call `save_progress` with the whole plan each time.
|
|
31
|
+
3. **Switching task?** Call `update_task` on the task you are moving to (status `in_progress`,
|
|
32
|
+
`process_state` = what you are about to do). A task named in the user's request (`#N`, `GH #N`)
|
|
33
|
+
is picked up without this.
|
|
34
|
+
4. **Memory before a wide search.** Before searching the whole repository, try
|
|
35
|
+
`find_requirements`, `search_code_changes` and `line_hints`, then open only the files they name.
|
|
36
|
+
Line numbers from memory are hints: check them before you quote them.
|
|
37
|
+
5. **Finished a task?** `update_task` with status `done` and a `next_action` for any follow-up.
|
|
38
|
+
|
|
39
|
+
## Tools (`local-memory-sqlite` MCP server)
|
|
40
|
+
|
|
41
|
+
| Need | Tool |
|
|
42
|
+
| --- | --- |
|
|
43
|
+
| The whole resume state: full plan, last commands, files | `resume_task` |
|
|
44
|
+
| Save your plan when you have no to-do tool | `save_progress` |
|
|
45
|
+
| Requirements and tasks | `find_requirements`, `search_tasks`, `get_task`, `list_tasks` |
|
|
46
|
+
| Create or move a task | `save_task`, `update_task` |
|
|
47
|
+
| Where something was changed or found before | `search_code_changes`, `recent_code_changes`, `line_hints`, `search_steps` |
|
|
48
|
+
|
|
49
|
+
If the MCP tools are not connected, say so in one line and carry on: the hooks still save the work.
|
|
50
|
+
|
|
51
|
+
## Good to know
|
|
52
|
+
|
|
53
|
+
- Memory lives in `.claude-memory/` at the project root (the git root), one database per project.
|
|
54
|
+
- Secrets are masked before they are stored, but do not write keys, tokens or passwords into a
|
|
55
|
+
plan, a task or a summary.
|
package/skills.mjs
CHANGED
|
@@ -27,13 +27,39 @@
|
|
|
27
27
|
*/
|
|
28
28
|
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
29
29
|
import { homedir } from "node:os";
|
|
30
|
-
import { join } from "node:path";
|
|
30
|
+
import { dirname, join } from "node:path";
|
|
31
|
+
import { fileURLToPath } from "node:url";
|
|
31
32
|
import { resolveSkillSource, sourceDirName } from "./skill-source.mjs";
|
|
32
33
|
|
|
33
34
|
export const SKILL_FILE = "SKILL.md";
|
|
34
35
|
/** Claude Code's rule: lowercase letters, digits and hyphens, at most 64. It is also a slash command. */
|
|
35
36
|
export const SKILL_NAME_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* CORE SKILLS (GH #344): skills that ship INSIDE the package, <package>/skills/core/<name>/SKILL.md.
|
|
40
|
+
* They are read from there on every scan and never copied into ~/.gonext/skills, so `npm i -g`
|
|
41
|
+
* is enough (no postinstall to fail under --ignore-scripts), an upgrade upgrades them, and
|
|
42
|
+
* `rm -rf ~/.gonext/skills` cannot remove them. They belong to gu, not to a skills folder, so they
|
|
43
|
+
* load whichever source /switch-skill chose.
|
|
44
|
+
*
|
|
45
|
+
* ORDER: project < core < yours. A personal skill with a core skill's name replaces it, visibly
|
|
46
|
+
* (`overrides: "core"`), except the LOCKED ones other features depend on.
|
|
47
|
+
*/
|
|
48
|
+
export function coreSkillsDir() {
|
|
49
|
+
return join(dirname(fileURLToPath(import.meta.url)), "skills", "core");
|
|
50
|
+
}
|
|
51
|
+
/** Core skills a personal skill may not replace: hooks and the resume flow rely on them. */
|
|
52
|
+
export const LOCKED_CORE_SKILLS = ["gu-session-memory-orchestration"];
|
|
53
|
+
|
|
54
|
+
/** The gu version the core skills ship with (package.json beside skills/), "" if unreadable. */
|
|
55
|
+
export function coreSkillsVersion(dir = coreSkillsDir()) {
|
|
56
|
+
try {
|
|
57
|
+
return String(JSON.parse(readFileSync(join(dir, "..", "..", "package.json"), "utf8")).version ?? "");
|
|
58
|
+
} catch {
|
|
59
|
+
return "";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
37
63
|
export function userSkillsDir(home = homedir(), source = "gu") {
|
|
38
64
|
return join(home, sourceDirName(source), "skills");
|
|
39
65
|
}
|
|
@@ -155,23 +181,38 @@ export const HIDDEN_SKILLS = ["gu-session-memory-orchestration"];
|
|
|
155
181
|
* `source` = whose skills ("gu" | "claude"); left out, it is the folder's own choice (/switch-skill).
|
|
156
182
|
* Only that source's skills are listed — the two are never mixed.
|
|
157
183
|
*
|
|
158
|
-
*
|
|
184
|
+
* `coreDir` = where the shipped skills are (default: the package's own); null/"" = none (tests).
|
|
185
|
+
*
|
|
186
|
+
* → { skills: [{ name, description, path, dir, scope, layer, slash, source, version?, overrides? }],
|
|
187
|
+
* warnings: string[], source }
|
|
159
188
|
*/
|
|
160
|
-
export function discoverSkills({ cwd = process.cwd(), home = homedir(), reserved = [], source } = {}) {
|
|
189
|
+
export function discoverSkills({ cwd = process.cwd(), home = homedir(), reserved = [], source, coreDir = coreSkillsDir() } = {}) {
|
|
161
190
|
const src = resolveSkillSource({ source, cwd, home });
|
|
162
191
|
const user = scanDir(userSkillsDir(home, src), "user");
|
|
163
192
|
const project =
|
|
164
193
|
cwd && projectSkillsDir(cwd, src) !== userSkillsDir(home, src)
|
|
165
194
|
? scanDir(projectSkillsDir(cwd, src), "project")
|
|
166
195
|
: { skills: [], warnings: [] };
|
|
196
|
+
const core = coreDir ? scanDir(coreDir, "core") : { skills: [], warnings: [] };
|
|
197
|
+
const version = core.skills.length ? coreSkillsVersion(coreDir) : "";
|
|
198
|
+
const warnings = [...user.warnings, ...project.warnings, ...core.warnings];
|
|
199
|
+
// project < core < yours.
|
|
167
200
|
const byName = new Map();
|
|
168
|
-
for (const s of
|
|
169
|
-
for (const s of
|
|
201
|
+
for (const s of project.skills) byName.set(s.name, { ...s, layer: "project" });
|
|
202
|
+
for (const s of core.skills) byName.set(s.name, { ...s, layer: "core", ...(version ? { version } : {}) });
|
|
203
|
+
for (const s of user.skills) {
|
|
204
|
+
const had = byName.get(s.name);
|
|
205
|
+
if (had?.layer === "core" && LOCKED_CORE_SKILLS.includes(s.name)) {
|
|
206
|
+
warnings.push(`user skill "${s.name}": the name belongs to a core skill that cannot be replaced — skipped`);
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
byName.set(s.name, { ...s, layer: "user", ...(had?.layer === "core" ? { overrides: "core", coreVersion: had.version } : {}) });
|
|
210
|
+
}
|
|
170
211
|
const taken = new Set(reserved.map((r) => r.replace(/^\//, "")));
|
|
171
212
|
const skills = [...byName.values()]
|
|
172
213
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
173
214
|
.map((s) => ({ ...s, slash: !taken.has(s.name), hidden: HIDDEN_SKILLS.includes(s.name), source: src }));
|
|
174
|
-
return { skills, warnings
|
|
215
|
+
return { skills, warnings, source: src };
|
|
175
216
|
}
|
|
176
217
|
|
|
177
218
|
/** What the worker hands the agent for one turn: enough to list them and to read one. */
|