@vellumai/assistant 0.12.5-dev.202609251619.e268c7d → 0.12.5-dev.202609251714.4e37a15

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/ARCHITECTURE.md +4 -0
  2. package/node_modules/@vellumai/environments/src/shell.test.ts +13 -1
  3. package/node_modules/@vellumai/environments/src/shell.ts +22 -1
  4. package/openapi.yaml +174 -1
  5. package/package.json +1 -1
  6. package/src/__tests__/document-append-idempotency.test.ts +13 -0
  7. package/src/__tests__/document-create-dedupe.test.ts +13 -0
  8. package/src/__tests__/document-find-replace.test.ts +13 -0
  9. package/src/__tests__/document-revision-history.test.ts +390 -0
  10. package/src/__tests__/document-revision.test.ts +425 -0
  11. package/src/__tests__/document-tool-security.test.ts +13 -0
  12. package/src/__tests__/document-update-default-surface.test.ts +13 -0
  13. package/src/__tests__/host-shell-tool.test.ts +6 -2
  14. package/src/acp/agent-process.ts +6 -1
  15. package/src/acp/client-handler.ts +6 -1
  16. package/src/api/events/document-editor-show.ts +5 -0
  17. package/src/api/events/document-editor-update.ts +10 -0
  18. package/src/daemon/lifecycle.ts +11 -1
  19. package/src/desktop/desktop-session-manager.ts +4 -2
  20. package/src/documents/document-revisions-store.ts +153 -0
  21. package/src/documents/document-store.ts +471 -133
  22. package/src/monitoring/__tests__/oom-inheritance-sweep.test.ts +86 -0
  23. package/src/monitoring/control.ts +2 -1
  24. package/src/monitoring/oom-inheritance-sweep.ts +96 -0
  25. package/src/monitoring/resource-sampler.ts +22 -0
  26. package/src/persistence/embeddings/embed.test.ts +96 -0
  27. package/src/persistence/embeddings/embed.ts +20 -2
  28. package/src/persistence/embeddings/embedding-gemini.test.ts +39 -3
  29. package/src/persistence/embeddings/embedding-gemini.ts +39 -1
  30. package/src/persistence/embeddings/embedding-local.ts +6 -0
  31. package/src/persistence/embeddings/qdrant-manager.ts +5 -0
  32. package/src/persistence/migrations/384-add-document-revision.test.ts +83 -0
  33. package/src/persistence/migrations/384-add-document-revision.ts +21 -0
  34. package/src/persistence/migrations/385-create-document-revisions.test.ts +67 -0
  35. package/src/persistence/migrations/385-create-document-revisions.ts +28 -0
  36. package/src/persistence/schema/documents.ts +20 -0
  37. package/src/persistence/steps.ts +4 -0
  38. package/src/plugins/defaults/empty-response/hooks/post-model-call.ts +11 -6
  39. package/src/runtime/routes/documents-routes.ts +185 -47
  40. package/src/tools/document/document-tool.ts +13 -11
  41. package/src/util/__tests__/oom-priority.test.ts +55 -0
  42. package/src/util/oom-priority.ts +79 -0
  43. package/src/util/worker-process.ts +8 -0
package/ARCHITECTURE.md CHANGED
@@ -45,6 +45,10 @@ Resource pressure monitoring reports sustained CPU/memory pressure on platform-h
45
45
 
46
46
  **Lifecycle:** `src/daemon/resource-pressure-guard-lifecycle.ts` starts the guard at daemon boot with the first sample deferred onto a macrotask so it never blocks startup, and stops the guard (cancelling any pending deferred sample) on shutdown. The web chat banner built on this status is documented in the repo-level [`/ARCHITECTURE.md`](../ARCHITECTURE.md) "Resource Pressure Monitoring" section.
47
47
 
48
+ ### OOM Priority
49
+
50
+ When the container hits its memory limit, the kernel kills the process with the highest `oom_score` (memory share plus `oom_score_adj`). `src/util/oom-priority.ts` steers that choice so the assistant is never the victim of a runaway tool: the daemon sets itself to -700 as the first thing in `runDaemon`, before any spawn. Children inherit the parent's value at fork, so every spawn path resets its child: shell children get +1000 from the Linux prefix in `buildShellInvocation` (`packages/environments`), desktop children and ACP agents and terminals get +1000 from `withOomScoreAdj`, an `sh -c ... exec` wrapper that keeps pid and process group, and workers, the embedding worker, and Qdrant get 0 from a parent-side write right after spawn (the resource monitor gets -500 so it outlives everything but the daemon and records the kill). The monitor also sweeps the daemon's descendants every few seconds (`src/monitoring/oom-inheritance-sweep.ts`) and writes 0 over any negative value it finds, logging the comm, so a spawn path that forgets the reset degrades to a few seconds of inherited protection instead of a protected runaway. Bundled plugins (the memory plugin's rerank worker, for one) rely on the sweep rather than importing the helper, since the plugin import boundary forbids reaching outside the plugin. Raising never needs a capability; lowering needs `CAP_SYS_RESOURCE`, which the platform grants and self-hosted Docker does not, where the daemon simply stays at 0. Nothing here caps a single process or acts early: it only decides who dies once the kernel has to kill.
51
+
48
52
  ### Single-Header JWT Auth Model
49
53
 
50
54
  All HTTP API requests use a single `Authorization: Bearer <jwt>` header for authentication. The JWT carries identity, permissions, and policy versioning in a unified token.
@@ -3,18 +3,30 @@ import { describe, expect, test } from "bun:test";
3
3
  import {
4
4
  buildShellInvocation,
5
5
  buildShellSpawnFlags,
6
+ CHILD_OOM_SCORE_ADJ,
6
7
  pathListDelimiter,
7
8
  prependUniquePathEntries,
8
9
  } from "./shell.js";
9
10
 
10
11
  describe("buildShellInvocation", () => {
11
12
  test("uses Bash on POSIX hosts", () => {
12
- expect(buildShellInvocation("printf hello", "linux")).toEqual({
13
+ expect(buildShellInvocation("printf hello", "darwin")).toEqual({
13
14
  command: "bash",
14
15
  args: ["-c", "--", "printf hello"],
15
16
  });
16
17
  });
17
18
 
19
+ test("raises the shell's OOM-kill priority on Linux", () => {
20
+ expect(buildShellInvocation("printf hello", "linux")).toEqual({
21
+ command: "bash",
22
+ args: [
23
+ "-c",
24
+ "--",
25
+ `echo ${CHILD_OOM_SCORE_ADJ} 2>/dev/null >/proc/self/oom_score_adj; printf hello`,
26
+ ],
27
+ });
28
+ });
29
+
18
30
  test("uses encoded non-interactive PowerShell on Windows", () => {
19
31
  const invocation = buildShellInvocation(
20
32
  "Write-Output 'hello 世界'",
@@ -24,6 +24,23 @@ if (-not $__vellumCommandSucceeded) {
24
24
  }
25
25
  exit 0`;
26
26
 
27
+ /**
28
+ * `oom_score_adj` for assistant-owned tool processes. Any positive value
29
+ * outranks a 0-scored process; 1000 makes a tool the kernel's first choice
30
+ * whenever the container runs out of memory, so the assistant itself is never
31
+ * the victim of a runaway command.
32
+ */
33
+ export const CHILD_OOM_SCORE_ADJ = 1000;
34
+
35
+ /**
36
+ * Prefix for a Bash `-c` script that raises the shell's own OOM-kill priority
37
+ * before the command runs. Every process the command forks inherits it. Bash
38
+ * performs a builtin's redirection itself, so `/proc/self` is the shell.
39
+ * Redirections apply left to right, so stderr goes to /dev/null before the
40
+ * procfs open can fail and complain about it.
41
+ */
42
+ const LINUX_OOM_SCORE_ADJ_PREFIX = `echo ${CHILD_OOM_SCORE_ADJ} 2>/dev/null >/proc/self/oom_score_adj; `;
43
+
27
44
  export function buildShellInvocation(
28
45
  command: string,
29
46
  hostPlatform: NodeJS.Platform = process.platform,
@@ -45,7 +62,11 @@ export function buildShellInvocation(
45
62
  ],
46
63
  };
47
64
  }
48
- return { command: "bash", args: ["-c", "--", command] };
65
+ const script =
66
+ hostPlatform === "linux"
67
+ ? `${LINUX_OOM_SCORE_ADJ_PREFIX}${command}`
68
+ : command;
69
+ return { command: "bash", args: ["-c", "--", script] };
49
70
  }
50
71
 
51
72
  /**
package/openapi.yaml CHANGED
@@ -12482,6 +12482,9 @@ paths:
12482
12482
  type: number
12483
12483
  updatedAt:
12484
12484
  type: number
12485
+ revision:
12486
+ description: Bumped by one on every write. Absent from assistants that predate document revisions.
12487
+ type: number
12485
12488
  required:
12486
12489
  - surfaceId
12487
12490
  - conversationId
@@ -12496,7 +12499,10 @@ paths:
12496
12499
  post:
12497
12500
  operationId: documents_post
12498
12501
  summary: Save a document
12499
- description: Create or upsert a document (by surfaceId).
12502
+ description:
12503
+ Create or upsert a document (by surfaceId). With `baseRevision`, an existing document is only overwritten
12504
+ while its revision still equals `baseRevision`; otherwise the save is rejected with 409 CONFLICT and
12505
+ `error.details` carries the current `revision`, `title`, and `content`.
12500
12506
  tags:
12501
12507
  - documents
12502
12508
  requestBody:
@@ -12521,6 +12527,13 @@ paths:
12521
12527
  wordCount:
12522
12528
  type: number
12523
12529
  description: Word count
12530
+ baseRevision:
12531
+ description:
12532
+ The revision this save was edited from. When set and the stored revision differs, nothing is written and
12533
+ the request fails with 409. Omit for an unconditional write.
12534
+ type: integer
12535
+ minimum: 0
12536
+ maximum: 9007199254740991
12524
12537
  required:
12525
12538
  - surfaceId
12526
12539
  - conversationId
@@ -12540,6 +12553,9 @@ paths:
12540
12553
  const: true
12541
12554
  surfaceId:
12542
12555
  type: string
12556
+ revision:
12557
+ description: The document's revision after the save. Absent from assistants that predate document revisions.
12558
+ type: number
12543
12559
  required:
12544
12560
  - success
12545
12561
  - surfaceId
@@ -12581,6 +12597,9 @@ paths:
12581
12597
  type: number
12582
12598
  updatedAt:
12583
12599
  type: number
12600
+ revision:
12601
+ description: Bumped by one on every write. Absent from assistants that predate document revisions.
12602
+ type: number
12584
12603
  required:
12585
12604
  - success
12586
12605
  - surfaceId
@@ -13007,6 +13026,157 @@ paths:
13007
13026
  schema:
13008
13027
  type: string
13009
13028
  format: binary
13029
+ /v1/documents/{id}/revisions:
13030
+ get:
13031
+ operationId: documents_by_id_revisions_get
13032
+ summary: List a document's revisions
13033
+ description: Return the document's history snapshots, newest first, without their content.
13034
+ tags:
13035
+ - documents
13036
+ parameters:
13037
+ - name: id
13038
+ in: path
13039
+ required: true
13040
+ schema:
13041
+ type: string
13042
+ responses:
13043
+ "200":
13044
+ description: Successful response
13045
+ content:
13046
+ application/json:
13047
+ schema:
13048
+ type: object
13049
+ properties:
13050
+ revisions:
13051
+ type: array
13052
+ items:
13053
+ type: object
13054
+ properties:
13055
+ revision:
13056
+ type: number
13057
+ description: The document revision this snapshot holds
13058
+ author:
13059
+ type: string
13060
+ enum:
13061
+ - user
13062
+ - assistant
13063
+ description: Who made the edit that replaced this state
13064
+ createdAt:
13065
+ type: number
13066
+ description: When the snapshot was taken
13067
+ wordCount:
13068
+ type: number
13069
+ title:
13070
+ type: string
13071
+ required:
13072
+ - revision
13073
+ - author
13074
+ - createdAt
13075
+ - wordCount
13076
+ - title
13077
+ additionalProperties: false
13078
+ required:
13079
+ - revisions
13080
+ additionalProperties: false
13081
+ /v1/documents/{id}/revisions/{revision}:
13082
+ get:
13083
+ operationId: documents_by_id_revisions_by_revision_get
13084
+ summary: Get a document revision
13085
+ description: Return one history snapshot with its content.
13086
+ tags:
13087
+ - documents
13088
+ parameters:
13089
+ - name: id
13090
+ in: path
13091
+ required: true
13092
+ schema:
13093
+ type: string
13094
+ - name: revision
13095
+ in: path
13096
+ required: true
13097
+ schema:
13098
+ type: string
13099
+ responses:
13100
+ "200":
13101
+ description: Successful response
13102
+ content:
13103
+ application/json:
13104
+ schema:
13105
+ type: object
13106
+ properties:
13107
+ revision:
13108
+ type: number
13109
+ description: The document revision this snapshot holds
13110
+ author:
13111
+ type: string
13112
+ enum:
13113
+ - user
13114
+ - assistant
13115
+ description: Who made the edit that replaced this state
13116
+ createdAt:
13117
+ type: number
13118
+ description: When the snapshot was taken
13119
+ wordCount:
13120
+ type: number
13121
+ title:
13122
+ type: string
13123
+ content:
13124
+ type: string
13125
+ required:
13126
+ - revision
13127
+ - author
13128
+ - createdAt
13129
+ - wordCount
13130
+ - title
13131
+ - content
13132
+ additionalProperties: false
13133
+ /v1/documents/{id}/revisions/{revision}/restore:
13134
+ post:
13135
+ operationId: documents_by_id_revisions_by_revision_restore_post
13136
+ summary: Restore a document revision
13137
+ description:
13138
+ Write a snapshot's title and content back as a new revision. The current state is snapshotted first, so the
13139
+ restore can itself be undone.
13140
+ tags:
13141
+ - documents
13142
+ parameters:
13143
+ - name: id
13144
+ in: path
13145
+ required: true
13146
+ schema:
13147
+ type: string
13148
+ - name: revision
13149
+ in: path
13150
+ required: true
13151
+ schema:
13152
+ type: string
13153
+ responses:
13154
+ "200":
13155
+ description: Successful response
13156
+ content:
13157
+ application/json:
13158
+ schema:
13159
+ type: object
13160
+ properties:
13161
+ success:
13162
+ type: boolean
13163
+ const: true
13164
+ surfaceId:
13165
+ type: string
13166
+ revision:
13167
+ type: number
13168
+ description: The document's revision after the restore
13169
+ title:
13170
+ type: string
13171
+ content:
13172
+ type: string
13173
+ required:
13174
+ - success
13175
+ - surfaceId
13176
+ - revision
13177
+ - title
13178
+ - content
13179
+ additionalProperties: false
13010
13180
  /v1/documents/create:
13011
13181
  post:
13012
13182
  operationId: documents_create_post
@@ -13053,6 +13223,9 @@ paths:
13053
13223
  type: number
13054
13224
  updatedAt:
13055
13225
  type: number
13226
+ revision:
13227
+ description: Bumped by one on every write. Absent from assistants that predate document revisions.
13228
+ type: number
13056
13229
  required:
13057
13230
  - success
13058
13231
  - surfaceId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/assistant",
3
- "version": "0.12.5-dev.202609251619.e268c7d",
3
+ "version": "0.12.5-dev.202609251714.4e37a15",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -35,6 +35,7 @@ function bootstrapDocumentTables(): void {
35
35
  const raw = getSqlite();
36
36
  raw.exec(/*sql*/ `
37
37
  DROP TABLE IF EXISTS document_conversations;
38
+ DROP TABLE IF EXISTS document_revisions;
38
39
  DROP TABLE IF EXISTS documents;
39
40
  DROP TABLE IF EXISTS conversations;
40
41
 
@@ -51,9 +52,21 @@ function bootstrapDocumentTables(): void {
51
52
  word_count INTEGER NOT NULL DEFAULT 0,
52
53
  created_at INTEGER NOT NULL,
53
54
  updated_at INTEGER NOT NULL,
55
+ revision INTEGER NOT NULL DEFAULT 0,
54
56
  workspace_path TEXT
55
57
  );
56
58
 
59
+ CREATE TABLE document_revisions (
60
+ surface_id TEXT NOT NULL REFERENCES documents(surface_id) ON DELETE CASCADE,
61
+ revision INTEGER NOT NULL,
62
+ title TEXT NOT NULL,
63
+ content TEXT NOT NULL,
64
+ word_count INTEGER NOT NULL DEFAULT 0,
65
+ author TEXT NOT NULL,
66
+ created_at INTEGER NOT NULL,
67
+ PRIMARY KEY (surface_id, revision)
68
+ );
69
+
57
70
  CREATE TABLE document_conversations (
58
71
  surface_id TEXT NOT NULL,
59
72
  conversation_id TEXT NOT NULL,
@@ -29,6 +29,7 @@ function bootstrapDocumentTables(): void {
29
29
  const raw = getSqlite();
30
30
  raw.exec(/*sql*/ `
31
31
  DROP TABLE IF EXISTS document_conversations;
32
+ DROP TABLE IF EXISTS document_revisions;
32
33
  DROP TABLE IF EXISTS documents;
33
34
  DROP TABLE IF EXISTS conversations;
34
35
 
@@ -45,9 +46,21 @@ function bootstrapDocumentTables(): void {
45
46
  word_count INTEGER NOT NULL DEFAULT 0,
46
47
  created_at INTEGER NOT NULL,
47
48
  updated_at INTEGER NOT NULL,
49
+ revision INTEGER NOT NULL DEFAULT 0,
48
50
  workspace_path TEXT
49
51
  );
50
52
 
53
+ CREATE TABLE document_revisions (
54
+ surface_id TEXT NOT NULL REFERENCES documents(surface_id) ON DELETE CASCADE,
55
+ revision INTEGER NOT NULL,
56
+ title TEXT NOT NULL,
57
+ content TEXT NOT NULL,
58
+ word_count INTEGER NOT NULL DEFAULT 0,
59
+ author TEXT NOT NULL,
60
+ created_at INTEGER NOT NULL,
61
+ PRIMARY KEY (surface_id, revision)
62
+ );
63
+
51
64
  CREATE TABLE document_conversations (
52
65
  surface_id TEXT NOT NULL,
53
66
  conversation_id TEXT NOT NULL,
@@ -28,6 +28,7 @@ function bootstrapDocumentTables(): void {
28
28
  const raw = getSqlite();
29
29
  raw.exec(/*sql*/ `
30
30
  DROP TABLE IF EXISTS document_conversations;
31
+ DROP TABLE IF EXISTS document_revisions;
31
32
  DROP TABLE IF EXISTS documents;
32
33
  DROP TABLE IF EXISTS conversations;
33
34
 
@@ -44,9 +45,21 @@ function bootstrapDocumentTables(): void {
44
45
  word_count INTEGER NOT NULL DEFAULT 0,
45
46
  created_at INTEGER NOT NULL,
46
47
  updated_at INTEGER NOT NULL,
48
+ revision INTEGER NOT NULL DEFAULT 0,
47
49
  workspace_path TEXT
48
50
  );
49
51
 
52
+ CREATE TABLE document_revisions (
53
+ surface_id TEXT NOT NULL REFERENCES documents(surface_id) ON DELETE CASCADE,
54
+ revision INTEGER NOT NULL,
55
+ title TEXT NOT NULL,
56
+ content TEXT NOT NULL,
57
+ word_count INTEGER NOT NULL DEFAULT 0,
58
+ author TEXT NOT NULL,
59
+ created_at INTEGER NOT NULL,
60
+ PRIMARY KEY (surface_id, revision)
61
+ );
62
+
50
63
  CREATE TABLE document_conversations (
51
64
  surface_id TEXT NOT NULL,
52
65
  conversation_id TEXT NOT NULL,