@tiens.nguyen/gu-cli 1.0.930 → 1.0.932

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/gu-cli.mjs CHANGED
@@ -14,12 +14,14 @@
14
14
  import { localModeNodeProblem, requireSupportedNode } from "./node-version.mjs";
15
15
  // The brand accent, shared with the REPL — see accent.mjs.
16
16
  import { accent } from "./accent.mjs";
17
+ import { installInternalLabel } from "./cli-token.mjs";
18
+ installInternalLabel(); // our own machines only (GU_INTERNAL_LABEL / ~/.gonext/internal-label)
17
19
  import { paint } from "./theme.mjs";
18
20
  requireSupportedNode();
19
21
  import { mkdir, mkdtemp, readFile, rm, stat, unlink, writeFile } from "node:fs/promises";
20
22
  import { execFile as execFileCallback, spawn } from "node:child_process";
21
23
  import { createHash, randomUUID } from "node:crypto";
22
- import { writeFileSync, unlinkSync } from "node:fs";
24
+ import { readFileSync, writeFileSync, unlinkSync } from "node:fs";
23
25
  import { createTaskPool, createFolderQueue } from "./job-pools.mjs";
24
26
  import { NO_STEP, foldStepTokens, withStepTokens, NO_CACHE, foldTurnCache, withTurnCache } from "./step-tokens.mjs";
25
27
  import { agentStoppedLine, jobEnded, jobStatusFrom409, stopGracefully } from "./agent-stop.mjs";
@@ -42,6 +44,7 @@ import { MINIMAL_RUN_LOGS, agentLogProfile, currentLevel, installLevelFilter, le
42
44
  import { skillsForTurn } from "./skills.mjs";
43
45
  import { mcpForTurn } from "./mcp-config.mjs";
44
46
  import { hooksForTurn, sessionForTurn } from "./hooks-config.mjs";
47
+ import { allLanguages, lspExtensions, lspStatePath, readLspState } from "./lsp-registry.mjs";
45
48
 
46
49
  /** The `skills` / `mcp` fields of one job's agent config (task #269). A broken config is a log
47
50
  * line, never a failed turn — the turn runs without them. */
@@ -750,7 +753,10 @@ const currentApiVersion = async () => {
750
753
  // /api/health answers without touching MongoDB, so this line said "up" on a machine whose
751
754
  // mongod was gone while every real request timed out. The handshake is the live check.
752
755
  let mongoDown = "";
753
- if (probe.ok) {
756
+ // gudb (GH #534) has no MongoDB to ask: on a computer without one the probe would report
757
+ // "MongoDB is NOT answering" about a database the API never uses (GH #557 follow-up).
758
+ const onGudb = probe.body?.storage === "gudb" || ce.readLocalDb() === "gudb";
759
+ if (probe.ok && !onGudb) {
754
760
  try {
755
761
  const { localMongoDown } = await import("./client-expert-run.mjs");
756
762
  mongoDown = await localMongoDown(ce.localMongoUri());
@@ -761,7 +767,7 @@ const currentApiVersion = async () => {
761
767
  ? `\n API is running on ${ce.LOCAL_API_BASE}` + (running ? ` (${running})` : "") +
762
768
  `, but MongoDB is NOT answering at ${mongoDown}\n — every request will hang until it does. Run \`gu\`: it says how to start it.`
763
769
  : probe.ok
764
- ? `\n API is up on ${ce.LOCAL_API_BASE} (mongo, persistence on)` +
770
+ ? `\n API is up on ${ce.LOCAL_API_BASE} (${probe.body?.storage === "gudb" ? `built-in database: ${ce.gudbFile()}` : "mongo"}, persistence on)` +
765
771
  (running ? ` — running ${running}` : "")
766
772
  : `\n API is not usable: ${probe.why}\n Log: ${ce.API_LOG_FILE}`
767
773
  );
@@ -1248,7 +1254,7 @@ if (args[0] === "fix-powershell") {
1248
1254
  // stops the profile loading — the same "said Done, changed nothing" mistake one branch along.
1249
1255
  const blockedBy = () => {
1250
1256
  try {
1251
- return pa.profileBlockedBy(runPs(host, "Get-ExecutionPolicy"));
1257
+ return pa.profileBlockedBy(runPs(host, pa.SAVED_POLICY_EXPR)); // not this process's override
1252
1258
  } catch {
1253
1259
  return "";
1254
1260
  }
@@ -1332,7 +1338,10 @@ if (args[0] === "clear" || args[0] === "reset") {
1332
1338
  // Client Expert keeps everything in a local database, which is state this command has to
1333
1339
  // account for — see localDatabaseItem.
1334
1340
  const { readdir: _readdir } = await import("node:fs/promises");
1335
- const dbItem = cs.localDatabaseItem({ apiBase: process.env.GONEXT_API_BASE ?? "" });
1341
+ const dbItem = cs.localDatabaseItem({
1342
+ apiBase: process.env.GONEXT_API_BASE ?? "",
1343
+ localDb: (await import("./client-expert-api.mjs")).readLocalDb(),
1344
+ });
1336
1345
  let apiDirForDrop = "";
1337
1346
  if (dbItem) {
1338
1347
  const base = join(homedir(), ".gonext", "api");
@@ -2033,7 +2042,7 @@ if (args[0] === "doctor") {
2033
2042
  // NOW Mongo matters, and it goes first: the API waits on it without a timeout of its
2034
2043
  // own, so starting the API against a dead database produces exactly the "listening but
2035
2044
  // never answers" state that sends people here.
2036
- const mongo = await run.probeMongo();
2045
+ const mongo = ce.readLocalDb() === "gudb" ? { running: true, how: `built in: ${ce.gudbFile()}` } : await run.probeMongo();
2037
2046
  if (mongo.running) {
2038
2047
  console.log(` · MongoDB is running (${mongo.how}), so the API is the problem.`);
2039
2048
  } else {
@@ -3989,6 +3998,32 @@ function _runBetweenTurnsIndex({ python, pythonArgs, scriptPath, input, jobActiv
3989
3998
  console.log(`[gu-worker] between-turns index started for ${jobActiveWorkspace}`);
3990
3999
  }
3991
4000
 
4001
+ // GH #540: the language-server host, started the first time a terminal turn needs it and kept for
4002
+ // the life of this worker — servers are slow to start, turns are short. See lsp-host.mjs.
4003
+ let _lspHost = null;
4004
+ function getLspHost() {
4005
+ if (!_lspHost) {
4006
+ _lspHost = import("./lsp-host.mjs")
4007
+ .then((m) => m.serveLspHost({ home: homedir(), log: (s) => console.log(`[gu-worker] ${s}`) }))
4008
+ .catch((e) => {
4009
+ console.log(`[gu-worker] [lsp] host not started: ${e?.message || e}`);
4010
+ _lspHost = null;
4011
+ return null;
4012
+ });
4013
+ }
4014
+ return _lspHost;
4015
+ }
4016
+
4017
+ /** The languages the user turned on — the agent's `lsp` tool is offered only when there is one (GH #541). */
4018
+ function lspLanguagesOn() {
4019
+ try {
4020
+ const st = readLspState(readFileSync(lspStatePath(homedir()), "utf8"));
4021
+ return Object.entries(st.languages).filter(([, v]) => v === "on").map(([k]) => k);
4022
+ } catch {
4023
+ return [];
4024
+ }
4025
+ }
4026
+
3992
4027
  async function runAgentChatJob(job) {
3993
4028
  const { jobId, payload } = job;
3994
4029
  const start = Date.now();
@@ -4290,6 +4325,11 @@ async function runAgentChatJob(job) {
4290
4325
  // REPL's "I can show a picker" signal (else python keeps hard-blocking, as on web).
4291
4326
  jobId,
4292
4327
  interactiveApproval: payload?.interactiveApproval === true,
4328
+ // GH #540: where the agent asks for a file's errors after an edit — only for a terminal turn
4329
+ // whose folder is on THIS computer (a language server reads the project from disk).
4330
+ lsp: terminalActiveWs && wsExistsHere
4331
+ ? await getLspHost().then((h) => (h ? { url: h.url, token: h.token, exts: lspExtensions(allLanguages({ home: homedir(), workspace: terminalActiveWs })), on: lspLanguagesOn() } : null))
4332
+ : null,
4293
4333
  // "accept edits" (task #179). Absent ⇒ true: only the terminal sends it, and only when
4294
4334
  // the user has turned it OFF, so every other caller keeps today's behaviour.
4295
4335
  acceptEdits: payload?.acceptEdits !== false,