@myagentroam/node 0.9.113 → 0.9.115

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.
@@ -1,5 +1,6 @@
1
1
  import { tmpdir } from 'node:os';
2
- import { isAbsolute, win32 } from 'node:path';
2
+ import { isAbsolute, relative, resolve, win32 } from 'node:path';
3
+ import { realpath } from 'node:fs/promises';
3
4
  import { listWorkspaceFiles, mutateWorkspaceFile, normalizeFilePreviewPath, readAllowedFileContentRange, readWorkspaceFileContentRange, readAllowedTextFile, readWorkspaceTextFile, writeWorkspaceTextFile, WorkspaceFileIndex } from '../workspace.js';
4
5
  const INDEX_CACHE_LIMIT = 32;
5
6
  export class WorkspaceFileService {
@@ -52,6 +53,19 @@ export class WorkspaceFileService {
52
53
  const path = normalizeFilePreviewPath(input.path);
53
54
  if (workspacePath !== workspace.path && isFilePreviewAbsolutePath(path))
54
55
  throw new Error('FILE_PATH_ESCAPE');
56
+ if (input.previewDirectory !== undefined) {
57
+ if (typeof input.previewDirectory !== 'string' ||
58
+ isFilePreviewAbsolutePath(path) ||
59
+ isFilePreviewAbsolutePath(input.previewDirectory))
60
+ throw new Error('FILE_PATH_ESCAPE');
61
+ const root = await realpath(resolve(workspacePath, input.previewDirectory));
62
+ const target = await realpath(resolve(workspacePath, path));
63
+ const suffix = relative(root, target);
64
+ if (suffix === '..' ||
65
+ suffix.startsWith(`..${process.platform === 'win32' ? '\\' : '/'}`) ||
66
+ isAbsolute(suffix))
67
+ throw new Error('FILE_PATH_ESCAPE');
68
+ }
55
69
  const offset = typeof input.offset === 'number' ? input.offset : 0;
56
70
  const limit = typeof input.limit === 'number' ? input.limit : 512 * 1024;
57
71
  return isFilePreviewAbsolutePath(path)
@@ -150,7 +150,8 @@ export class WorkspaceWorkbenchService {
150
150
  const workspace = this.options.requireWorkspace(input.workspaceId);
151
151
  const repository = await this.fileRepository(workspace, input);
152
152
  return {
153
- file: await this.options.files.readContent(workspace, input, repository)
153
+ file: await this.options.files.readContent(workspace, input, repository),
154
+ ...(input.previewDirectory === undefined ? {} : { previewBoundaryVerified: true })
154
155
  };
155
156
  }
156
157
  async directFileMetadata(input) {
package/dist/workspace.js CHANGED
@@ -385,7 +385,18 @@ class RankedCandidateHeap {
385
385
  }
386
386
  function fuzzyPathScore(path, query) {
387
387
  const source = path.toLocaleLowerCase();
388
- const needle = query.trim().toLocaleLowerCase();
388
+ const terms = query.trim().toLocaleLowerCase().split(/\s+/u);
389
+ const name = source.slice(source.lastIndexOf('/') + 1);
390
+ let total = 0;
391
+ for (const needle of terms) {
392
+ const score = fuzzyTermScore(source, name, needle);
393
+ if (score < 0)
394
+ return -1;
395
+ total += score;
396
+ }
397
+ return total - path.length / 1_000;
398
+ }
399
+ function fuzzyTermScore(source, name, needle) {
389
400
  let cursor = 0;
390
401
  let score = 0;
391
402
  let previous = -2;
@@ -399,12 +410,11 @@ function fuzzyPathScore(path, query) {
399
410
  previous = index;
400
411
  cursor = index + 1;
401
412
  }
402
- const name = path.slice(path.lastIndexOf('/') + 1).toLocaleLowerCase();
403
413
  if (name.includes(needle))
404
414
  score += 40;
405
415
  else if (source.includes(needle))
406
416
  score += 16;
407
- return score - path.length / 1_000;
417
+ return score;
408
418
  }
409
419
  /**
410
420
  * Lists directory names only for the Workspace picker. Browsing begins at the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myagentroam/node",
3
- "version": "0.9.113",
3
+ "version": "0.9.115",
4
4
  "description": "MyAgentRoam Node runtime CLI.",
5
5
  "license": "Apache-2.0 AND GPL-2.0-or-later",
6
6
  "type": "module",
@@ -30,9 +30,9 @@
30
30
  "npm": "11.12.1",
31
31
  "ws": "^8.21.3",
32
32
  "zod": "4.4.3",
33
- "@myagentroam/agent": "0.9.113",
34
- "@myagentroam/code-navigation": "0.9.113",
35
- "@myagentroam/protocol": "0.9.113"
33
+ "@myagentroam/agent": "0.9.115",
34
+ "@myagentroam/protocol": "0.9.115",
35
+ "@myagentroam/code-navigation": "0.9.115"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/ws": "^8.18.1"