@ashx-j/lunr-dev 0.2.40-dev.60.1 → 0.2.40-dev.62.1

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 (63) hide show
  1. package/dist/core/agent-session.d.ts +10 -0
  2. package/dist/core/agent-session.js +49 -1
  3. package/dist/core/auth-storage.d.ts +2 -0
  4. package/dist/core/auth-storage.js +5 -0
  5. package/dist/core/model-runtime.d.ts +3 -0
  6. package/dist/core/model-runtime.js +20 -5
  7. package/dist/core/resolve-config-value.d.ts +5 -0
  8. package/dist/core/resolve-config-value.js +16 -0
  9. package/dist/core/saved-login-redaction.d.ts +74 -0
  10. package/dist/core/saved-login-redaction.js +322 -0
  11. package/dist/core/session-manager.d.ts +13 -0
  12. package/dist/core/session-manager.js +19 -8
  13. package/dist/core/subscriptions.d.ts +2 -0
  14. package/dist/core/subscriptions.js +5 -0
  15. package/dist/core/tools/edit.d.ts +11 -4
  16. package/dist/core/tools/edit.js +36 -20
  17. package/dist/modes/interactive/tool-renderers/edit.js +4 -0
  18. package/dist/node-runtime/{agent-session-services-UOVUJAX2.js → agent-session-services-2MOVXNT5.js} +6 -6
  19. package/dist/node-runtime/{builtin-extensions-JNJRND4E.js → builtin-extensions-S23KMP4W.js} +1 -1
  20. package/dist/node-runtime/{chunk-HQ5A4VVO.js → chunk-2EQL4TLM.js} +19 -8
  21. package/dist/node-runtime/{chunk-EJMB4PAV.js → chunk-4JOKLU3I.js} +35 -20
  22. package/dist/node-runtime/{chunk-4OALPI3C.js → chunk-6NUWUTVC.js} +1 -1
  23. package/dist/node-runtime/{chunk-QNFPZIP3.js → chunk-C5PAMN7Y.js} +244 -17
  24. package/dist/node-runtime/{chunk-GX7UZDSI.js → chunk-EWYLZSES.js} +1 -1
  25. package/dist/node-runtime/{chunk-GAWWLIGY.js → chunk-FIDZY4JX.js} +4 -4
  26. package/dist/node-runtime/{chunk-U7MTVVT3.js → chunk-JCL5IRM5.js} +1 -1
  27. package/dist/node-runtime/{chunk-Y7DFMHY5.js → chunk-KV4RBM3L.js} +10 -10
  28. package/dist/node-runtime/{chunk-HYOPEHDE.js → chunk-QQSC6CTJ.js} +1 -1
  29. package/dist/node-runtime/{chunk-RXG6DWO2.js → chunk-S2BEWKPR.js} +3 -3
  30. package/dist/node-runtime/{chunk-S46QLY2F.js → chunk-SJSWJWAT.js} +30 -11
  31. package/dist/node-runtime/{chunk-BQROL43X.js → chunk-TKN7VEZR.js} +11 -11
  32. package/dist/node-runtime/{chunk-QDQAKIVU.js → chunk-TYPA7FJQ.js} +1 -1
  33. package/dist/node-runtime/{chunk-FCINT2KC.js → chunk-VBNMCUV2.js} +2 -2
  34. package/dist/node-runtime/{chunk-2B5RTZA4.js → chunk-XLGSGHTG.js} +1 -1
  35. package/dist/node-runtime/{chunk-XXGJ7Z3C.js → chunk-YVOU5W7H.js} +7 -7
  36. package/dist/node-runtime/{command-6GJNLXGD.js → command-ARYMXJF7.js} +3 -3
  37. package/dist/node-runtime/{commands-2UG5F4VT.js → commands-E3EQFYAC.js} +5 -5
  38. package/dist/node-runtime/{doctor-cli-TU4HVXWP.js → doctor-cli-DWI46VPW.js} +1 -1
  39. package/dist/node-runtime/{export-html-SW3CIZRJ.js → export-html-YM4QKDTD.js} +1 -1
  40. package/dist/node-runtime/{gateway-UDWVYEGX.js → gateway-I7YA6MJ4.js} +9 -9
  41. package/dist/node-runtime/index.js +12 -12
  42. package/dist/node-runtime/{install-cli-YIIFVCFM.js → install-cli-A5HIEOOK.js} +1 -1
  43. package/dist/node-runtime/{interactive-mode-VCPSTUAW.js → interactive-mode-6UDD62TS.js} +9 -9
  44. package/dist/node-runtime/{lunr-cron-3VI5CLK3.js → lunr-cron-FYLIKLSZ.js} +4 -4
  45. package/dist/node-runtime/main.js +8 -8
  46. package/dist/node-runtime/{mobile-commands-HQXEYAF6.js → mobile-commands-CKQHQBEW.js} +2 -2
  47. package/dist/node-runtime/{model-runtime-T552YPXL.js → model-runtime-RFMIP23V.js} +1 -1
  48. package/dist/node-runtime/{pi-subagents-YVVMY4B4.js → pi-subagents-C5FBVY72.js} +3 -3
  49. package/dist/node-runtime/{print-mode-M52NLHKG.js → print-mode-I6R6RWLJ.js} +7 -7
  50. package/dist/node-runtime/rpc-entry.js +8 -8
  51. package/dist/node-runtime/{session-handoff-TEOBWIFW.js → session-handoff-XCKL6SRJ.js} +2 -2
  52. package/dist/node-runtime/{session-manager-I6535F4R.js → session-manager-AGK72CRA.js} +1 -1
  53. package/dist/node-runtime/{setup-7IC2PQIB.js → setup-HF7HDJKG.js} +1 -1
  54. package/dist/node-runtime/{subagent-executor-RTGKJ35C.js → subagent-executor-N6FKWYCK.js} +3 -3
  55. package/dist/node-runtime/{tool-renderers-KL5EPAMN.js → tool-renderers-XZX7BEOM.js} +1 -1
  56. package/docs/extensions.md +3 -1
  57. package/docs/security.md +28 -0
  58. package/examples/extensions/built-in-tool-renderer.ts +2 -0
  59. package/examples/extensions/minimal-mode.ts +2 -0
  60. package/install-lock/package-lock.json +24 -24
  61. package/install-lock/package.json +2 -2
  62. package/npm-shrinkwrap.json +12 -12
  63. package/package.json +4 -4
@@ -174,6 +174,14 @@ export declare function loadEntriesFromFile(filePath: string): FileEntry[];
174
174
  /** Exported for testing */
175
175
  export declare function findMostRecentSession(sessionDir: string, cwd?: string): string | null;
176
176
  export type SessionListProgress = (loaded: number, total: number) => void;
177
+ /**
178
+ * Removes saved-login values (`core/saved-login-redaction.ts`): from each serialized JSONL line the
179
+ * manager writes, and from summary text before it enters the session and the model's context.
180
+ */
181
+ export interface SessionSavedLoginFilter {
182
+ redactSessionLine(line: string): string;
183
+ redactText(text: string): string;
184
+ }
177
185
  /**
178
186
  * Manages conversation sessions as append-only trees stored in JSONL files.
179
187
  *
@@ -193,6 +201,7 @@ export declare class SessionManager {
193
201
  private persist;
194
202
  private flushed;
195
203
  private needsAppendSeparator;
204
+ private savedLoginFilter;
196
205
  private fileEntries;
197
206
  private byId;
198
207
  private labelsById;
@@ -223,6 +232,10 @@ export declare class SessionManager {
223
232
  * Rename protects the previous log on write failure, not against every power-loss scenario.
224
233
  */
225
234
  private _rewriteFile;
235
+ /** Set by AgentSession, so every line this manager writes from now on is filtered. */
236
+ setSavedLoginFilter(filter: SessionSavedLoginFilter | undefined): void;
237
+ /** The one place an entry becomes a JSONL line. */
238
+ private serialize;
226
239
  private _appendToFile;
227
240
  isPersisted(): boolean;
228
241
  getCwd(): string;
@@ -536,7 +536,7 @@ function renameReplacing(from, to) {
536
536
  renameSync(from, to);
537
537
  }
538
538
  /** Atomically replace a log without changing the manager that owns it. */
539
- function writeSessionEntries(file, entries) {
539
+ function writeSessionEntries(file, entries, serialize) {
540
540
  const mode = existsSync(file) ? statSync(file).mode & 0o777 : SESSION_FILE_MODE;
541
541
  const temp = `${file}.${randomUUID()}.tmp`;
542
542
  const fd = openSync(temp, "wx", mode);
@@ -544,7 +544,7 @@ function writeSessionEntries(file, entries) {
544
544
  try {
545
545
  fchmodSync(fd, mode);
546
546
  for (const entry of entries) {
547
- writeFileSync(fd, `${JSON.stringify(entry)}\n`);
547
+ writeFileSync(fd, `${serialize(entry)}\n`);
548
548
  }
549
549
  fsyncSync(fd);
550
550
  }
@@ -578,6 +578,7 @@ export class SessionManager {
578
578
  persist;
579
579
  flushed = false;
580
580
  needsAppendSeparator = false;
581
+ savedLoginFilter;
581
582
  fileEntries = [];
582
583
  byId = new Map();
583
584
  labelsById = new Map();
@@ -826,13 +827,22 @@ export class SessionManager {
826
827
  if (!this.persist || !this.sessionFile)
827
828
  return;
828
829
  const file = this.ownership?.owner.file ?? this.sessionFile;
829
- writeSessionEntries(file, this.fileEntries);
830
+ writeSessionEntries(file, this.fileEntries, (entry) => this.serialize(entry));
830
831
  this.needsAppendSeparator = false;
831
832
  }
833
+ /** Set by AgentSession, so every line this manager writes from now on is filtered. */
834
+ setSavedLoginFilter(filter) {
835
+ this.savedLoginFilter = filter;
836
+ }
837
+ /** The one place an entry becomes a JSONL line. */
838
+ serialize(entry) {
839
+ const line = JSON.stringify(entry);
840
+ return this.savedLoginFilter ? this.savedLoginFilter.redactSessionLine(line) : line;
841
+ }
832
842
  _appendToFile(entry) {
833
843
  if (!this.sessionFile)
834
844
  return;
835
- appendFileSync(this.sessionFile, `${this.needsAppendSeparator ? "\n" : ""}${JSON.stringify(entry)}\n`, {
845
+ appendFileSync(this.sessionFile, `${this.needsAppendSeparator ? "\n" : ""}${this.serialize(entry)}\n`, {
836
846
  mode: SESSION_FILE_MODE,
837
847
  });
838
848
  this.needsAppendSeparator = false;
@@ -874,7 +884,7 @@ export class SessionManager {
874
884
  const fd = openSync(this.sessionFile, "wx", SESSION_FILE_MODE);
875
885
  try {
876
886
  for (const e of this.fileEntries) {
877
- writeFileSync(fd, `${JSON.stringify(e)}\n`);
887
+ writeFileSync(fd, `${this.serialize(e)}\n`);
878
888
  }
879
889
  }
880
890
  finally {
@@ -957,7 +967,8 @@ export class SessionManager {
957
967
  id: generateId(this.byId),
958
968
  parentId: this.leafId,
959
969
  timestamp: new Date(Math.max(Date.now(), this.newestTimestampFrom(firstKeptEntryId) + 1)).toISOString(),
960
- summary,
970
+ // The summary replaces history in the model's context, so it gets the text filter too.
971
+ summary: this.savedLoginFilter ? this.savedLoginFilter.redactText(summary) : summary,
961
972
  firstKeptEntryId,
962
973
  tokensBefore,
963
974
  details,
@@ -1249,7 +1260,7 @@ export class SessionManager {
1249
1260
  parentId: branchFromId,
1250
1261
  timestamp: new Date().toISOString(),
1251
1262
  fromId: branchFromId ?? "root",
1252
- summary,
1263
+ summary: this.savedLoginFilter ? this.savedLoginFilter.redactText(summary) : summary,
1253
1264
  details,
1254
1265
  fromHook,
1255
1266
  };
@@ -1325,7 +1336,7 @@ export class SessionManager {
1325
1336
  try {
1326
1337
  nextOwnership.bindSession(newSessionId);
1327
1338
  if (hasAssistant) {
1328
- writeSessionEntries(nextOwnership.owner.file, entries);
1339
+ writeSessionEntries(nextOwnership.owner.file, entries, (entry) => this.serialize(entry));
1329
1340
  wroteFork = true;
1330
1341
  }
1331
1342
  this.ownership?.release();
@@ -38,6 +38,8 @@ export declare class SubscriptionManager {
38
38
  private queue;
39
39
  private memoryExhausted;
40
40
  private constructor();
41
+ /** The pool keys loaded so far, for `SavedLoginRedactor`; the same array until they change. */
42
+ savedLoginValues(): readonly string[];
41
43
  static create(authStorage: CredentialStore, path?: string): SubscriptionManager;
42
44
  static fromStorage(authStorage: CredentialStore, storage: AuthStorageBackend): SubscriptionManager;
43
45
  static inMemory(authStorage: CredentialStore, data?: SubscriptionData): SubscriptionManager;
@@ -14,6 +14,7 @@ import { createHash } from "node:crypto";
14
14
  import { join } from "path";
15
15
  import { getAgentDir } from "../config.js";
16
16
  import { FileAuthStorageBackend, InMemoryAuthStorageBackend } from "./auth-storage.js";
17
+ import { poolValuesOf } from "./saved-login-redaction.js";
17
18
  import { parseResetTimeMs } from "./usage-limit.js";
18
19
  import { clearPlanUsageCache } from "./usage-service.js";
19
20
  /** Request identities are non-secret digests kept outside messages and storage. */
@@ -33,6 +34,10 @@ export class SubscriptionManager {
33
34
  this.authStorage = authStorage;
34
35
  this.storage = storage;
35
36
  }
37
+ /** The pool keys loaded so far, for `SavedLoginRedactor`; the same array until they change. */
38
+ savedLoginValues() {
39
+ return poolValuesOf(this.data);
40
+ }
36
41
  static create(authStorage, path) {
37
42
  return new SubscriptionManager(authStorage, new FileAuthStorageBackend(path ?? join(getAgentDir(), "subscriptions.json")));
38
43
  }
@@ -1,14 +1,21 @@
1
1
  import type { AgentTool } from "@ashx-j/lunr-agent";
2
- import { type Static, Type } from "typebox";
2
+ import { Type } from "typebox";
3
3
  import type { ToolDefinition } from "../extensions/types.ts";
4
+ import { type Edit } from "./edit-diff.ts";
4
5
  declare const editSchema: Type.TObject<{
5
6
  path: Type.TString;
6
- edits: Type.TArray<Type.TObject<{
7
+ oldText: Type.TOptional<Type.TString>;
8
+ newText: Type.TOptional<Type.TString>;
9
+ edits: Type.TOptional<Type.TArray<Type.TObject<{
7
10
  oldText: Type.TString;
8
11
  newText: Type.TString;
9
- }>>;
12
+ }>>>;
10
13
  }>;
11
- export type EditToolInput = Static<typeof editSchema>;
14
+ /** Edit arguments after `prepareEditArguments` folds the flat oldText/newText form into `edits`. */
15
+ export type EditToolInput = {
16
+ path: string;
17
+ edits: Edit[];
18
+ };
12
19
  export interface EditToolDetails {
13
20
  /** Display-oriented diff of the changes made */
14
21
  diff: string;
@@ -1,3 +1,4 @@
1
+ import { validateToolArguments } from "@ashx-j/lunr-ai";
1
2
  import { constants } from "fs";
2
3
  import { access as fsAccess, readFile as fsReadFile, writeFile as fsWriteFile } from "fs/promises";
3
4
  import { Type } from "typebox";
@@ -5,30 +6,34 @@ import { applyEditsToNormalizedContent, detectLineEnding, generateDiffString, ge
5
6
  import { withFileMutationQueue } from "./file-mutation-queue.js";
6
7
  import { resolveToCwd } from "./path-utils.js";
7
8
  import { wrapToolDefinition } from "./tool-definition-wrapper.js";
8
- const replaceEditSchema = Type.Object({
9
- oldText: Type.String({
10
- description: "Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call.",
11
- }),
12
- newText: Type.String({ description: "Replacement text for this targeted edit." }),
13
- }, {});
9
+ // The tool description carries the matching rules, so the properties stay short: each one costs
10
+ // first-request tokens on every session.
11
+ const replaceEditSchema = Type.Object({ oldText: Type.String(), newText: Type.String() });
14
12
  const editSchema = Type.Object({
15
13
  path: Type.String({ description: "Path to the file to edit (relative or absolute)" }),
16
- edits: Type.Array(replaceEditSchema, {
17
- description: "One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead.",
18
- }),
14
+ oldText: Type.Optional(Type.String({ description: "Exact text to replace (one replacement)" })),
15
+ newText: Type.Optional(Type.String({ description: "Replacement for oldText" })),
16
+ edits: Type.Optional(Type.Array(replaceEditSchema, { description: "Several replacements, each matched against the original file" })),
19
17
  }, {});
20
18
  const defaultEditOperations = {
21
19
  readFile: (path) => fsReadFile(path),
22
20
  writeFile: (path, content) => fsWriteFile(path, content, "utf-8"),
23
21
  access: (path) => fsAccess(path, constants.R_OK | constants.W_OK),
24
22
  };
23
+ const FLAT_FORM_HINT = 'For one replacement, send top-level strings: {"path": "...", "oldText": "...", "newText": "..."}';
24
+ function invalidEditArguments(problem, args) {
25
+ return new Error(`Validation failed for tool "edit":\n - ${problem}\n\nReceived arguments:\n${JSON.stringify(args, null, 2)}\n\n${FLAT_FORM_HINT}`);
26
+ }
27
+ /**
28
+ * Folds the flat form (top-level oldText/newText) into `edits`. Any other call is returned as it came,
29
+ * so the agent loop's validation, its coercions and extra fields reach hooks exactly as before. This
30
+ * runs that validation once first only to add the flat form to its error, which the model reads.
31
+ */
25
32
  function prepareEditArguments(input) {
26
- if (!input || typeof input !== "object") {
27
- return input;
28
- }
33
+ // Untyped model input: the validator below checks it.
29
34
  const args = input;
30
35
  // Some models (Opus 4.6, GLM-5.1) send edits as a JSON string instead of an array
31
- if (typeof args.edits === "string") {
36
+ if (args && typeof args === "object" && typeof args.edits === "string") {
32
37
  try {
33
38
  const parsed = JSON.parse(args.edits);
34
39
  if (Array.isArray(parsed))
@@ -38,14 +43,25 @@ function prepareEditArguments(input) {
38
43
  // Not JSON: leave the string so schema validation reports the bad edits argument.
39
44
  }
40
45
  }
41
- const legacy = args;
42
- if (typeof legacy.oldText !== "string" || typeof legacy.newText !== "string") {
46
+ let valid;
47
+ try {
48
+ valid = validateToolArguments({ name: "edit", description: "", parameters: editSchema }, { type: "toolCall", id: "", name: "edit", arguments: args });
49
+ }
50
+ catch (error) {
51
+ throw new Error(`${error instanceof Error ? error.message : String(error)}\n\n${FLAT_FORM_HINT}`);
52
+ }
53
+ const { oldText, newText, edits, ...rest } = valid;
54
+ if (oldText === undefined && newText === undefined) {
55
+ if (edits === undefined)
56
+ throw invalidEditArguments("send oldText and newText, or edits", args);
43
57
  return args;
44
58
  }
45
- const edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];
46
- edits.push({ oldText: legacy.oldText, newText: legacy.newText });
47
- const { oldText: _oldText, newText: _newText, ...rest } = legacy;
48
- return { ...rest, edits };
59
+ if (edits !== undefined)
60
+ throw invalidEditArguments("send oldText and newText, or edits, not both", args);
61
+ if (oldText === undefined || newText === undefined) {
62
+ throw invalidEditArguments("send oldText and newText together", args);
63
+ }
64
+ return { ...rest, edits: [{ oldText, newText }] };
49
65
  }
50
66
  function validateEditInput(input) {
51
67
  if (!Array.isArray(input.edits) || input.edits.length === 0) {
@@ -58,7 +74,7 @@ export function createEditToolDefinition(cwd, options) {
58
74
  return {
59
75
  name: "edit",
60
76
  label: "edit",
61
- description: "Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.",
77
+ description: "Edit a single file using exact text replacement. Pass either oldText and newText for one replacement, or edits[] for several replacements in the same file, not both. Every oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit. Do not include large unchanged regions just to connect distant changes.",
62
78
  promptSnippet: "Make precise file edits with exact text replacement, including multiple disjoint edits in one call",
63
79
  promptGuidelines: [
64
80
  "Use edit for precise changes (edits[].oldText must match exactly)",
@@ -31,6 +31,10 @@ function getRenderablePreviewInput(args) {
31
31
  if (!path) {
32
32
  return null;
33
33
  }
34
+ // The tool rejects a call that sends both forms, so it gets no preview.
35
+ if (args.edits !== undefined && (args.oldText !== undefined || args.newText !== undefined)) {
36
+ return null;
37
+ }
34
38
  if (Array.isArray(args.edits) &&
35
39
  args.edits.length > 0 &&
36
40
  args.edits.every((edit) => typeof edit?.oldText === "string" && typeof edit?.newText === "string")) {
@@ -2,20 +2,20 @@ import { createRequire as __lunrRequire } from "node:module"; const require = __
2
2
  import {
3
3
  createAgentSessionFromServices,
4
4
  createAgentSessionServices
5
- } from "./chunk-S46QLY2F.js";
5
+ } from "./chunk-SJSWJWAT.js";
6
6
  import "./chunk-QP4I6GEW.js";
7
7
  import "./chunk-KDBQKVNZ.js";
8
8
  import "./chunk-GLSX5WQB.js";
9
9
  import "./chunk-DVGWF6A2.js";
10
10
  import "./chunk-F5NKEKNO.js";
11
- import "./chunk-2B5RTZA4.js";
11
+ import "./chunk-XLGSGHTG.js";
12
12
  import "./chunk-3XBYDZWT.js";
13
13
  import "./chunk-AW6PDL4D.js";
14
14
  import "./chunk-6Z5EUITR.js";
15
15
  import "./chunk-IXG6F4NT.js";
16
16
  import "./chunk-CGBXPL3E.js";
17
17
  import "./chunk-IMLLN6W5.js";
18
- import "./chunk-EJMB4PAV.js";
18
+ import "./chunk-4JOKLU3I.js";
19
19
  import "./chunk-PGWSMQ4K.js";
20
20
  import "./chunk-YSB6URMT.js";
21
21
  import "./chunk-IAZSK7KK.js";
@@ -23,7 +23,7 @@ import "./chunk-TCT6PCUR.js";
23
23
  import "./chunk-LGRRFSE7.js";
24
24
  import "./chunk-XPKOWSYN.js";
25
25
  import "./chunk-BDRGN3L2.js";
26
- import "./chunk-QNFPZIP3.js";
26
+ import "./chunk-C5PAMN7Y.js";
27
27
  import "./chunk-4SBPXNVV.js";
28
28
  import "./chunk-53YJI7JU.js";
29
29
  import "./chunk-V3AX7UT3.js";
@@ -34,8 +34,8 @@ import "./chunk-5ZDIECKE.js";
34
34
  import "./chunk-SJVCEPQS.js";
35
35
  import "./chunk-V4VKJDRA.js";
36
36
  import "./chunk-5UCVERGR.js";
37
- import "./chunk-4OALPI3C.js";
38
- import "./chunk-HQ5A4VVO.js";
37
+ import "./chunk-6NUWUTVC.js";
38
+ import "./chunk-2EQL4TLM.js";
39
39
  import "./chunk-FVDOXRUD.js";
40
40
  import "./chunk-MIWAGF3T.js";
41
41
  import "./chunk-SRCSFFDW.js";
@@ -6,7 +6,7 @@ import {
6
6
  lightBuiltinExtensions,
7
7
  loadAllBuiltinExtensions,
8
8
  loadDeferredBuiltinExtensions
9
- } from "./chunk-FCINT2KC.js";
9
+ } from "./chunk-VBNMCUV2.js";
10
10
  import "./chunk-PDQLKTGM.js";
11
11
  import "./chunk-PKDES47T.js";
12
12
  import "./chunk-5ZH3ZFIZ.js";
@@ -342,13 +342,13 @@ function renameReplacing(from, to) {
342
342
  }
343
343
  renameSync(from, to);
344
344
  }
345
- function writeSessionEntries(file, entries) {
345
+ function writeSessionEntries(file, entries, serialize) {
346
346
  let mode = existsSync(file) ? statSync(file).mode & 511 : SESSION_FILE_MODE, temp = `${file}.${randomUUID()}.tmp`, fd = openSync(temp, "wx", mode);
347
347
  try {
348
348
  try {
349
349
  fchmodSync(fd, mode);
350
350
  for (let entry of entries)
351
- writeFileSync(fd, `${JSON.stringify(entry)}
351
+ writeFileSync(fd, `${serialize(entry)}
352
352
  `);
353
353
  fsyncSync(fd);
354
354
  } finally {
@@ -367,6 +367,7 @@ var SessionManager = class _SessionManager {
367
367
  persist;
368
368
  flushed = !1;
369
369
  needsAppendSeparator = !1;
370
+ savedLoginFilter;
370
371
  fileEntries = [];
371
372
  byId = /* @__PURE__ */ new Map();
372
373
  labelsById = /* @__PURE__ */ new Map();
@@ -510,11 +511,20 @@ var SessionManager = class _SessionManager {
510
511
  if (this.assertWritable(), !this.persist || !this.sessionFile)
511
512
  return;
512
513
  let file = this.ownership?.owner.file ?? this.sessionFile;
513
- writeSessionEntries(file, this.fileEntries), this.needsAppendSeparator = !1;
514
+ writeSessionEntries(file, this.fileEntries, (entry) => this.serialize(entry)), this.needsAppendSeparator = !1;
515
+ }
516
+ /** Set by AgentSession, so every line this manager writes from now on is filtered. */
517
+ setSavedLoginFilter(filter) {
518
+ this.savedLoginFilter = filter;
519
+ }
520
+ /** The one place an entry becomes a JSONL line. */
521
+ serialize(entry) {
522
+ let line = JSON.stringify(entry);
523
+ return this.savedLoginFilter ? this.savedLoginFilter.redactSessionLine(line) : line;
514
524
  }
515
525
  _appendToFile(entry) {
516
526
  this.sessionFile && (appendFileSync(this.sessionFile, `${this.needsAppendSeparator ? `
517
- ` : ""}${JSON.stringify(entry)}
527
+ ` : ""}${this.serialize(entry)}
518
528
  `, {
519
529
  mode: SESSION_FILE_MODE
520
530
  }), this.needsAppendSeparator = !1);
@@ -550,7 +560,7 @@ var SessionManager = class _SessionManager {
550
560
  let fd = openSync(this.sessionFile, "wx", SESSION_FILE_MODE);
551
561
  try {
552
562
  for (let e of this.fileEntries)
553
- writeFileSync(fd, `${JSON.stringify(e)}
563
+ writeFileSync(fd, `${this.serialize(e)}
554
564
  `);
555
565
  } finally {
556
566
  closeSync(fd);
@@ -621,7 +631,8 @@ var SessionManager = class _SessionManager {
621
631
  id: generateId(this.byId),
622
632
  parentId: this.leafId,
623
633
  timestamp: new Date(Math.max(Date.now(), this.newestTimestampFrom(firstKeptEntryId) + 1)).toISOString(),
624
- summary,
634
+ // The summary replaces history in the model's context, so it gets the text filter too.
635
+ summary: this.savedLoginFilter ? this.savedLoginFilter.redactText(summary) : summary,
625
636
  firstKeptEntryId,
626
637
  tokensBefore,
627
638
  details,
@@ -861,7 +872,7 @@ var SessionManager = class _SessionManager {
861
872
  parentId: branchFromId,
862
873
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
863
874
  fromId: branchFromId ?? "root",
864
- summary,
875
+ summary: this.savedLoginFilter ? this.savedLoginFilter.redactText(summary) : summary,
865
876
  details,
866
877
  fromHook
867
878
  };
@@ -907,7 +918,7 @@ var SessionManager = class _SessionManager {
907
918
  this.saveLeaf();
908
919
  let nextOwnership = new SessionOwnership(canonicalSessionPath(newSessionFile)), wroteFork = !1;
909
920
  try {
910
- nextOwnership.bindSession(newSessionId), hasAssistant && (writeSessionEntries(nextOwnership.owner.file, entries), wroteFork = !0), this.ownership?.release();
921
+ nextOwnership.bindSession(newSessionId), hasAssistant && (writeSessionEntries(nextOwnership.owner.file, entries, (entry) => this.serialize(entry)), wroteFork = !0), this.ownership?.release();
911
922
  } catch (error) {
912
923
  if (wroteFork)
913
924
  try {
@@ -721,41 +721,56 @@ function createBashTool(cwd, options) {
721
721
  }
722
722
 
723
723
  // packages/coding-agent/dist/core/tools/edit.js
724
+ import { validateToolArguments } from "@ashx-j/lunr-ai";
724
725
  import { constants as constants2 } from "fs";
725
726
  import { access as fsAccess2, readFile as fsReadFile, writeFile as fsWriteFile } from "fs/promises";
726
727
  import { Type as Type3 } from "typebox";
727
- var replaceEditSchema = Type3.Object({
728
- oldText: Type3.String({
729
- description: "Exact text for one targeted replacement. It must be unique in the original file and must not overlap with any other edits[].oldText in the same call."
730
- }),
731
- newText: Type3.String({ description: "Replacement text for this targeted edit." })
732
- }, {}), editSchema = Type3.Object({
728
+ var replaceEditSchema = Type3.Object({ oldText: Type3.String(), newText: Type3.String() }), editSchema = Type3.Object({
733
729
  path: Type3.String({ description: "Path to the file to edit (relative or absolute)" }),
734
- edits: Type3.Array(replaceEditSchema, {
735
- description: "One or more targeted replacements. Each edit is matched against the original file, not incrementally. Do not include overlapping or nested edits. If two changes touch the same block or nearby lines, merge them into one edit instead."
736
- })
730
+ oldText: Type3.Optional(Type3.String({ description: "Exact text to replace (one replacement)" })),
731
+ newText: Type3.Optional(Type3.String({ description: "Replacement for oldText" })),
732
+ edits: Type3.Optional(Type3.Array(replaceEditSchema, { description: "Several replacements, each matched against the original file" }))
737
733
  }, {}), defaultEditOperations = {
738
734
  readFile: (path3) => fsReadFile(path3),
739
735
  writeFile: (path3, content) => fsWriteFile(path3, content, "utf-8"),
740
736
  access: (path3) => fsAccess2(path3, constants2.R_OK | constants2.W_OK)
741
- };
737
+ }, FLAT_FORM_HINT = 'For one replacement, send top-level strings: {"path": "...", "oldText": "...", "newText": "..."}';
738
+ function invalidEditArguments(problem, args) {
739
+ return new Error(`Validation failed for tool "edit":
740
+ - ${problem}
741
+
742
+ Received arguments:
743
+ ${JSON.stringify(args, null, 2)}
744
+
745
+ ${FLAT_FORM_HINT}`);
746
+ }
742
747
  function prepareEditArguments(input) {
743
- if (!input || typeof input != "object")
744
- return input;
745
748
  let args = input;
746
- if (typeof args.edits == "string")
749
+ if (args && typeof args == "object" && typeof args.edits == "string")
747
750
  try {
748
751
  let parsed = JSON.parse(args.edits);
749
752
  Array.isArray(parsed) && (args.edits = parsed);
750
753
  } catch {
751
754
  }
752
- let legacy = args;
753
- if (typeof legacy.oldText != "string" || typeof legacy.newText != "string")
755
+ let valid;
756
+ try {
757
+ valid = validateToolArguments({ name: "edit", description: "", parameters: editSchema }, { type: "toolCall", id: "", name: "edit", arguments: args });
758
+ } catch (error) {
759
+ throw new Error(`${error instanceof Error ? error.message : String(error)}
760
+
761
+ ${FLAT_FORM_HINT}`);
762
+ }
763
+ let { oldText, newText, edits, ...rest } = valid;
764
+ if (oldText === void 0 && newText === void 0) {
765
+ if (edits === void 0)
766
+ throw invalidEditArguments("send oldText and newText, or edits", args);
754
767
  return args;
755
- let edits = Array.isArray(legacy.edits) ? [...legacy.edits] : [];
756
- edits.push({ oldText: legacy.oldText, newText: legacy.newText });
757
- let { oldText: _oldText, newText: _newText, ...rest } = legacy;
758
- return { ...rest, edits };
768
+ }
769
+ if (edits !== void 0)
770
+ throw invalidEditArguments("send oldText and newText, or edits, not both", args);
771
+ if (oldText === void 0 || newText === void 0)
772
+ throw invalidEditArguments("send oldText and newText together", args);
773
+ return { ...rest, edits: [{ oldText, newText }] };
759
774
  }
760
775
  function validateEditInput(input) {
761
776
  if (!Array.isArray(input.edits) || input.edits.length === 0)
@@ -767,7 +782,7 @@ function createEditToolDefinition(cwd, options) {
767
782
  return {
768
783
  name: "edit",
769
784
  label: "edit",
770
- description: "Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.",
785
+ description: "Edit a single file using exact text replacement. Pass either oldText and newText for one replacement, or edits[] for several replacements in the same file, not both. Every oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit. Do not include large unchanged regions just to connect distant changes.",
771
786
  promptSnippet: "Make precise file edits with exact text replacement, including multiple disjoint edits in one call",
772
787
  promptGuidelines: [
773
788
  "Use edit for precise changes (edits[].oldText must match exactly)",
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __lunrRequire } from "node:module"; const require = __lunrRequire(import.meta.url);
2
2
  import {
3
3
  SessionManager
4
- } from "./chunk-HQ5A4VVO.js";
4
+ } from "./chunk-2EQL4TLM.js";
5
5
  import {
6
6
  SessionOwnership,
7
7
  canonicalSessionPath,