@myagentroam/node 0.1.4 → 0.1.7

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 (210) hide show
  1. package/README.md +9 -1
  2. package/dist/capabilities.d.ts +2 -0
  3. package/dist/capabilities.js +15 -4
  4. package/dist/claude-agent-sdk.d.ts +3 -1
  5. package/dist/claude-agent-sdk.js +9 -2
  6. package/dist/claude-channel.js +0 -1
  7. package/dist/codex-app-server.d.ts +1 -0
  8. package/dist/codex-app-server.js +8 -1
  9. package/dist/config.d.ts +3 -0
  10. package/dist/config.js +18 -2
  11. package/dist/connector/node-connector-options.d.ts +3 -0
  12. package/dist/connector/node-connector-options.js +0 -1
  13. package/dist/connector/node-operation-router.js +0 -1
  14. package/dist/connector.d.ts +3 -0
  15. package/dist/connector.js +109 -7
  16. package/dist/control-outbound-scheduler.js +0 -1
  17. package/dist/database.d.ts +4 -0
  18. package/dist/database.js +14 -9
  19. package/dist/event-buffer.js +0 -1
  20. package/dist/fake-runner.js +0 -1
  21. package/dist/health.js +0 -1
  22. package/dist/main.js +6 -1
  23. package/dist/migrations/v001.js +0 -1
  24. package/dist/migrations/v002.js +0 -1
  25. package/dist/migrations/v003.d.ts +4 -0
  26. package/dist/migrations/v003.js +44 -0
  27. package/dist/native-jsonl-reader.js +0 -1
  28. package/dist/native-session-history.d.ts +19 -1
  29. package/dist/native-session-history.js +65 -3
  30. package/dist/opencode-runtime.d.ts +33 -0
  31. package/dist/opencode-runtime.js +80 -0
  32. package/dist/opencode-server.d.ts +47 -0
  33. package/dist/opencode-server.js +250 -0
  34. package/dist/operational.js +10 -3
  35. package/dist/process-tree.js +0 -1
  36. package/dist/runner/abstract-runner.d.ts +7 -2
  37. package/dist/runner/abstract-runner.js +17 -2
  38. package/dist/runner/claude/managed-run-controller.js +20 -1
  39. package/dist/runner/claude-code-runner.d.ts +3 -1
  40. package/dist/runner/claude-code-runner.js +26 -8
  41. package/dist/runner/codex/conversation-parser.d.ts +1 -3
  42. package/dist/runner/codex/conversation-parser.js +174 -34
  43. package/dist/runner/codex/managed-run-controller.d.ts +2 -1
  44. package/dist/runner/codex/managed-run-controller.js +13 -4
  45. package/dist/runner/codex-runner.d.ts +4 -0
  46. package/dist/runner/codex-runner.js +27 -4
  47. package/dist/runner/fake-test-runner.js +0 -1
  48. package/dist/runner/opencode/conversation-parser.d.ts +27 -0
  49. package/dist/runner/opencode/conversation-parser.js +217 -0
  50. package/dist/runner/opencode/managed-run-controller.d.ts +76 -0
  51. package/dist/runner/opencode/managed-run-controller.js +451 -0
  52. package/dist/runner/opencode-runner.d.ts +60 -0
  53. package/dist/runner/opencode-runner.js +330 -0
  54. package/dist/runner/runner-registry.d.ts +3 -1
  55. package/dist/runner/runner-registry.js +12 -3
  56. package/dist/runner-command-engine.js +0 -1
  57. package/dist/runner-profiles.d.ts +4 -0
  58. package/dist/runner-profiles.js +76 -3
  59. package/dist/runner-usage.js +0 -1
  60. package/dist/runtime-state.js +20 -9
  61. package/dist/service/attachment-domain-state.js +0 -1
  62. package/dist/service/conversation-history-service.js +0 -1
  63. package/dist/service/external-session-resume-service.js +0 -1
  64. package/dist/service/fake-managed-run-service.js +0 -1
  65. package/dist/service/managed-runner-session-service.d.ts +3 -1
  66. package/dist/service/managed-runner-session-service.js +8 -4
  67. package/dist/service/native-session-projection-service.d.ts +2 -1
  68. package/dist/service/native-session-projection-service.js +8 -5
  69. package/dist/service/native-session-watch-service.js +0 -1
  70. package/dist/service/node-connection-lifecycle-service.js +3 -2
  71. package/dist/service/node-control-channel.d.ts +1 -1
  72. package/dist/service/node-control-channel.js +5 -4
  73. package/dist/service/node-control-message-service.js +0 -1
  74. package/dist/service/node-request-service.js +0 -1
  75. package/dist/service/node-run-event-bridge.d.ts +2 -0
  76. package/dist/service/node-run-event-bridge.js +4 -1
  77. package/dist/service/node-terminal-channel.js +16 -10
  78. package/dist/service/node-upgrade-coordinator.d.ts +29 -0
  79. package/dist/service/node-upgrade-coordinator.js +137 -0
  80. package/dist/service/node-workspace-coordinator.js +0 -1
  81. package/dist/service/run-attachment-service.js +0 -1
  82. package/dist/service/run-domain-state.js +0 -1
  83. package/dist/service/run-event-service.js +0 -1
  84. package/dist/service/run-workbench-service.js +0 -1
  85. package/dist/service/runner-channel-message-service.js +0 -1
  86. package/dist/service/runner-interaction-service.js +2 -1
  87. package/dist/service/runner-service.d.ts +5 -4
  88. package/dist/service/runner-service.js +19 -6
  89. package/dist/service/session-catalog-service.d.ts +16 -1
  90. package/dist/service/session-catalog-service.js +82 -3
  91. package/dist/service/session-command-service.js +0 -1
  92. package/dist/service/session-context-service.js +0 -1
  93. package/dist/service/session-domain-state.js +0 -1
  94. package/dist/service/session-identity-service.js +0 -1
  95. package/dist/service/session-lifecycle-service.js +13 -7
  96. package/dist/service/session-message-service.js +0 -1
  97. package/dist/service/session-presentation-service.js +0 -1
  98. package/dist/service/session-query-service.js +0 -1
  99. package/dist/service/terminal-relay-state.js +0 -1
  100. package/dist/service/terminal-service.js +0 -1
  101. package/dist/service/workbench-event-service.js +0 -1
  102. package/dist/service/workbench-manifest-service.d.ts +5 -4
  103. package/dist/service/workbench-manifest-service.js +3 -2
  104. package/dist/service/workspace-change-service.js +2 -2
  105. package/dist/service/workspace-content-search-service.d.ts +14 -0
  106. package/dist/service/workspace-content-search-service.js +477 -0
  107. package/dist/service/workspace-domain-state.js +0 -1
  108. package/dist/service/workspace-file-service.d.ts +3 -0
  109. package/dist/service/workspace-file-service.js +35 -3
  110. package/dist/service/workspace-queue-workbench-service.js +0 -1
  111. package/dist/service/workspace-service.js +23 -10
  112. package/dist/service/workspace-session-service.js +0 -1
  113. package/dist/service/workspace-upload-service.js +0 -1
  114. package/dist/service/workspace-watch-service.js +0 -1
  115. package/dist/service/workspace-workbench-service.d.ts +9 -0
  116. package/dist/service/workspace-workbench-service.js +69 -2
  117. package/dist/service.js +2 -3
  118. package/dist/storage.js +0 -1
  119. package/dist/supervisor.d.ts +1 -0
  120. package/dist/supervisor.js +154 -0
  121. package/dist/terminal.js +0 -1
  122. package/dist/util/node-operation-parsers.d.ts +1 -0
  123. package/dist/util/node-operation-parsers.js +3 -1
  124. package/dist/util/runner-native-session-parsers.js +117 -73
  125. package/dist/util/secret-environment.js +0 -1
  126. package/dist/workspace.d.ts +62 -2
  127. package/dist/workspace.js +539 -57
  128. package/package.json +3 -2
  129. package/dist/capabilities.js.map +0 -1
  130. package/dist/claude-agent-sdk.js.map +0 -1
  131. package/dist/claude-channel.js.map +0 -1
  132. package/dist/codex-app-server.js.map +0 -1
  133. package/dist/config.js.map +0 -1
  134. package/dist/connector/node-connector-options.js.map +0 -1
  135. package/dist/connector/node-operation-router.js.map +0 -1
  136. package/dist/connector.js.map +0 -1
  137. package/dist/control-outbound-scheduler.js.map +0 -1
  138. package/dist/database.js.map +0 -1
  139. package/dist/event-buffer.js.map +0 -1
  140. package/dist/fake-runner.js.map +0 -1
  141. package/dist/health.js.map +0 -1
  142. package/dist/main.js.map +0 -1
  143. package/dist/migrations/v001.js.map +0 -1
  144. package/dist/migrations/v002.js.map +0 -1
  145. package/dist/native-jsonl-reader.js.map +0 -1
  146. package/dist/native-session-history.js.map +0 -1
  147. package/dist/operational.js.map +0 -1
  148. package/dist/process-tree.js.map +0 -1
  149. package/dist/runner/abstract-runner.js.map +0 -1
  150. package/dist/runner/claude/managed-run-controller.js.map +0 -1
  151. package/dist/runner/claude-code-runner.js.map +0 -1
  152. package/dist/runner/codex/conversation-parser.js.map +0 -1
  153. package/dist/runner/codex/managed-run-controller.js.map +0 -1
  154. package/dist/runner/codex-runner.js.map +0 -1
  155. package/dist/runner/fake-test-runner.js.map +0 -1
  156. package/dist/runner/runner-registry.js.map +0 -1
  157. package/dist/runner-command-engine.js.map +0 -1
  158. package/dist/runner-profiles.js.map +0 -1
  159. package/dist/runner-usage.js.map +0 -1
  160. package/dist/runtime-state.js.map +0 -1
  161. package/dist/service/attachment-domain-state.js.map +0 -1
  162. package/dist/service/conversation-history-service.js.map +0 -1
  163. package/dist/service/external-session-resume-service.js.map +0 -1
  164. package/dist/service/fake-managed-run-service.js.map +0 -1
  165. package/dist/service/managed-runner-session-service.js.map +0 -1
  166. package/dist/service/native-session-projection-service.js.map +0 -1
  167. package/dist/service/native-session-watch-service.js.map +0 -1
  168. package/dist/service/node-connection-lifecycle-service.js.map +0 -1
  169. package/dist/service/node-control-channel.js.map +0 -1
  170. package/dist/service/node-control-message-service.js.map +0 -1
  171. package/dist/service/node-request-service.js.map +0 -1
  172. package/dist/service/node-run-event-bridge.js.map +0 -1
  173. package/dist/service/node-terminal-channel.js.map +0 -1
  174. package/dist/service/node-workspace-coordinator.js.map +0 -1
  175. package/dist/service/run-attachment-service.js.map +0 -1
  176. package/dist/service/run-domain-state.js.map +0 -1
  177. package/dist/service/run-event-service.js.map +0 -1
  178. package/dist/service/run-workbench-service.js.map +0 -1
  179. package/dist/service/runner-channel-message-service.js.map +0 -1
  180. package/dist/service/runner-interaction-service.js.map +0 -1
  181. package/dist/service/runner-service.js.map +0 -1
  182. package/dist/service/session-catalog-service.js.map +0 -1
  183. package/dist/service/session-command-service.js.map +0 -1
  184. package/dist/service/session-context-service.js.map +0 -1
  185. package/dist/service/session-domain-state.js.map +0 -1
  186. package/dist/service/session-identity-service.js.map +0 -1
  187. package/dist/service/session-lifecycle-service.js.map +0 -1
  188. package/dist/service/session-message-service.js.map +0 -1
  189. package/dist/service/session-presentation-service.js.map +0 -1
  190. package/dist/service/session-query-service.js.map +0 -1
  191. package/dist/service/terminal-relay-state.js.map +0 -1
  192. package/dist/service/terminal-service.js.map +0 -1
  193. package/dist/service/workbench-event-service.js.map +0 -1
  194. package/dist/service/workbench-manifest-service.js.map +0 -1
  195. package/dist/service/workspace-change-service.js.map +0 -1
  196. package/dist/service/workspace-domain-state.js.map +0 -1
  197. package/dist/service/workspace-file-service.js.map +0 -1
  198. package/dist/service/workspace-queue-workbench-service.js.map +0 -1
  199. package/dist/service/workspace-service.js.map +0 -1
  200. package/dist/service/workspace-session-service.js.map +0 -1
  201. package/dist/service/workspace-upload-service.js.map +0 -1
  202. package/dist/service/workspace-watch-service.js.map +0 -1
  203. package/dist/service/workspace-workbench-service.js.map +0 -1
  204. package/dist/service.js.map +0 -1
  205. package/dist/storage.js.map +0 -1
  206. package/dist/terminal.js.map +0 -1
  207. package/dist/util/node-operation-parsers.js.map +0 -1
  208. package/dist/util/runner-native-session-parsers.js.map +0 -1
  209. package/dist/util/secret-environment.js.map +0 -1
  210. package/dist/workspace.js.map +0 -1
@@ -1,8 +1,11 @@
1
- import { readCurrentChangeDiff, readRestrictedDiff, resolveGitRepository, restoreCurrentChange } from '../workspace.js';
1
+ import { listGitHistoryRefs, readGitHistory, readGitHistoryFileDiff, readGitHistoryFiles, readCurrentChangeDiff, readRestrictedDiff, resolveGitRepository, restoreCurrentChange } from '../workspace.js';
2
+ import { WorkspaceContentSearchService } from './workspace-content-search-service.js';
2
3
  export class WorkspaceWorkbenchService {
3
4
  options;
5
+ contentSearch;
4
6
  constructor(options) {
5
7
  this.options = options;
8
+ this.contentSearch = new WorkspaceContentSearchService(options.files);
6
9
  }
7
10
  operations() {
8
11
  return {
@@ -12,6 +15,8 @@ export class WorkspaceWorkbenchService {
12
15
  'workspace.files.list': (data) => this.listFiles(record(data)),
13
16
  'workspace.file.read': (data) => this.readFile(record(data)),
14
17
  'workspace.files.search': (data) => this.searchFiles(record(data)),
18
+ 'workspace.files.mutate': (data) => this.mutateFile(record(data)),
19
+ 'workspace.content.search': (data) => this.searchContent(record(data)),
15
20
  'workspace.files.upload.preflight': (data) => this.preflight(record(data)),
16
21
  'workspace.files.upload.create': (data) => this.createUpload(record(data)),
17
22
  'workspace.files.upload.chunk': (data) => this.writeUpload(record(data)),
@@ -23,6 +28,10 @@ export class WorkspaceWorkbenchService {
23
28
  'workspace.changes.current': (data) => this.currentChanges(record(data)),
24
29
  'workspace.change.diff': (data) => this.changeDiff(record(data)),
25
30
  'workspace.change.restore': (data) => this.restoreChange(record(data)),
31
+ 'workspace.git.refs.list': (data) => this.gitRefs(record(data)),
32
+ 'workspace.git.history.list': (data) => this.gitHistory(record(data)),
33
+ 'workspace.git.commit.files': (data) => this.gitCommitFiles(record(data)),
34
+ 'workspace.git.commit.file.diff': (data) => this.gitCommitFileDiff(record(data)),
26
35
  'workspace.diff': (data) => this.diff(record(data))
27
36
  };
28
37
  }
@@ -87,6 +96,14 @@ export class WorkspaceWorkbenchService {
87
96
  const workspace = this.options.requireWorkspace(input.workspaceId);
88
97
  return { files: await this.options.files.search(workspace, input) };
89
98
  }
99
+ async mutateFile(input) {
100
+ const workspace = this.options.requireWorkspace(input.workspaceId);
101
+ return { file: await this.options.files.mutate(workspace, input) };
102
+ }
103
+ async searchContent(input) {
104
+ const workspace = this.options.requireWorkspace(input.workspaceId);
105
+ return { search: await this.contentSearch.search(workspace, input) };
106
+ }
90
107
  async preflight(input) {
91
108
  return {
92
109
  uploads: await this.options.uploads.preflight(this.options.requireWorkspace(input.workspaceId), input)
@@ -133,6 +150,57 @@ export class WorkspaceWorkbenchService {
133
150
  this.options.invalidate(workspace.id);
134
151
  return { restored: true };
135
152
  }
153
+ async gitRepository(input) {
154
+ if (typeof input.workspaceId !== 'string' ||
155
+ (input.repositoryPath !== undefined && typeof input.repositoryPath !== 'string'))
156
+ throw new Error('GIT_REPOSITORY_INVALID');
157
+ const workspace = this.gitWorkspace(input.workspaceId);
158
+ return resolveGitRepository(workspace.path, input.repositoryPath ?? '');
159
+ }
160
+ refs(input) {
161
+ if (input.refs === undefined)
162
+ return undefined;
163
+ if (!Array.isArray(input.refs) ||
164
+ input.refs.length > 128 ||
165
+ input.refs.some((ref) => typeof ref !== 'string'))
166
+ throw new Error('GIT_HISTORY_REF_INVALID');
167
+ return input.refs;
168
+ }
169
+ async gitRefs(input) {
170
+ return { refs: await listGitHistoryRefs(await this.gitRepository(input)) };
171
+ }
172
+ async gitHistory(input) {
173
+ const refs = this.refs(input);
174
+ if (input.cursor !== undefined && typeof input.cursor !== 'string')
175
+ throw new Error('GIT_HISTORY_CURSOR_INVALID');
176
+ if (input.limit !== undefined &&
177
+ (typeof input.limit !== 'number' ||
178
+ !Number.isInteger(input.limit) ||
179
+ input.limit < 1 ||
180
+ input.limit > 100))
181
+ throw new Error('GIT_HISTORY_LIMIT_INVALID');
182
+ return readGitHistory(await this.gitRepository(input), {
183
+ ...(refs === undefined ? {} : { refs }),
184
+ ...(typeof input.cursor === 'string' ? { cursor: input.cursor } : {}),
185
+ ...(typeof input.limit === 'number' ? { limit: input.limit } : {})
186
+ });
187
+ }
188
+ async gitCommitFiles(input) {
189
+ if (typeof input.commit !== 'string')
190
+ throw new Error('GIT_HISTORY_COMMIT_INVALID');
191
+ return {
192
+ files: await readGitHistoryFiles(await this.gitRepository(input), input.commit, this.refs(input))
193
+ };
194
+ }
195
+ async gitCommitFileDiff(input) {
196
+ if (typeof input.commit !== 'string' ||
197
+ typeof input.path !== 'string' ||
198
+ (input.previousPath !== undefined && typeof input.previousPath !== 'string'))
199
+ throw new Error('GIT_DIFF_INVALID');
200
+ return {
201
+ diff: await readGitHistoryFileDiff(await this.gitRepository(input), input.commit, input.path, this.refs(input), input.previousPath)
202
+ };
203
+ }
136
204
  async diff(input) {
137
205
  if (typeof input.workspaceId !== 'string' ||
138
206
  typeof input.fromRef !== 'string' ||
@@ -153,4 +221,3 @@ function record(value) {
153
221
  ? value
154
222
  : {};
155
223
  }
156
- //# sourceMappingURL=workspace-workbench-service.js.map
package/dist/service.js CHANGED
@@ -6,13 +6,13 @@ export function systemdUnit(executable, configPath, entrypoint, writablePaths =
6
6
  ...(entrypoint === undefined ? [] : [escapeSystemd(entrypoint)])
7
7
  ].join(' ');
8
8
  const readWritePaths = writablePaths.map((path) => escapeSystemd(resolve(path))).join(' ');
9
- return `[Unit]\nDescription=MyAgentRoam Node\nAfter=network-online.target\n\n[Service]\nType=simple\nUser=mar-node\nNoNewPrivileges=true\nPrivateTmp=true\nProtectSystem=strict\n${readWritePaths.length === 0 ? '' : `ReadWritePaths=${readWritePaths}\n`}ExecStart=${command} run --config ${escapeSystemd(configPath)}\nRestart=on-failure\n\n[Install]\nWantedBy=multi-user.target\n`;
9
+ return `[Unit]\nDescription=MyAgentRoam Node\nAfter=network-online.target\n\n[Service]\nType=simple\nUser=mar-node\nNoNewPrivileges=true\nPrivateTmp=true\nProtectSystem=strict\n${readWritePaths.length === 0 ? '' : `ReadWritePaths=${readWritePaths}\n`}ExecStart=${command} supervise --config ${escapeSystemd(configPath)}\nRestart=on-failure\n\n[Install]\nWantedBy=multi-user.target\n`;
10
10
  }
11
11
  export function windowsServiceDefinition(executable, configPath, entrypoint) {
12
12
  return JSON.stringify({
13
13
  serviceName: 'MyAgentRoamNode',
14
14
  displayName: 'MyAgentRoam Node',
15
- binaryPath: `"${executable}"${entrypoint === undefined ? '' : ` "${entrypoint}"`} run --config "${configPath}"`,
15
+ binaryPath: `"${executable}"${entrypoint === undefined ? '' : ` "${entrypoint}"`} supervise --config "${configPath}"`,
16
16
  startType: 'auto',
17
17
  account: 'LocalService'
18
18
  }, undefined, 2);
@@ -36,4 +36,3 @@ export async function removeServiceDefinition(outputPath) {
36
36
  function escapeSystemd(value) {
37
37
  return JSON.stringify(value);
38
38
  }
39
- //# sourceMappingURL=service.js.map
package/dist/storage.js CHANGED
@@ -30,4 +30,3 @@ async function existingParent(path) {
30
30
  current = parent;
31
31
  }
32
32
  }
33
- //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ export declare function superviseNode(configPath: string, bootstrapEntrypoint: string): Promise<void>;
@@ -0,0 +1,154 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { access, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
3
+ import { dirname, resolve } from 'node:path';
4
+ import { loadNodeConfig, nodeDatabasePath } from './config.js';
5
+ import { nodeLog, platformCliInvocation } from './operational.js';
6
+ import { nodeUpgradeRequestPath } from './service/node-upgrade-coordinator.js';
7
+ const UPGRADE_EXIT_CODE = 75;
8
+ const STABLE_VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/u;
9
+ export async function superviseNode(configPath, bootstrapEntrypoint) {
10
+ const config = await loadNodeConfig(configPath);
11
+ const dataDirectory = dirname(nodeDatabasePath(config, configPath));
12
+ const activePath = resolve(dataDirectory, 'node-active-entrypoint');
13
+ let entrypoint = await readActiveEntrypoint(activePath, bootstrapEntrypoint);
14
+ for (;;) {
15
+ const childResult = await runProcess(process.execPath, [entrypoint, 'run', '--config', configPath], true, { ...process.env, MAR_NODE_SUPERVISED: '1' });
16
+ if (childResult.signalled)
17
+ return;
18
+ const code = childResult.code;
19
+ if (code !== UPGRADE_EXIT_CODE) {
20
+ if (code === 0)
21
+ return;
22
+ nodeLog('node.supervisor.child-exited', { code });
23
+ await delay(1_000);
24
+ continue;
25
+ }
26
+ const requestPath = nodeUpgradeRequestPath(nodeDatabasePath(config, configPath));
27
+ let stopping = false;
28
+ try {
29
+ const request = JSON.parse(await readFile(requestPath, 'utf8'));
30
+ const targetVersion = request['targetVersion'];
31
+ if (request['schemaVersion'] !== 1 ||
32
+ typeof targetVersion !== 'string' ||
33
+ !STABLE_VERSION.test(targetVersion))
34
+ throw new Error('NODE_UPGRADE_REQUEST_INVALID');
35
+ const prefix = resolve(dataDirectory, 'node-versions', targetVersion);
36
+ await rm(prefix, { recursive: true, force: true });
37
+ await mkdir(prefix, { recursive: true, mode: 0o700 });
38
+ const registry = validatedRegistry(config.upgrade?.registryUrl);
39
+ const invocation = platformCliInvocation('npm', [
40
+ 'install',
41
+ '--prefix',
42
+ prefix,
43
+ '--ignore-scripts',
44
+ '--no-audit',
45
+ '--no-fund',
46
+ ...(registry === undefined ? [] : ['--registry', registry]),
47
+ `@myagentroam/node@${targetVersion}`
48
+ ]);
49
+ const installResult = await runProcess(invocation.command, invocation.args, false);
50
+ if (installResult.signalled) {
51
+ stopping = true;
52
+ throw new Error('NODE_UPGRADE_INSTALL_INTERRUPTED');
53
+ }
54
+ if (installResult.code !== 0)
55
+ throw new Error('NODE_UPGRADE_INSTALL_FAILED');
56
+ const rebuild = platformCliInvocation('npm', [
57
+ 'rebuild',
58
+ '--prefix',
59
+ prefix,
60
+ ...(registry === undefined ? [] : ['--registry', registry]),
61
+ 'node-pty'
62
+ ]);
63
+ const rebuildResult = await runProcess(rebuild.command, rebuild.args, false);
64
+ if (rebuildResult.signalled) {
65
+ stopping = true;
66
+ throw new Error('NODE_UPGRADE_INSTALL_INTERRUPTED');
67
+ }
68
+ if (rebuildResult.code !== 0)
69
+ throw new Error('NODE_UPGRADE_NATIVE_REBUILD_FAILED');
70
+ const nextEntrypoint = resolve(prefix, 'node_modules', '@myagentroam', 'node', 'dist', 'main.js');
71
+ await access(nextEntrypoint);
72
+ await writeAtomic(activePath, `${nextEntrypoint}\n`);
73
+ await writeResult(dataDirectory, {
74
+ state: 'SUCCEEDED',
75
+ targetVersion,
76
+ updatedAt: Date.now()
77
+ });
78
+ await rm(requestPath, { force: true });
79
+ entrypoint = nextEntrypoint;
80
+ }
81
+ catch (error) {
82
+ await writeResult(dataDirectory, {
83
+ state: 'FAILED',
84
+ errorCode: error instanceof Error ? error.message : 'NODE_UPGRADE_INSTALL_FAILED',
85
+ updatedAt: Date.now()
86
+ });
87
+ await rm(requestPath, { force: true });
88
+ }
89
+ if (stopping)
90
+ return;
91
+ }
92
+ }
93
+ async function runProcess(command, args, inherit, env = process.env) {
94
+ return new Promise((resolveProcess) => {
95
+ const child = spawn(command, args, {
96
+ windowsHide: true,
97
+ stdio: inherit ? 'inherit' : 'ignore',
98
+ env
99
+ });
100
+ let settled = false;
101
+ let signalled = false;
102
+ const forward = (signal) => {
103
+ signalled = true;
104
+ child.kill(signal);
105
+ };
106
+ const onSigint = () => forward('SIGINT');
107
+ const onSigterm = () => forward('SIGTERM');
108
+ const finish = (code) => {
109
+ if (settled)
110
+ return;
111
+ settled = true;
112
+ process.off('SIGINT', onSigint);
113
+ process.off('SIGTERM', onSigterm);
114
+ resolveProcess({ code, signalled });
115
+ };
116
+ process.once('SIGINT', onSigint);
117
+ process.once('SIGTERM', onSigterm);
118
+ child.once('error', () => finish(null));
119
+ child.once('close', finish);
120
+ });
121
+ }
122
+ async function readActiveEntrypoint(path, fallback) {
123
+ try {
124
+ const value = (await readFile(path, 'utf8')).trim();
125
+ await access(value);
126
+ return value;
127
+ }
128
+ catch {
129
+ return fallback;
130
+ }
131
+ }
132
+ async function writeResult(directory, result) {
133
+ await writeAtomic(resolve(directory, 'upgrade-result.json'), `${JSON.stringify(result)}\n`);
134
+ }
135
+ async function writeAtomic(path, contents) {
136
+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });
137
+ const temporary = `${path}.${process.pid}.tmp`;
138
+ await writeFile(temporary, contents, { mode: 0o600 });
139
+ await rename(temporary, path);
140
+ }
141
+ function validatedRegistry(value) {
142
+ if (value === undefined)
143
+ return undefined;
144
+ const url = new URL(value);
145
+ if (url.protocol !== 'https:' &&
146
+ !(url.protocol === 'http:' && ['127.0.0.1', 'localhost'].includes(url.hostname)))
147
+ throw new Error('NODE_UPGRADE_REGISTRY_INVALID');
148
+ if (url.username !== '' || url.password !== '' || url.search !== '' || url.hash !== '')
149
+ throw new Error('NODE_UPGRADE_REGISTRY_INVALID');
150
+ return url.toString().replace(/\/$/u, '');
151
+ }
152
+ function delay(milliseconds) {
153
+ return new Promise((resolveDelay) => setTimeout(resolveDelay, milliseconds));
154
+ }
package/dist/terminal.js CHANGED
@@ -414,4 +414,3 @@ function splitFrameData(value) {
414
414
  }
415
415
  return chunks;
416
416
  }
417
- //# sourceMappingURL=terminal.js.map
@@ -67,6 +67,7 @@ export declare function boundedConversationItemId(prefix: string, value: string)
67
67
  export declare function validUserAuthorization(value: unknown, envelope: NodeEnvelope, operation: string, nodeId: string | undefined, now?: number): boolean;
68
68
  export declare function isTerminalRunStatus(status: AgentRunStatus): boolean;
69
69
  export declare function validSessionOption(value: unknown): boolean;
70
+ export declare function validSessionEffort(value: unknown): boolean;
70
71
  export declare function validSessionTitle(value: unknown): boolean;
71
72
  export declare function sessionTitleFromFirstMessage(content: string): string;
72
73
  export declare function parseComposerAttachmentUpload(input: Record<string, unknown>): {
@@ -234,6 +234,9 @@ export function validSessionOption(value) {
234
234
  return (value === undefined ||
235
235
  (typeof value === 'string' && value.trim().length > 0 && value.length <= 120));
236
236
  }
237
+ export function validSessionEffort(value) {
238
+ return value === undefined || (typeof value === 'string' && value.length <= 120);
239
+ }
237
240
  export function validSessionTitle(value) {
238
241
  return (value === undefined ||
239
242
  (typeof value === 'string' && value.trim().length > 0 && value.length <= 160));
@@ -377,4 +380,3 @@ export function isNodeConversationTurn(value) {
377
380
  typeof value.sessionId === 'string' &&
378
381
  Array.isArray(value.items));
379
382
  }
380
- //# sourceMappingURL=node-operation-parsers.js.map
@@ -154,57 +154,119 @@ export function deduplicateDirectSessions(sessions) {
154
154
  }
155
155
  export function nativeConversationPage(session, history, input, runtimeTurns = [], registerImages = () => []) {
156
156
  const limit = Math.min(Math.max(input.limit ?? 30, 1), 500);
157
- const end = nativePageEnd(input.cursor, session.id, history.items.length);
157
+ const nativeTurns = nativeTranscriptTurns(history.items);
158
+ const end = nativePageEnd(input.cursor, session.id, nativeTurns.length);
158
159
  const start = Math.max(0, end - limit);
159
- const turns = history.items.slice(start, end).map((entry, offset) => {
160
- const index = start + offset;
161
- const time = entry.createdAt ?? index;
162
- const turnId = `${session.id}:native:${index}`;
163
- const isToolCall = entry.kind === 'tool_call';
164
- const isCommand = isToolCall && isClaudeCommandTool(entry.toolName);
165
- const userInputQuestions = session.runner === 'claude-code' &&
166
- isToolCall &&
167
- entry.toolName === 'AskUserQuestion' &&
168
- isPlainRecord(entry.input)
169
- ? claudeUserInputQuestions(entry.input)
170
- : [];
171
- const isUserInputRequest = userInputQuestions.length > 0;
172
- const clientMessageId = !isToolCall && entry.role === 'USER'
173
- ? nativeUserClientMessageId(entry, time, runtimeTurns)
174
- : null;
175
- // Claude 标签式 Plan Mode:用户正文剥离注入的规划指令标签,
176
- // 完整的 <proposed_plan> Agent 文本归一化为计划卡。
177
- const entryText = entry.kind === 'message'
178
- ? entry.role === 'USER'
179
- ? stripClaudePlanTag(entry.text)
180
- : entry.text
181
- : '';
182
- const planText = entry.kind === 'message' && entry.role !== 'USER' ? claudePlanText(entryText) : undefined;
183
- const item = {
184
- id: `${turnId}:item`,
160
+ const turns = nativeTurns
161
+ .slice(start, end)
162
+ .map((entries, relativeIndex) => {
163
+ const firstIndex = entries[0]?.index ?? 0;
164
+ const turnId = `${session.id}:native:${firstIndex}`;
165
+ const items = entries.map(({ entry, index }) => nativeTranscriptConversationItem(session, entry, index, turnId, runtimeTurns, registerImages));
166
+ const startedAt = items[0]?.startedAt ?? firstIndex;
167
+ const completedAt = items.at(-1)?.completedAt ?? startedAt;
168
+ const after = lastNativeItemId(entries);
169
+ return {
170
+ id: turnId,
185
171
  sessionId: session.id,
186
- turnId,
187
172
  runId: null,
188
- parentItemId: null,
189
- sourceSequence: index,
190
- revision: 0,
191
- kind: isUserInputRequest
192
- ? 'user_input_request'
173
+ userItemId: items.find((item) => item.kind === 'user_message')?.id ?? null,
174
+ status: 'SUCCEEDED',
175
+ model: null,
176
+ effort: null,
177
+ access: null,
178
+ ...(after === undefined || session.runner !== 'claude-code'
179
+ ? {}
180
+ : {
181
+ rewind: {
182
+ before: lastNativeItemId(nativeTurns[start + relativeIndex - 1] ?? []) ?? null,
183
+ after
184
+ }
185
+ }),
186
+ items,
187
+ startedAt,
188
+ completedAt
189
+ };
190
+ });
191
+ return {
192
+ turns,
193
+ nextCursor: start > 0
194
+ ? Buffer.from(JSON.stringify({ sessionId: session.id, end: start })).toString('base64url')
195
+ : null
196
+ };
197
+ }
198
+ function lastNativeItemId(entries) {
199
+ return entries.findLast(({ entry }) => entry.nativeId !== undefined)?.entry.nativeId;
200
+ }
201
+ function nativeTranscriptTurns(items) {
202
+ const turns = [];
203
+ let current = [];
204
+ for (const [index, entry] of items.entries()) {
205
+ if (entry.kind === 'message' && entry.role === 'USER' && current.length > 0) {
206
+ turns.push(current);
207
+ current = [];
208
+ }
209
+ current.push({ entry, index });
210
+ }
211
+ if (current.length > 0)
212
+ turns.push(current);
213
+ return turns;
214
+ }
215
+ function nativeTranscriptConversationItem(session, entry, index, turnId, runtimeTurns, registerImages) {
216
+ const time = entry.createdAt ?? index;
217
+ const isToolCall = entry.kind === 'tool_call';
218
+ const isUnknown = entry.kind === 'unknown';
219
+ const isReasoning = entry.kind === 'reasoning_summary';
220
+ const isCommand = isToolCall && isClaudeCommandTool(entry.toolName);
221
+ const userInputQuestions = session.runner === 'claude-code' &&
222
+ isToolCall &&
223
+ entry.toolName === 'AskUserQuestion' &&
224
+ isPlainRecord(entry.input)
225
+ ? claudeUserInputQuestions(entry.input)
226
+ : [];
227
+ const isUserInputRequest = userInputQuestions.length > 0;
228
+ const clientMessageId = entry.kind === 'message' && entry.role === 'USER'
229
+ ? nativeUserClientMessageId(entry, time, runtimeTurns)
230
+ : null;
231
+ // Claude 标签式 Plan Mode:用户正文剥离注入的规划指令标签,
232
+ // 完整的 <proposed_plan> Agent 文本归一化为计划卡。
233
+ const entryText = entry.kind === 'message'
234
+ ? entry.role === 'USER'
235
+ ? stripClaudePlanTag(entry.text)
236
+ : entry.text
237
+ : '';
238
+ const planText = entry.kind === 'message' && entry.role !== 'USER' ? claudePlanText(entryText) : undefined;
239
+ const item = {
240
+ id: `${turnId}:item:${index}`,
241
+ sessionId: session.id,
242
+ turnId,
243
+ runId: null,
244
+ parentItemId: null,
245
+ sourceSequence: index,
246
+ revision: 0,
247
+ kind: isUserInputRequest
248
+ ? 'user_input_request'
249
+ : isReasoning
250
+ ? 'reasoning_summary'
193
251
  : isToolCall
194
252
  ? isCommand
195
253
  ? 'command_execution'
196
254
  : 'tool_call'
197
- : entry.role === 'USER'
198
- ? 'user_message'
199
- : planText !== undefined
200
- ? 'plan'
201
- : 'assistant_message',
202
- status: 'COMPLETED',
203
- payload: isUserInputRequest
204
- ? {
205
- requestId: `native:${entry.kind === 'tool_call' ? entry.toolUseId : `item-${index}`}`,
206
- questions: userInputQuestions
207
- }
255
+ : isUnknown
256
+ ? 'unknown'
257
+ : entry.kind === 'message' && entry.role === 'USER'
258
+ ? 'user_message'
259
+ : planText !== undefined
260
+ ? 'plan'
261
+ : 'assistant_message',
262
+ status: 'COMPLETED',
263
+ payload: isUserInputRequest
264
+ ? {
265
+ requestId: `native:${entry.kind === 'tool_call' ? entry.toolUseId : `item-${index}`}`,
266
+ questions: userInputQuestions
267
+ }
268
+ : isReasoning
269
+ ? { sections: entry.sections }
208
270
  : isToolCall
209
271
  ? isCommand
210
272
  ? {
@@ -229,34 +291,17 @@ export function nativeConversationPage(session, history, input, runtimeTurns = [
229
291
  ? {}
230
292
  : { attachments: registerImages(entry.imageAttachments) })
231
293
  }
232
- : entry.role === 'USER'
233
- ? { clientMessageId, text: entryText, contexts: [], delivery: 'ACCEPTED' }
234
- : planText !== undefined
235
- ? { explanation: compactRunnerText(planText, 20_000), steps: [] }
236
- : { text: entryText, format: 'markdown', source: 'native-file' },
237
- startedAt: time,
238
- completedAt: time
239
- };
240
- return {
241
- id: turnId,
242
- sessionId: session.id,
243
- runId: null,
244
- userItemId: !isToolCall && entry.role === 'USER' ? item.id : null,
245
- status: 'SUCCEEDED',
246
- model: null,
247
- effort: null,
248
- access: null,
249
- items: [item],
250
- startedAt: time,
251
- completedAt: time
252
- };
253
- });
254
- return {
255
- turns,
256
- nextCursor: start > 0
257
- ? Buffer.from(JSON.stringify({ sessionId: session.id, end: start })).toString('base64url')
258
- : null
294
+ : isUnknown
295
+ ? { sourceEventType: entry.sourceEventType, label: entry.label }
296
+ : entry.kind === 'message' && entry.role === 'USER'
297
+ ? { clientMessageId, text: entryText, contexts: [], delivery: 'ACCEPTED' }
298
+ : planText !== undefined
299
+ ? { explanation: compactRunnerText(planText, 20_000), steps: [] }
300
+ : { text: entryText, format: 'markdown', source: 'native-file' },
301
+ startedAt: time,
302
+ completedAt: time
259
303
  };
304
+ return item;
260
305
  }
261
306
  /**
262
307
  * Claude JSONL 不保存浏览器请求 ID。Node 进程仍存活时,以正文和生成时刻
@@ -326,7 +371,7 @@ export function claudeUserInputQuestions(value) {
326
371
  prompt: compactRunnerText(raw.question, 5_000),
327
372
  input: options.length === 0 ? 'SHORT_TEXT' : multiSelect ? 'MULTI_SELECT' : 'SINGLE_SELECT',
328
373
  options,
329
- allowOther: options.length === 0,
374
+ allowOther: true,
330
375
  multiSelect
331
376
  };
332
377
  });
@@ -334,4 +379,3 @@ export function claudeUserInputQuestions(value) {
334
379
  ? []
335
380
  : questions;
336
381
  }
337
- //# sourceMappingURL=runner-native-session-parsers.js.map
@@ -23,4 +23,3 @@ export function parseSecretEnvironment(value) {
23
23
  }
24
24
  return environment;
25
25
  }
26
- //# sourceMappingURL=secret-environment.js.map
@@ -41,6 +41,7 @@ export interface WorkspaceDirectoryListing {
41
41
  readonly entries: readonly WorkspaceDirectoryEntry[];
42
42
  readonly truncated: boolean;
43
43
  }
44
+ export declare function createWorkspaceDirectory(parentPath: string, directoryName: string, allowedRoots: readonly string[]): Promise<string>;
44
45
  /** A per-workspace, process-local index for the Quick Open file picker. */
45
46
  export declare class WorkspaceFileIndex {
46
47
  private readonly workspaceRoot;
@@ -61,8 +62,12 @@ export declare class WorkspaceFileIndex {
61
62
  });
62
63
  /** Starts/renews the lightweight index observer without exposing file data. */
63
64
  observe(): Promise<void>;
65
+ contentCandidates(): Promise<{
66
+ readonly entries: readonly WorkspaceFileEntry[];
67
+ readonly truncated: boolean;
68
+ }>;
64
69
  dispose(): void;
65
- search(query: string, cursor?: string, limit?: number): Promise<WorkspaceFileSearchPage>;
70
+ search(query: string, cursor?: string, limit?: number, includeDirectories?: boolean): Promise<WorkspaceFileSearchPage>;
66
71
  private ensureLoaded;
67
72
  private touch;
68
73
  private rebuild;
@@ -77,6 +82,24 @@ export declare class WorkspaceFileIndex {
77
82
  */
78
83
  export declare function listWorkspaceDirectories(requestedPath: string | undefined, allowedRoots: readonly string[], homePath?: string): Promise<WorkspaceDirectoryListing>;
79
84
  export declare function listWorkspaceFiles(workspaceRoot: string, requestedPath?: string, cursor?: string, limit?: number): Promise<WorkspaceFilePage>;
85
+ export type WorkspaceFileMutation = {
86
+ readonly action: 'CREATE_FILE';
87
+ readonly path: string;
88
+ } | {
89
+ readonly action: 'CREATE_DIRECTORY';
90
+ readonly path: string;
91
+ } | {
92
+ readonly action: 'MOVE';
93
+ readonly path: string;
94
+ readonly destination: string;
95
+ } | {
96
+ readonly action: 'DELETE';
97
+ readonly path: string;
98
+ };
99
+ export declare function mutateWorkspaceFile(workspaceRoot: string, mutation: WorkspaceFileMutation): Promise<{
100
+ readonly path?: string;
101
+ readonly deleted?: true;
102
+ }>;
80
103
  /** Validates an upload destination without following an existing target symlink. */
81
104
  export declare function preflightWorkspaceUpload(workspaceRoot: string, requestedDirectory: string, name: string): Promise<WorkspaceUploadTarget>;
82
105
  export declare function workspaceUploadTemporaryName(uploadId: string): string;
@@ -98,7 +121,7 @@ export declare function readAllowedTextFile(requestedPath: string, allowedRoots:
98
121
  readonly nextOffset: number | null;
99
122
  }>;
100
123
  /** Searches file names only, so an exploratory request cannot exfiltrate file contents. */
101
- export declare function searchWorkspaceFiles(workspaceRoot: string, query: string, cursor?: string, limit?: number): Promise<WorkspaceFileSearchPage>;
124
+ export declare function searchWorkspaceFiles(workspaceRoot: string, query: string, cursor?: string, limit?: number, includeDirectories?: boolean): Promise<WorkspaceFileSearchPage>;
102
125
  export declare function normalizeWorkspacePath(input: string, platform?: NodeJS.Platform): string;
103
126
  export declare function isWithinAllowedRoot(target: string, roots: readonly string[], platform?: NodeJS.Platform): boolean;
104
127
  /** Resolving both candidate and roots rejects Linux symlinks which point outside a root. */
@@ -128,6 +151,35 @@ export declare function readCurrentChangesSummary(workspacePath: string): Promis
128
151
  }>;
129
152
  export declare function listInitializedSubmodulePaths(workspacePath: string): Promise<readonly string[]>;
130
153
  export declare function resolveGitRepository(workspacePath: string, repositoryPath: string): Promise<string>;
154
+ export interface GitHistoryRefEntry {
155
+ readonly name: string;
156
+ readonly displayName: string;
157
+ readonly kind: 'LOCAL' | 'REMOTE';
158
+ readonly hash: string;
159
+ readonly current: boolean;
160
+ }
161
+ export declare function listGitHistoryRefs(repository: string): Promise<readonly GitHistoryRefEntry[]>;
162
+ export declare function readGitHistory(repository: string, input: {
163
+ readonly refs?: readonly string[];
164
+ readonly cursor?: string;
165
+ readonly limit?: number;
166
+ }): Promise<{
167
+ readonly commits: readonly object[];
168
+ readonly nextCursor: string | null;
169
+ }>;
170
+ export declare function readGitHistoryFiles(repository: string, commit: string, refs?: readonly string[]): Promise<readonly {
171
+ path: string;
172
+ previousPath?: string;
173
+ change: ReturnType<typeof gitChange>;
174
+ }[]>;
175
+ export declare function readGitHistoryFileDiff(repository: string, commit: string, requestedPath: string, refs?: readonly string[], requestedPreviousPath?: string): Promise<{
176
+ readonly binary: boolean;
177
+ readonly text?: string;
178
+ readonly summary?: string;
179
+ readonly truncated: boolean;
180
+ readonly beforePreview?: BinaryDiffPreview;
181
+ readonly afterPreview?: BinaryDiffPreview;
182
+ }>;
131
183
  export declare function readCurrentChanges(workspacePath: string): Promise<readonly {
132
184
  readonly path: string;
133
185
  readonly state: 'STAGED' | 'UNSTAGED' | 'UNTRACKED';
@@ -140,12 +192,20 @@ export declare function readCurrentChangeDiff(workspacePath: string, requestedPa
140
192
  readonly truncated: boolean;
141
193
  readonly afterText?: string;
142
194
  readonly afterTruncated?: boolean;
195
+ readonly beforePreview?: BinaryDiffPreview;
196
+ readonly afterPreview?: BinaryDiffPreview;
143
197
  }>;
144
198
  /** Current Changes must not expose an external link. */
145
199
  export declare function isWorkspaceChangeVisible(workspacePath: string, requestedPath: string): Promise<boolean>;
200
+ interface BinaryDiffPreview {
201
+ readonly contentBase64?: string;
202
+ readonly truncated: boolean;
203
+ }
146
204
  export declare function restoreCurrentChange(workspacePath: string, requestedPath: string, state: 'STAGED' | 'UNSTAGED' | 'UNTRACKED'): Promise<void>;
205
+ declare function gitChange(status: string): 'ADDED' | 'MODIFIED' | 'DELETED' | 'RENAMED' | 'COPIED' | 'TYPE_CHANGED';
147
206
  export declare class GitCommandError extends Error {
148
207
  readonly code: number;
149
208
  readonly stderr: string;
150
209
  constructor(code: number, stderr: string);
151
210
  }
211
+ export {};