@layernorm/overlay-agent-host 0.8.0 → 0.9.0

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 (48) hide show
  1. package/Dockerfile +0 -1
  2. package/LICENSE +176 -0
  3. package/README.md +7 -7
  4. package/dist/cli.js +1 -1
  5. package/dist/host-capabilities.d.ts +1 -1
  6. package/dist/host-capabilities.js +1 -1
  7. package/dist/keyed-lock.d.ts +2 -0
  8. package/dist/keyed-lock.d.ts.map +1 -0
  9. package/dist/keyed-lock.js +18 -0
  10. package/dist/keyed-lock.js.map +1 -0
  11. package/dist/local-tools-exec.d.ts +14 -1
  12. package/dist/local-tools-exec.d.ts.map +1 -1
  13. package/dist/local-tools-exec.js +68 -12
  14. package/dist/local-tools-exec.js.map +1 -1
  15. package/dist/local-tools-paths.d.ts +8 -0
  16. package/dist/local-tools-paths.d.ts.map +1 -1
  17. package/dist/local-tools-paths.js +6 -2
  18. package/dist/local-tools-paths.js.map +1 -1
  19. package/dist/local-tools-terminal.d.ts +12 -3
  20. package/dist/local-tools-terminal.d.ts.map +1 -1
  21. package/dist/local-tools-terminal.js +113 -8
  22. package/dist/local-tools-terminal.js.map +1 -1
  23. package/dist/local-tools.d.ts.map +1 -1
  24. package/dist/local-tools.js +10 -4
  25. package/dist/local-tools.js.map +1 -1
  26. package/dist/private-threads-context.js +3 -3
  27. package/dist/private-threads-context.js.map +1 -1
  28. package/dist/private-threads-models.d.ts +1 -9
  29. package/dist/private-threads-models.d.ts.map +1 -1
  30. package/dist/private-threads-models.js +0 -20
  31. package/dist/private-threads-models.js.map +1 -1
  32. package/dist/private-threads-protocol.d.ts +5 -34
  33. package/dist/private-threads-protocol.d.ts.map +1 -1
  34. package/dist/private-threads-protocol.js +7 -21
  35. package/dist/private-threads-protocol.js.map +1 -1
  36. package/dist/private-threads-title.d.ts +12 -0
  37. package/dist/private-threads-title.d.ts.map +1 -0
  38. package/dist/private-threads-title.js +47 -0
  39. package/dist/private-threads-title.js.map +1 -0
  40. package/dist/private-threads-tools.d.ts +3 -0
  41. package/dist/private-threads-tools.d.ts.map +1 -1
  42. package/dist/private-threads-tools.js +73 -8
  43. package/dist/private-threads-tools.js.map +1 -1
  44. package/dist/private-threads.d.ts +16 -7
  45. package/dist/private-threads.d.ts.map +1 -1
  46. package/dist/private-threads.js +83 -30
  47. package/dist/private-threads.js.map +1 -1
  48. package/package.json +3 -3
package/Dockerfile CHANGED
@@ -12,7 +12,6 @@ COPY packages ./packages
12
12
  # bun.lock covers every workspace; their manifests must be present to install from it.
13
13
  COPY apps/admin/package.json ./apps/admin/
14
14
  COPY apps/chrome/package.json ./apps/chrome/
15
- COPY apps/chrome/packages ./apps/chrome/packages
16
15
  COPY apps/desktop/package.json ./apps/desktop/
17
16
  COPY apps/mobile/package.json ./apps/mobile/
18
17
  RUN bun install --frozen-lockfile --production --filter @layernorm/overlay-agent-host \
package/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Business Source License 1.1
2
+
3
+ Parameters
4
+
5
+ Licensor: LayerNorm Inc.
6
+
7
+ Licensed Work: Overlay, meaning each version of the first-party
8
+ material in the Overlay repository
9
+ (https://github.com/LayerNorm/overlay) that LayerNorm
10
+ Inc. makes available under this License, including its
11
+ web app, backend, desktop, mobile and Chrome apps, Agent
12
+ Host and packages. Third-party material keeps its own
13
+ license.
14
+ The Licensed Work is (c) 2026 LayerNorm Inc.
15
+
16
+ Additional Use Grant: You may also make production use of the Licensed Work in
17
+ any of the five ways below. None of them includes a
18
+ Commercial Offering. This grant only adds to your rights
19
+ under this License. It does not limit non-production use.
20
+
21
+ 1. Personal use. You may use the Licensed Work as an
22
+ individual for your own personal purposes. Use for an
23
+ employer, a client or your own business is not
24
+ personal use.
25
+
26
+ 2. Small organizations. A Small Organization may use the
27
+ Licensed Work for its own internal operations.
28
+
29
+ 3. Growing past a limit. An organization that was using
30
+ the Licensed Work under section 2 and stops being a
31
+ Small Organization may continue that use for 60 days
32
+ from the date it stopped qualifying.
33
+
34
+ 4. Trial. Any organization may use the Licensed Work for
35
+ its own internal operations for one period of 30 days
36
+ in a row, starting on its first production use under
37
+ this section. An organization and its Affiliates share
38
+ one trial.
39
+
40
+ 5. Apps that connect to Overlay. Any individual or
41
+ organization may use the official Overlay desktop,
42
+ mobile and Chrome apps and Agent Host, as LayerNorm
43
+ Inc. distributes them, (a) with the Overlay service
44
+ that LayerNorm Inc. operates, under the terms of that
45
+ service, including for features of those apps that
46
+ run on the user's own device, or (b) with a
47
+ deployment whose use is allowed by this License or by
48
+ a commercial license from LayerNorm Inc. This section
49
+ does not allow anyone to run the Overlay web app or
50
+ backend.
51
+
52
+ An organization may have contractors install and run the
53
+ Licensed Work for it, and may run it on rented
54
+ infrastructure, if the contractor or provider uses it
55
+ only for that organization. That use counts as the
56
+ organization's use. An organization may also let guests
57
+ use its deployment to work with that organization.
58
+ Neither may be used to make a Commercial Offering.
59
+
60
+ Definitions for this grant:
61
+
62
+ "Affiliate" means any entity that controls, is controlled
63
+ by, or is under common control with an organization.
64
+ "Control" means owning more than half of an entity, or
65
+ the power to direct its management and policies.
66
+
67
+ "Commercial Offering" means selling, renting or
68
+ sublicensing the Licensed Work, or making its
69
+ functionality available to third parties as a hosted,
70
+ managed or embedded product or service, whether or not
71
+ there is a charge. Letting guests work with an
72
+ organization in its own deployment, as described above,
73
+ is not a Commercial Offering on its own.
74
+
75
+ "Organization" means any company, nonprofit, school,
76
+ government body or other entity, and any individual using
77
+ the Licensed Work for their own business, including as a
78
+ sole proprietor or freelancer.
79
+
80
+ "People" means everyone who works for an organization,
81
+ full time or part time, as an employee, a working owner
82
+ or an individual contractor, whether or not they use the
83
+ Licensed Work. Software agents are not People.
84
+
85
+ "Small Organization" means an organization that, together
86
+ with all its Affiliates, has both (a) fewer than 10
87
+ People and (b) less than US$100,000 in Total Revenue
88
+ during the previous 12 months.
89
+
90
+ "Total Revenue" means gross income from all sources
91
+ before expenses, including sales, grants, donations and
92
+ public funding. It does not include loans or money
93
+ raised by selling an ownership interest. Amounts in
94
+ other currencies are converted to US dollars.
95
+
96
+ Change Date: For each version of the Licensed Work, four years from
97
+ the date that version is first made publicly available
98
+ under this License.
99
+
100
+ Change License: GNU General Public License, version 3 or any later
101
+ version (GPL-3.0-or-later)
102
+
103
+ For production use that this License does not allow, contact
104
+ divyansh@layernorm.co to buy an Overlay self-host license.
105
+
106
+ -----------------------------------------------------------------------------
107
+
108
+ License text copyright © 2017 MariaDB Corporation Ab, All Rights Reserved.
109
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
110
+
111
+ Terms
112
+
113
+ The Licensor hereby grants you the right to copy, modify, create derivative
114
+ works, redistribute, and make non-production use of the Licensed Work. The
115
+ Licensor may make an Additional Use Grant, above, permitting limited
116
+ production use.
117
+
118
+ Effective on the Change Date, or the fourth anniversary of the first publicly
119
+ available distribution of a specific version of the Licensed Work under this
120
+ License, whichever comes first, the Licensor hereby grants you rights under
121
+ the terms of the Change License, and the rights granted in the paragraph
122
+ above terminate.
123
+
124
+ If your use of the Licensed Work does not comply with the requirements
125
+ currently in effect as described in this License, you must purchase a
126
+ commercial license from the Licensor, its affiliated entities, or authorized
127
+ resellers, or you must refrain from using the Licensed Work.
128
+
129
+ All copies of the original and modified Licensed Work, and derivative works
130
+ of the Licensed Work, are subject to this License. This License applies
131
+ separately for each version of the Licensed Work and the Change Date may vary
132
+ for each version of the Licensed Work released by Licensor.
133
+
134
+ You must conspicuously display this License on each original or modified copy
135
+ of the Licensed Work. If you receive the Licensed Work in original or
136
+ modified form from a third party, the terms and conditions set forth in this
137
+ License apply to your use of that work.
138
+
139
+ Any use of the Licensed Work in violation of this License will automatically
140
+ terminate your rights under this License for the current and all other
141
+ versions of the Licensed Work.
142
+
143
+ This License does not grant you any right in any trademark or logo of
144
+ Licensor or its affiliates (provided that you may use a trademark or logo of
145
+ Licensor as expressly required by this License).
146
+
147
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
148
+ AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
149
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
150
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
151
+ TITLE.
152
+
153
+ MariaDB hereby grants you permission to use this License’s text to license
154
+ your works, and to refer to it using the trademark “Business Source License”,
155
+ as long as you comply with the Covenants of Licensor below.
156
+
157
+ Covenants of Licensor
158
+
159
+ In consideration of the right to use this License’s text and the “Business
160
+ Source License” name and trademark, Licensor covenants to MariaDB, and to all
161
+ other recipients of the licensed work to be provided by Licensor:
162
+
163
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
164
+ or a license that is compatible with GPL Version 2.0 or a later version,
165
+ where “compatible” means that software provided under the Change License can
166
+ be included in a program with software provided under GPL Version 2.0 or a
167
+ later version. Licensor may specify additional Change Licenses without
168
+ limitation.
169
+
170
+ 2. To either: (a) specify an additional grant of rights to use that does not
171
+ impose any additional restriction on the right granted in this License, as
172
+ the Additional Use Grant; or (b) insert the text “None”.
173
+
174
+ 3. To specify a Change Date.
175
+
176
+ 4. Not to modify this License in any other way.
package/README.md CHANGED
@@ -8,7 +8,7 @@ Node.js 24 or newer is required. Overlay's one-copy command supplies a pinned No
8
8
  when the machine's default `node` is older:
9
9
 
10
10
  ```sh
11
- npx --yes --package node@24 --package @layernorm/overlay-agent-host@0.8.0 \
11
+ npx --yes --package node@24 --package @layernorm/overlay-agent-host@0.9.0 \
12
12
  overlay-agent-host connect <enrollment-code> \
13
13
  --server https://overlay.works \
14
14
  --kind vps \
@@ -78,7 +78,7 @@ network URL:
78
78
  The equivalent enrollment form is:
79
79
 
80
80
  ```sh
81
- npx --yes --package node@24 --package @layernorm/overlay-agent-host@0.8.0 \
81
+ npx --yes --package node@24 --package @layernorm/overlay-agent-host@0.9.0 \
82
82
  overlay-agent-host connect <enrollment-code> \
83
83
  --server https://overlay.works \
84
84
  --kind vps \
@@ -102,9 +102,9 @@ Terminal closes and returns after login or process failure. Use the exact config
102
102
  `connect`:
103
103
 
104
104
  ```sh
105
- npx --yes --package node@24 --package @layernorm/overlay-agent-host@0.8.0 \
105
+ npx --yes --package node@24 --package @layernorm/overlay-agent-host@0.9.0 \
106
106
  overlay-agent-host service install --config "$HOME/.overlay/agent-host/config.json"
107
- npx --yes --package node@24 --package @layernorm/overlay-agent-host@0.8.0 \
107
+ npx --yes --package node@24 --package @layernorm/overlay-agent-host@0.9.0 \
108
108
  overlay-agent-host service status --config "$HOME/.overlay/agent-host/config.json"
109
109
  ```
110
110
 
@@ -182,8 +182,8 @@ enrollment remains rejected.
182
182
 
183
183
  `overlay-agent-host private --state-dir <dir>` runs threads whose Cloud sync is off. Overlay Desktop starts it with a
184
184
  Node.js IPC channel; it opens no port, runs one AI SDK `ToolLoopAgent` per turn with this computer's tools, and calls
185
- the model the desktop names for that turn: a provider with the person's own key, a Claude or ChatGPT plan through the
186
- desktop's local CLIProxyAPI, or Overlay's metered model relay with a short-lived token. It keeps transcripts in
187
- `<dir>/private-threads.sqlite`. It
185
+ the model the desktop names for that turn: a provider with the person's own key, or Overlay's model relay (Overlay's models or
186
+ the agent's provider connection) with a short-lived token. It keeps transcripts in
187
+ `<dir>/private-threads.sqlite`, and asks the same model for a short title after a thread's first message. It
188
188
  also starts the person's local (stdio) MCP servers when a turn's agent may use them, and stops them when idle or on
189
189
  exit. It is not meant to be started by hand. See `internal/develop/private-threads.md` in the Overlay repository.
package/dist/cli.js CHANGED
@@ -13,7 +13,7 @@ import { AgentHostRuntime } from './runtime.js';
13
13
  import { assertSupportedNodeVersion } from './runtime-version.js';
14
14
  import { HttpAgentControlPlaneClient } from './transport.js';
15
15
  import { servePrivateThreads } from './private-threads-ipc.js';
16
- const PACKAGE_SPEC = '@layernorm/overlay-agent-host@0.8.0';
16
+ const PACKAGE_SPEC = '@layernorm/overlay-agent-host@0.9.0';
17
17
  assertSupportedNodeVersion();
18
18
  const [command, ...args] = process.argv.slice(2);
19
19
  const configPath = option(args, '--config');
@@ -1,5 +1,5 @@
1
1
  import { type FilesystemGrant, type HostCapabilities, type LocalToolsCapability } from '@layernorm/overlay-agent-bridge-protocol';
2
- export declare const AGENT_HOST_VERSION = "0.8.0";
2
+ export declare const AGENT_HOST_VERSION = "0.9.0";
3
3
  /** A host advertises only its local tools; it runs no agent harness. */
4
4
  export declare function buildHostCapabilities(options: {
5
5
  filesystem: FilesystemGrant;
@@ -1,6 +1,6 @@
1
1
  import { OVERLAY_AGENT_PROTOCOL_VERSION } from '@layernorm/overlay-agent-bridge-protocol';
2
2
  import { platform, release } from 'node:os';
3
- export const AGENT_HOST_VERSION = '0.8.0';
3
+ export const AGENT_HOST_VERSION = '0.9.0';
4
4
  /** A host advertises only its local tools; it runs no agent harness. */
5
5
  export function buildHostCapabilities(options) {
6
6
  return {
@@ -0,0 +1,2 @@
1
+ export declare function withKeyedLock<T>(key: string, work: () => Promise<T>): Promise<T>;
2
+ //# sourceMappingURL=keyed-lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyed-lock.d.ts","sourceRoot":"","sources":["../src/keyed-lock.ts"],"names":[],"mappings":"AAMA,wBAAsB,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAKtF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Runs work for the same key one at a time, in call order. Locks are shared by everything in this process, because
3
+ * synced threads and each private turn have their own LocalToolExecutor on the same files and sessions.
4
+ */
5
+ const tails = new Map();
6
+ export async function withKeyedLock(key, work) {
7
+ const result = (tails.get(key) ?? Promise.resolve()).then(work);
8
+ const tail = result.catch(() => undefined);
9
+ tails.set(key, tail);
10
+ try {
11
+ return await result;
12
+ }
13
+ finally {
14
+ if (tails.get(key) === tail)
15
+ tails.delete(key);
16
+ }
17
+ }
18
+ //# sourceMappingURL=keyed-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyed-lock.js","sourceRoot":"","sources":["../src/keyed-lock.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,KAAK,GAAG,IAAI,GAAG,EAA4B,CAAA;AAEjD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAI,GAAW,EAAE,IAAsB;IACxE,MAAM,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/D,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;IAC1C,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IACpB,IAAI,CAAC;QAAC,OAAO,MAAM,MAAM,CAAA;IAAC,CAAC;YAAS,CAAC;QAAC,IAAI,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI;YAAE,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAAC,CAAC;AACxF,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { FilesystemGrant, LocalExecResult, LocalListFilesResult, LocalReadFileResult } from '@layernorm/overlay-agent-bridge-protocol';
1
+ import { type FilesystemGrant, type LocalExecResult, type LocalListFilesResult, type LocalReadFileResult } from '@layernorm/overlay-agent-bridge-protocol';
2
2
  export declare const LOCAL_EXEC_MAX_OUTPUT_BYTES: number;
3
3
  /** The user's login shell, so commands see the same PATH (Homebrew, nvm, …) as their terminal. */
4
4
  export declare function localShell(): {
@@ -14,6 +14,7 @@ export declare function readLocalFile(grant: FilesystemGrant, input: {
14
14
  path: string;
15
15
  maxBytes: number;
16
16
  }): Promise<LocalReadFileResult>;
17
+ export declare function sha256(bytes: Uint8Array): string;
17
18
  export declare function writeLocalFile(grant: FilesystemGrant, input: {
18
19
  path: string;
19
20
  contentsBase64: string;
@@ -21,6 +22,18 @@ export declare function writeLocalFile(grant: FilesystemGrant, input: {
21
22
  path: string;
22
23
  bytes: number;
23
24
  }>;
25
+ /**
26
+ * Saves a file only if it still has the revision the caller read. The lock covers Overlay's own file tools; another
27
+ * program can still save in the moment between the last check and the rename.
28
+ */
29
+ export declare function replaceLocalFile(grant: FilesystemGrant, input: {
30
+ path: string;
31
+ contentsBase64: string;
32
+ expectedRevision: string;
33
+ }): Promise<{
34
+ path: string;
35
+ bytes: number;
36
+ }>;
24
37
  export declare function listLocalFiles(grant: FilesystemGrant, input: {
25
38
  path: string;
26
39
  }): Promise<LocalListFilesResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"local-tools-exec.d.ts","sourceRoot":"","sources":["../src/local-tools-exec.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAA;AAI3I,eAAO,MAAM,2BAA2B,QAAa,CAAA;AAGrD,kGAAkG;AAClG,wBAAgB,UAAU,IAAI;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,EAAE,CAAA;CAAE,CAIpF;AAmBD,wBAAsB,YAAY,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC,CAqCtK;AAMD,wBAAsB,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAWnI;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE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,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAUtJ;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,eAAe,EACtB,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,GACxE,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAoB1C;AAED,wBAAsB,cAAc,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAanH"}
@@ -1,8 +1,11 @@
1
1
  import { spawn } from 'node:child_process';
2
- import { mkdir, readdir, lstat, open, rename, writeFile } from 'node:fs/promises';
3
- import { dirname, join, basename } from 'node:path';
2
+ import { createHash, randomUUID } from 'node:crypto';
3
+ import { mkdir, readdir, readFile, lstat, open, rename, rm } from 'node:fs/promises';
4
+ import { dirname, join } from 'node:path';
5
+ import { COMPUTER_TEXT_MAX_BYTES, } from '@layernorm/overlay-agent-bridge-protocol';
6
+ import { withKeyedLock } from './keyed-lock.js';
4
7
  import { LocalToolFailure } from './local-tools-errors.js';
5
- import { resolveLocalToolPath, resolveLocalWorkingDirectory } from './local-tools-paths.js';
8
+ import { realLocation, resolveLocalToolPath, resolveLocalWorkingDirectory, unresolvedLocalToolPath } from './local-tools-paths.js';
6
9
  export const LOCAL_EXEC_MAX_OUTPUT_BYTES = 256 * 1024;
7
10
  const LIST_LIMIT = 500;
8
11
  /** The user's login shell, so commands see the same PATH (Homebrew, nvm, …) as their terminal. */
@@ -96,18 +99,71 @@ export async function readLocalFile(grant, input) {
96
99
  await handle.close();
97
100
  }
98
101
  }
102
+ export function sha256(bytes) {
103
+ return createHash('sha256').update(bytes).digest('hex');
104
+ }
105
+ /** One lock per real file, so two spellings of a path (or a linked folder) cannot be saved at the same time. */
106
+ async function withFileLock(path, work) {
107
+ return await withKeyedLock(`file:${await realLocation(path)}`, work);
108
+ }
109
+ /** Writes beside the target and renames, so a failed write never leaves a half-written file. */
110
+ async function saveFile(path, bytes, mode, beforeRename) {
111
+ const temporary = join(dirname(path), `.overlay-${randomUUID()}.tmp`);
112
+ try {
113
+ const handle = await open(temporary, 'wx', 0o600);
114
+ try {
115
+ await handle.writeFile(bytes);
116
+ await handle.chmod(mode);
117
+ }
118
+ finally {
119
+ await handle.close();
120
+ }
121
+ await beforeRename?.();
122
+ await rename(temporary, path);
123
+ }
124
+ finally {
125
+ await rm(temporary, { force: true });
126
+ }
127
+ }
99
128
  export async function writeLocalFile(grant, input) {
100
129
  const path = await resolveLocalToolPath(grant, input.path, 'write');
101
- const existing = await lstat(path).catch(() => null);
102
- if (existing && !existing.isFile())
103
- throw new LocalToolFailure('invalid_input', `${input.path} is not a file.`);
104
130
  const bytes = Buffer.from(input.contentsBase64, 'base64');
105
- await mkdir(dirname(path), { recursive: true });
106
- // Write beside the target and rename, so a failed write never leaves a half-written file.
107
- const temporary = join(dirname(path), `.${basename(path)}.overlay-${process.pid}-${Date.now()}.tmp`);
108
- await writeFile(temporary, bytes, { mode: existing ? existing.mode & 0o777 : 0o644 });
109
- await rename(temporary, path);
110
- return { path, bytes: bytes.length };
131
+ return await withFileLock(path, async () => {
132
+ const existing = await lstat(path).catch(() => null);
133
+ if (existing && !existing.isFile())
134
+ throw new LocalToolFailure('invalid_input', `${input.path} is not a file.`);
135
+ await mkdir(dirname(path), { recursive: true });
136
+ await saveFile(path, bytes, existing ? existing.mode & 0o777 : 0o644);
137
+ return { path, bytes: bytes.length };
138
+ });
139
+ }
140
+ /**
141
+ * Saves a file only if it still has the revision the caller read. The lock covers Overlay's own file tools; another
142
+ * program can still save in the moment between the last check and the rename.
143
+ */
144
+ export async function replaceLocalFile(grant, input) {
145
+ const bytes = Buffer.from(input.contentsBase64, 'base64');
146
+ const resolved = await resolveLocalToolPath(grant, input.path, 'write');
147
+ return await withFileLock(resolved, async () => {
148
+ // Resolved again under the lock: a folder may have become a link to somewhere that isn't approved.
149
+ const path = await resolveLocalToolPath(grant, input.path, 'write');
150
+ if (path !== resolved)
151
+ throw new LocalToolFailure('stale_revision', `${input.path} changed since it was read.`);
152
+ const named = await lstat(unresolvedLocalToolPath(grant, input.path)).catch(() => null);
153
+ const existing = await lstat(path).catch(() => null);
154
+ if (!named || !existing)
155
+ throw new LocalToolFailure('not_found', `No file at ${input.path}.`);
156
+ if (!named.isFile() || !existing.isFile())
157
+ throw new LocalToolFailure('invalid_input', `${input.path} is a link or is not a regular file. Edit the real file instead.`);
158
+ await saveFile(path, bytes, existing.mode & 0o777, async () => {
159
+ const current = await lstat(path).catch(() => null);
160
+ if (!current?.isFile() || current.size > COMPUTER_TEXT_MAX_BYTES
161
+ || sha256(await readFile(path)) !== input.expectedRevision) {
162
+ throw new LocalToolFailure('stale_revision', `${input.path} changed since it was read.`);
163
+ }
164
+ });
165
+ return { path, bytes: bytes.length };
166
+ });
111
167
  }
112
168
  export async function listLocalFiles(grant, input) {
113
169
  const path = await resolveLocalToolPath(grant, input.path, 'read');
@@ -1 +1 @@
1
- {"version":3,"file":"local-tools-exec.js","sourceRoot":"","sources":["../src/local-tools-exec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACjF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB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,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;IAC/D,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QACzD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAC9B,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;QAClD,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,OAAgB,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,WAAoB,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,MAAe,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,SAAkB,CAAC,CAAC,CAAC,OAAgB,CAAA;QACvL,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAA;IAChF,CAAC,CAAC,CAAC,CAAA;IACH,OAAO,EAAE,OAAO,EAAE,CAAA;AACpB,CAAC"}
@@ -2,6 +2,14 @@ import type { FilesystemGrant } from '@layernorm/overlay-agent-bridge-protocol';
2
2
  /** The directory relative paths resolve against: the first approved root, or home for an all-files grant. */
3
3
  export declare function localToolsBaseDirectory(grant: FilesystemGrant): string;
4
4
  export declare function expandHome(path: string): string;
5
+ /**
6
+ * Real location of a path that may not exist yet: the nearest existing
7
+ * ancestor is resolved through symlinks and the missing tail is appended, so a
8
+ * write into a new folder is checked against where it will actually land.
9
+ */
10
+ export declare function realLocation(path: string): Promise<string>;
11
+ /** The path as it was named, before links are followed. Not checked against the grant. */
12
+ export declare function unresolvedLocalToolPath(grant: FilesystemGrant, input: string): string;
5
13
  /**
6
14
  * Resolves a model-supplied path and enforces the approved roots. Symlinks are
7
15
  * followed before the check, so a link inside a root cannot reach outside it.
@@ -1 +1 @@
1
- {"version":3,"file":"local-tools-paths.d.ts","sourceRoot":"","sources":["../src/local-tools-paths.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAA;AAG/E,6GAA6G;AAC7G,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAEtE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/C;AA+BD;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAQzH;AAOD,0EAA0E;AAC1E,wBAAsB,4BAA4B,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAKrH"}
1
+ {"version":3,"file":"local-tools-paths.d.ts","sourceRoot":"","sources":["../src/local-tools-paths.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAA;AAG/E,6GAA6G;AAC7G,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAEtE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/C;AAeD;;;;GAIG;AACH,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAShE;AAED,0FAA0F;AAC1F,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAErF;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAQzH;AAOD,0EAA0E;AAC1E,wBAAsB,4BAA4B,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAKrH"}
@@ -32,7 +32,7 @@ async function realRoots(grant) {
32
32
  * ancestor is resolved through symlinks and the missing tail is appended, so a
33
33
  * write into a new folder is checked against where it will actually land.
34
34
  */
35
- async function realLocation(path) {
35
+ export async function realLocation(path) {
36
36
  let current = path;
37
37
  for (;;) {
38
38
  try {
@@ -46,13 +46,17 @@ async function realLocation(path) {
46
46
  }
47
47
  }
48
48
  }
49
+ /** The path as it was named, before links are followed. Not checked against the grant. */
50
+ export function unresolvedLocalToolPath(grant, input) {
51
+ return resolve(localToolsBaseDirectory(grant), expandHome(input));
52
+ }
49
53
  /**
50
54
  * Resolves a model-supplied path and enforces the approved roots. Symlinks are
51
55
  * followed before the check, so a link inside a root cannot reach outside it.
52
56
  * Approved roots are a scope, not an operating-system sandbox.
53
57
  */
54
58
  export async function resolveLocalToolPath(grant, input, mode) {
55
- const absolute = resolve(localToolsBaseDirectory(grant), expandHome(input));
59
+ const absolute = unresolvedLocalToolPath(grant, input);
56
60
  if (grant.mode === 'all_user_files')
57
61
  return absolute;
58
62
  const roots = await realRoots(grant);
@@ -1 +1 @@
1
- {"version":3,"file":"local-tools-paths.js","sourceRoot":"","sources":["../src/local-tools-paths.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAElE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AO,IAAI,CAAA;AACb,CAAC"}
@@ -1,4 +1,5 @@
1
- import type { FilesystemGrant } from '@layernorm/overlay-agent-bridge-protocol';
1
+ import { type FilesystemGrant } from '@layernorm/overlay-agent-bridge-protocol';
2
+ export declare function localTerminalsRoot(stateDirectory: string): string;
2
3
  export declare class LocalTerminals {
3
4
  private readonly root;
4
5
  private starting;
@@ -11,9 +12,17 @@ export declare class LocalTerminals {
11
12
  private ids;
12
13
  start(grant: FilesystemGrant, request: Record<string, unknown>): Promise<Record<string, unknown>>;
13
14
  read(request: Record<string, unknown>): Promise<Record<string, unknown>>;
15
+ /** Bytes of input this session has accepted, or null when it doesn't take input. */
16
+ private inputOffset;
17
+ private saveInputOffset;
18
+ /**
19
+ * Types into an interactive session, at most once. The new offset is saved before the text is sent, so after a crash
20
+ * the text may be lost but a repeated call is refused. It is put back only when nothing can have been sent.
21
+ */
22
+ write(request: Record<string, unknown>): Promise<Record<string, unknown>>;
14
23
  cancel(request: Record<string, unknown>): Promise<Record<string, unknown>>;
15
24
  list(): Promise<Record<string, unknown>>;
16
- /** Stop every running session, for host shutdown and sign-out. */
17
- stopAll(): Promise<void>;
25
+ /** Stop the given sessions, or every one for host shutdown and sign-out. */
26
+ stopAll(ids?: Iterable<string>): Promise<void>;
18
27
  }
19
28
  //# sourceMappingURL=local-tools-terminal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"local-tools-terminal.d.ts","sourceRoot":"","sources":["../src/local-tools-terminal.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAA;AAe/E,qBAAa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAsC;gBAEzB,IAAI,EAAE,MAAM;IAEzC,OAAO,CAAC,SAAS;YAKH,IAAI;YAOJ,QAAQ;IAQtB,OAAO,CAAC,MAAM,CAAC,YAAY;YAIb,OAAO;YAIP,GAAG;IAIX,KAAK,CA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