piroboros 0.2.0 → 0.3.3

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/NOTICE +12 -0
  3. package/README.md +11 -8
  4. package/dist/chat/log.js +1 -1
  5. package/dist/chat/turn.js +0 -15
  6. package/dist/conclave/pipeline.js +216 -13
  7. package/dist/config.js +121 -12
  8. package/dist/diff.js +90 -0
  9. package/dist/durable.js +1 -1
  10. package/dist/guard.js +170 -14
  11. package/dist/learn.js +938 -0
  12. package/dist/memory/akashic/tools.js +25 -28
  13. package/dist/memory/mnemosia/conflicts.js +0 -4
  14. package/dist/memory/mnemosia/orchestrator.js +1 -11
  15. package/dist/memory/mnemosia/policy.js +0 -3
  16. package/dist/memory/mnemosia/rank.js +0 -4
  17. package/dist/memory/mnemosia/rerank.js +3 -30
  18. package/dist/memory/mnemosia/rollback.js +1 -149
  19. package/dist/memory/mnemosia/tokens.js +1 -11
  20. package/dist/memory/mnemosia/tools.js +0 -10
  21. package/dist/memory/mnemosia/types.js +0 -2
  22. package/dist/runtime.js +51 -6
  23. package/dist/search.js +25 -12
  24. package/dist/shell.js +2 -2
  25. package/dist/tui/app.js +15 -3
  26. package/dist/tui/commands.js +5 -2
  27. package/dist/tui/settings.js +4 -1
  28. package/dist/tui/thinking/parse.js +0 -3
  29. package/dist/ws/apply.js +833 -0
  30. package/dist/ws/cas.js +144 -0
  31. package/dist/ws/confine.js +220 -0
  32. package/dist/ws/docker.js +145 -0
  33. package/dist/ws/git.js +235 -0
  34. package/dist/ws/lww.js +48 -0
  35. package/dist/ws/merge.js +129 -0
  36. package/dist/ws/workspace.js +1736 -0
  37. package/dist/ws/wsl.js +247 -0
  38. package/docs/conclave.md +14 -0
  39. package/docs/configuration.md +10 -4
  40. package/docs/privacy.md +3 -1
  41. package/docs/tools.md +43 -1
  42. package/package.json +1 -2
  43. package/settings.json.example +3 -1
package/dist/search.js CHANGED
@@ -81,21 +81,31 @@ export async function probeSearch(options = {}) {
81
81
  export function createSearch(deps) {
82
82
  const rg = deps.rg ?? "rg";
83
83
  let fffPromise;
84
- let holder;
84
+ // Two indexes, least recently used first: the root's and Vesperia's Workspace, so alternating searches build each once.
85
+ let holders = [];
85
86
  let creating = Promise.resolve();
86
87
  const loadFff = () => (fffPromise ??= (deps.loadFff ?? (() => import("@ff-labs/fff-node")))());
87
88
  const allowed = (path, cwd) => checkPath(path, cwd, deps.guard()).allowed;
89
+ // Ignore files above a Workspace (and the global one) never describe the project, whose own rules already decided what was copied.
90
+ const wsFlags = (cwd) => (deps.inWorkspace?.(cwd) ? ["--no-ignore-parent", "--no-ignore-global"] : []);
91
+ const drop = (h) => { if (!h.finder.isDestroyed)
92
+ h.finder.destroy(); };
88
93
  const destroy = () => {
89
- if (holder !== undefined && !holder.finder.isDestroyed)
90
- holder.finder.destroy();
91
- holder = undefined;
94
+ for (const h of holders)
95
+ drop(h);
96
+ holders = [];
92
97
  };
93
- /** One index per working directory; a different directory replaces it. Creation is serialized. */
98
+ /** One index per working directory, at most two; the least recently used goes when a third is needed. Creation is serialized. */
94
99
  const finderFor = (cwd) => {
95
100
  const next = creating.then(async () => {
96
- if (holder !== undefined && holder.cwd === cwd && !holder.finder.isDestroyed)
97
- return holder;
98
- destroy();
101
+ const hit = holders.find((h) => h.cwd === cwd && !h.finder.isDestroyed);
102
+ if (hit !== undefined) {
103
+ holders = [...holders.filter((h) => h !== hit), hit];
104
+ return hit;
105
+ }
106
+ holders = holders.filter((h) => !h.finder.isDestroyed);
107
+ while (holders.length >= 2)
108
+ drop(holders.shift());
99
109
  const fff = await loadFff();
100
110
  const base = { basePath: cwd, aiMode: true, enableHomeDirScanning: false, enableFsRootScanning: false };
101
111
  mkdirSync(join(deps.home, "fff"), { recursive: true });
@@ -110,7 +120,10 @@ export function createSearch(deps) {
110
120
  made.value.destroy();
111
121
  throw new Error(waited.error);
112
122
  }
113
- return (holder = { cwd, finder: made.value, cursors: new Map() });
123
+ deps.holderBuilt?.(cwd);
124
+ const built = { cwd, finder: made.value, cursors: new Map() };
125
+ holders.push(built);
126
+ return built;
114
127
  });
115
128
  creating = next.catch(() => undefined);
116
129
  return next;
@@ -146,7 +159,7 @@ export function createSearch(deps) {
146
159
  return { text: notes.length > 0 ? `${formatted.output}\n\n[${notes.join(". ")}]` : formatted.output, backend: "fff", total: totalMatched, page };
147
160
  }
148
161
  async function findRg(cwd, query, constraint, page, reason) {
149
- const argv = ["--no-config", "--no-messages", "--no-require-git", "--files", "--sort", "path", "--glob", "!.git", ...(constraint === undefined ? [] : ["--glob", rgGlob(constraint)]), "--", "."];
162
+ const argv = ["--no-config", "--no-messages", "--no-require-git", ...wsFlags(cwd), "--files", "--sort", "path", "--glob", "!.git", ...(constraint === undefined ? [] : ["--glob", rgGlob(constraint)]), "--", "."];
150
163
  const words = query.toLowerCase().split(/\s+/u).filter((word) => word !== "");
151
164
  const hits = [];
152
165
  let run;
@@ -217,7 +230,7 @@ export function createSearch(deps) {
217
230
  }
218
231
  async function grepRg(cwd, a, reason) {
219
232
  const argv = [
220
- "--no-config", "--no-messages", "--no-require-git", "--json", "--smart-case", "--max-count", "200", "--max-filesize", "1M", "--glob", "!.git",
233
+ "--no-config", "--no-messages", "--no-require-git", ...wsFlags(cwd), "--json", "--smart-case", "--max-count", "200", "--max-filesize", "1M", "--glob", "!.git",
221
234
  ...(a.constraint === undefined ? [] : ["--glob", rgGlob(a.constraint)]),
222
235
  ...(a.context > 0 ? ["-C", String(a.context)] : []),
223
236
  ...(a.mode === "regex" ? [] : ["--fixed-strings"]),
@@ -345,7 +358,7 @@ export function createSearch(deps) {
345
358
  return {
346
359
  tools: [findTool, grepTool],
347
360
  close: destroy,
348
- indexCwd: () => holder?.cwd,
361
+ indexCwd: () => holders[holders.length - 1]?.cwd,
349
362
  status: () => probeSearch({ rg, loadFff: deps.loadFff }),
350
363
  };
351
364
  }
package/dist/shell.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { delimiter, join } from "node:path";
3
- // The shell is bash on every platform. On Windows that is Git Bash. The WSL launcher in System32 is never used.
3
+ // The shell is bash on every platform. On Windows that is Git Bash. The WSL launchers (System32, Sysnative and the WindowsApps alias) are never used.
4
4
  export const BASH_HINT = "Install Git for Windows (https://git-scm.com/download/win), which includes Git Bash. On Linux and macOS install bash from your package manager.";
5
- const isWslLauncher = (path) => /[\\/](?:system32|sysnative)[\\/]bash\.exe$/iu.test(path);
5
+ export const isWslLauncher = (path) => /[\\/](?:system32|sysnative|microsoft[\\/]windowsapps)[\\/]bash\.exe$/iu.test(path);
6
6
  /** The bash executable to run commands with, or undefined when none is installed. */
7
7
  export function findBash(env = process.env, platform = process.platform) {
8
8
  if (platform !== "win32")
package/dist/tui/app.js CHANGED
@@ -416,8 +416,12 @@ export function missingKeyCheck(authPath, env = process.env) {
416
416
  }
417
417
  /** /conclave undo: list what it would do, ask, then restore the pre-images of the last Vesperia run. */
418
418
  async function undoCommand(rt, ask) {
419
- if (await rt.conclave.live())
420
- return "undo not run: a pipeline is running; /conclave cancel stops it";
419
+ const blocked = await rt.conclave.undoBlocked();
420
+ if (blocked !== undefined)
421
+ return blocked;
422
+ const workspace = await rt.conclave.undoWorkspace(ask);
423
+ if (workspace !== undefined)
424
+ return workspace;
421
425
  const home = rt.guard.config().home;
422
426
  const folder = loadRun(home);
423
427
  if (folder === undefined)
@@ -498,7 +502,13 @@ export function runCommand(rt, text, ask, flow) {
498
502
  return rt.conclave.status();
499
503
  if (sub === "undo")
500
504
  return ask === undefined ? "undo not run: this needs a confirmation, which only the chat screen can ask" : undoCommand(rt, ask);
501
- const started = sub === "approve" ? rt.conclave.approve() : rt.conclave.start(text.slice("/conclave".length));
505
+ if (sub === "merge")
506
+ return rt.conclave.merge(ask);
507
+ if (sub === "discard")
508
+ return rt.conclave.discard(ask);
509
+ if (sub === "retry")
510
+ return rt.conclave.retry();
511
+ const started = sub === "approve" ? rt.conclave.approve(ask) : rt.conclave.start(text.slice("/conclave".length));
502
512
  return started.then((result) => (result.ok ? result.message : `not started: ${result.error}`));
503
513
  }
504
514
  if (name === "telemetry")
@@ -507,6 +517,8 @@ export function runCommand(rt, text, ask, flow) {
507
517
  return skillsReport(rt.skills.state(), COMMANDS.map((command) => command.name));
508
518
  if (name === "akashic")
509
519
  return rt.akashic(rest.join(" "));
520
+ if (name === "learn")
521
+ return rt.learner.command(rest.filter((word) => word !== ""), ask);
510
522
  if (name === "thinking-steps")
511
523
  return thinkingStepsCommand(rt, rest);
512
524
  return undefined;
@@ -7,10 +7,11 @@ export const COMMANDS = [
7
7
  { name: "login", description: "sign in to a provider", args: "[provider]" },
8
8
  { name: "settings", description: "show or change a setting", args: "[key]" },
9
9
  { name: "status", description: "show the chat and compactor status" },
10
- { name: "conclave", description: "run the review pipeline on a task", args: "<task> | approve | cancel | status | undo" },
10
+ { name: "conclave", description: "run the review pipeline on a task", args: "<task> | approve | cancel | status | undo | merge | discard | retry" },
11
11
  { name: "akashic", description: "memory status, accept and vault", args: "[status | accept | vault ...]" },
12
12
  { name: "thinking-steps", description: "choose how thinking steps are shown", args: "[mode | global <mode | clear>]" },
13
13
  { name: "skills", description: "list the skills the chat can use" },
14
+ { name: "learn", description: "the learning loop: status, proposals, undo", args: "[now | accept <name> | reject <name|all> | undo <name> | retry | skip]" },
14
15
  { name: "telemetry", description: "model requests, latency and cost of the last 24 hours" },
15
16
  ];
16
17
  /** The skills that are commands: a name that starts with a letter, and no built-in command of the same name (that one wins). */
@@ -93,12 +94,14 @@ export function suggest(value, models = [], logins = [], skills = []) {
93
94
  return models.filter((model) => model.ref.toLowerCase().includes(needle)).map((model) => ({ complete: `/model ${model.ref}`, label: model.ref, ...(model.disabled === undefined ? {} : { disabled: model.disabled }) }));
94
95
  }
95
96
  if (name === "conclave")
96
- return tokens.length > 1 ? [] : words(lead, last, ["approve", "cancel", "status", "undo"]);
97
+ return tokens.length > 1 ? [] : words(lead, last, ["approve", "cancel", "status", "undo", "merge", "discard", "retry"]);
97
98
  if (name === "thinking-steps") {
98
99
  if (tokens.length === 1)
99
100
  return words(lead, last, [...MODES, "global"], ["global"]);
100
101
  return tokens.length === 2 && tokens[0] === "global" ? words(lead, last, [...MODES, "clear"]) : [];
101
102
  }
103
+ if (name === "learn")
104
+ return tokens.length > 1 ? [] : words(lead, last, ["now", "accept", "reject", "undo", "retry", "skip"]);
102
105
  if (name === "akashic") {
103
106
  if (tokens.length === 1)
104
107
  return words(lead, last, ["status", "accept", "vault"], ["vault"]);
@@ -13,7 +13,10 @@ const APPLIES = {
13
13
  run: "applies at the next Conclave run",
14
14
  start: "applies at the next start",
15
15
  };
16
+ // An allowed pi extensions folder is code that pi runs with your credentials.
17
+ const ALLOW_WARNING = "An allowed folder inside the pi extensions folder holds code that pi runs with your credentials: review edits and merges there like code you install, and merge while pi is not running (or reload pi after).";
16
18
  const FIELD_HELP = {
19
+ "guard.allow": " A project folder opened inside a protected location, at or inside the pi extensions folder or strictly inside a guard.deny root. Credential file names stay refused inside it.",
17
20
  cacheRetention: ' "short" keeps the prompt cache for about 5 minutes. "long" keeps it for an hour and costs more per cache write, so it pays off when you pause longer than 5 minutes between turns.',
18
21
  };
19
22
  const ENTRY_HELP = { env: "an environment variable name such as GIT_SSH_COMMAND", host: 'a lower case host name such as "docs.example.org"', path: "an absolute path" };
@@ -186,7 +189,7 @@ async function commit(rt, io, f, change) {
186
189
  throw error;
187
190
  }
188
191
  if (lines.length > 0) {
189
- io.notify("warn", lines.join("\n"));
192
+ io.notify("warn", (f.path === "guard.allow" ? [...lines, ALLOW_WARNING] : lines).join("\n"));
190
193
  if (!(await io.confirm(SECURITY_CONFIRM, false)))
191
194
  return `${f.path} not changed`;
192
195
  }
@@ -939,9 +939,6 @@ function summarizeThinkingTextDetailed(text, fallback = "Reasoning is hidden by
939
939
  hasExplicitSuccess: visibleMetadata.hasExplicitSuccess,
940
940
  };
941
941
  }
942
- export function summarizeThinkingText(text, fallback = "Reasoning is hidden by the provider.") {
943
- return summarizeThinkingTextDetailed(text, fallback).summary;
944
- }
945
942
  export function inferThinkingRole(text) {
946
943
  const haystack = ` ${normalizeNewlines(text).toLowerCase()} `;
947
944
  const referenceOnlyFailureCue = FAILURE_REFERENCE_CONTEXT_RE.test(haystack)