evolcore 0.0.43-test.5 → 0.0.43-test.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 (259) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/bin/ecmsg.js +281 -81
  3. package/dist/agents/baseagent-availability.js +20 -5
  4. package/dist/agents/baseagent.js +2 -2
  5. package/dist/agents/claude-runner.js +19 -4
  6. package/dist/agents/codex/app-server-client.js +36 -3
  7. package/dist/agents/codex-runner.js +75 -8
  8. package/dist/aun/group/invite-service.js +3 -2
  9. package/dist/aun/msg/p2p.js +6 -1
  10. package/dist/aun/service-proxy.js +18 -6
  11. package/dist/channels/aun.js +306 -30
  12. package/dist/cli/agent-create.js +18 -8
  13. package/dist/cli/aun-commands.js +9 -1
  14. package/dist/cli/daemon-commands.js +34 -65
  15. package/dist/cli/daemon-lifecycle-client.js +61 -0
  16. package/dist/cli/ecmsg-gateway.js +38 -3
  17. package/dist/cli/events-command.js +73 -0
  18. package/dist/cli/index.js +31 -14
  19. package/dist/cli/init.js +75 -0
  20. package/dist/cli/invoke-command.js +182 -0
  21. package/dist/cli/managed-command-guard.js +6 -1
  22. package/dist/cli/provider-command.js +1 -1
  23. package/dist/cli/restart-monitor.js +67 -50
  24. package/dist/cli/services-command.js +111 -0
  25. package/dist/cli/task-context.js +38 -1
  26. package/dist/cli/team-workspace-command.js +134 -0
  27. package/dist/cli/thread-command.js +6 -2
  28. package/dist/cli/watch-logs.js +6 -4
  29. package/dist/cli/watch-msg.js +1 -1
  30. package/dist/config/boot-log.js +6 -4
  31. package/dist/config/builtin-roles.js +2 -2
  32. package/dist/config/config-field-policy.js +2 -2
  33. package/dist/config/config-manager.js +1 -8
  34. package/dist/config/invoke-ipc-service.js +118 -0
  35. package/dist/config/peer-role-resolver.js +1 -1
  36. package/dist/config/provider-identity-migration.js +92 -17
  37. package/dist/config/provider-local-sync.js +2 -0
  38. package/dist/config/providers-config.js +13 -0
  39. package/dist/config/providers-management.js +100 -10
  40. package/dist/config/role-service.js +8 -8
  41. package/dist/config/role-store.js +22 -22
  42. package/dist/config/schema-migration.js +86 -88
  43. package/dist/config/snapshot.js +70 -41
  44. package/dist/config-store.js +2 -1
  45. package/dist/core/agent-reload-coordinator.js +6 -4
  46. package/dist/core/agent-runtime.js +146 -15
  47. package/dist/core/auth/delegation-authorization.js +66 -0
  48. package/dist/core/auth/operation-catalog.js +20 -0
  49. package/dist/core/baseagent-loader.js +75 -42
  50. package/dist/core/channel-loader.js +45 -13
  51. package/dist/core/channel-runtime.js +116 -45
  52. package/dist/core/command/agent-control.js +1 -1
  53. package/dist/core/command/agent-storage-menu.js +1 -1
  54. package/dist/core/command/chatmode-config.js +2 -36
  55. package/dist/core/command/command-handler.js +58 -16
  56. package/dist/core/command/data-root-resolver.js +32 -23
  57. package/dist/core/command/eventcenter-menu.js +338 -0
  58. package/dist/core/command/menu-catalog.js +8 -0
  59. package/dist/core/command/menu-handler.js +206 -87
  60. package/dist/core/command/menu-protocol.js +142 -22
  61. package/dist/core/command/menu-query-batch.js +194 -0
  62. package/dist/core/command/role-menu.js +27 -15
  63. package/dist/core/command/slash-gate.js +1 -1
  64. package/dist/core/command/slash-handler.js +34 -42
  65. package/dist/core/command/team-workspace-bootstrap.js +350 -0
  66. package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
  67. package/dist/core/command/team-workspace-initializer.js +2 -0
  68. package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
  69. package/dist/core/command/team-workspace-job-store.js +88 -0
  70. package/dist/core/command/team-workspace-management-service.js +2 -0
  71. package/dist/core/command/team-workspace-management-store.js +96 -0
  72. package/dist/core/command/team-workspace-management.js +265 -0
  73. package/dist/core/command/team-workspace-members-menu.js +88 -0
  74. package/dist/core/command/team-workspace-store.js +612 -0
  75. package/dist/core/command/team-workspace-team.js +193 -0
  76. package/dist/core/daemon-control.js +45 -15
  77. package/dist/core/daemon-lifecycle.js +478 -75
  78. package/dist/core/handoff/dispatcher.js +9 -3
  79. package/dist/core/handoff/runtime.js +130 -42
  80. package/dist/core/handoff/store.js +190 -2
  81. package/dist/core/handoff/types.js +5 -0
  82. package/dist/core/initialization/service.js +4 -4
  83. package/dist/core/invoke/executors/index.js +13 -0
  84. package/dist/core/invoke/executors/media.js +283 -0
  85. package/dist/core/invoke/executors/text.js +198 -0
  86. package/dist/core/invoke/invoke-service.js +157 -0
  87. package/dist/core/invoke/style-router.js +48 -0
  88. package/dist/core/invoke/types.js +19 -0
  89. package/dist/core/ipc-registration.js +51 -11
  90. package/dist/core/lifecycle-notice.js +10 -4
  91. package/dist/core/memory/consolidation.js +7 -5
  92. package/dist/core/message/aun-ipc-sender.js +149 -19
  93. package/dist/core/message/im-renderer.js +28 -84
  94. package/dist/core/message/message-bridge.js +57 -4
  95. package/dist/core/message/message-queue.js +46 -4
  96. package/dist/core/message/message-utils.js +10 -2
  97. package/dist/core/message/peer-mode.js +7 -34
  98. package/dist/core/message/pending-hints.js +4 -10
  99. package/dist/core/message/response-engine.js +163 -52
  100. package/dist/core/message/send-options.js +7 -4
  101. package/dist/core/message/send-routing.js +55 -7
  102. package/dist/core/ownership/owner-resolver.js +8 -0
  103. package/dist/core/permission/ec-command-parser.js +14 -3
  104. package/dist/core/permission/protected-paths.js +12 -2
  105. package/dist/core/permission/shell-environment.js +9 -0
  106. package/dist/core/session/adapters/claude-session-file-adapter.js +24 -0
  107. package/dist/core/session/adapters/codex-session-file-adapter.js +80 -0
  108. package/dist/core/session/adapters/ecagent-session-file-adapter.js +22 -0
  109. package/dist/core/session/adapters/gemini-session-file-adapter.js +39 -0
  110. package/dist/core/session/session-file-health.js +243 -0
  111. package/dist/core/session/session-fs-store.js +163 -3
  112. package/dist/core/session/session-idle-monitor.js +9 -1
  113. package/dist/core/session/session-manager.js +36 -2
  114. package/dist/core/task/task-recovery-service.js +13 -2
  115. package/dist/core/thread/command-parser.js +9 -2
  116. package/dist/core/thread/thread-operation.js +21 -2
  117. package/dist/core/thread/thread-route.js +13 -2
  118. package/dist/directory/owner-directory-admission.js +42 -30
  119. package/dist/directory/owner-directory-cache.js +143 -126
  120. package/dist/directory/owner-directory-query-operation.js +9 -8
  121. package/dist/eck/kit-renderer.js +7 -5
  122. package/dist/ecweb/basic-settings-service.js +1 -1
  123. package/dist/ecweb/message-context-service.js +0 -4
  124. package/dist/ecweb/runtime/lifecycle.js +14 -8
  125. package/dist/ecweb/runtime/supervisor.js +62 -30
  126. package/dist/event-center/admission-materializer.js +114 -0
  127. package/dist/event-center/bus-gate.js +136 -0
  128. package/dist/event-center/bus-host.js +290 -0
  129. package/dist/event-center/bus-resolver.js +120 -0
  130. package/dist/event-center/center-config.js +100 -0
  131. package/dist/event-center/client-factory.js +50 -0
  132. package/dist/event-center/daemon.js +45 -0
  133. package/dist/event-center/directory-source.js +53 -0
  134. package/dist/event-center/dispatcher.js +157 -0
  135. package/dist/event-center/event-log.js +110 -0
  136. package/dist/event-center/index-generator.js +63 -0
  137. package/dist/event-center/ipc-operation.js +308 -0
  138. package/dist/event-center/ledger.js +52 -0
  139. package/dist/event-center/pack-loader.js +202 -0
  140. package/dist/event-center/pack-manager.js +85 -0
  141. package/dist/event-center/registry.js +238 -0
  142. package/dist/event-center/runtime.js +641 -0
  143. package/dist/event-center/script-runner.js +356 -0
  144. package/dist/event-center/types.js +35 -0
  145. package/dist/event-center/validation.js +413 -0
  146. package/dist/index.js +751 -268
  147. package/dist/ipc.js +66 -12
  148. package/dist/paths.js +20 -0
  149. package/dist/product.js +14 -0
  150. package/dist/proxy/manager.js +43 -18
  151. package/dist/proxy/service-supervisor.js +78 -35
  152. package/dist/response-system/engines/v1/index.js +0 -1
  153. package/dist/response-system/modes/single-session/index.js +1 -1
  154. package/dist/services/dispatcher.js +100 -0
  155. package/dist/services/idempotency.js +90 -0
  156. package/dist/services/identity.js +52 -0
  157. package/dist/services/index-generator.js +70 -0
  158. package/dist/services/index.js +449 -0
  159. package/dist/services/ipc-operation.js +458 -0
  160. package/dist/services/ledger.js +52 -0
  161. package/dist/services/message-log.js +112 -0
  162. package/dist/services/pack-manager.js +204 -0
  163. package/dist/services/reply.js +55 -0
  164. package/dist/services/router.js +95 -0
  165. package/dist/services/script-runner.js +422 -0
  166. package/dist/services/service-payload.js +70 -0
  167. package/dist/services/types.js +18 -0
  168. package/dist/services/validation.js +297 -0
  169. package/dist/trigger/application-service.js +21 -1
  170. package/dist/trigger/audit.js +19 -4
  171. package/dist/trigger/authorization.js +14 -5
  172. package/dist/trigger/event-source.js +1 -1
  173. package/dist/trigger/history.js +176 -7
  174. package/dist/trigger/ipc-service.js +3 -1
  175. package/dist/trigger/manager.js +1 -3
  176. package/dist/trigger/scheduler.js +78 -5
  177. package/dist/trigger/script-sandbox.js +118 -22
  178. package/dist/utils/cross-platform.js +175 -13
  179. package/dist/utils/evolcore-version.js +69 -27
  180. package/dist/utils/host-info.js +11 -8
  181. package/dist/utils/instance-registry.js +19 -13
  182. package/dist/utils/npm-ops.js +48 -0
  183. package/dist/utils/process-introspect.js +109 -10
  184. package/dist/utils/startup-trace.js +222 -44
  185. package/dist/utils/windows-shell-trust.js +80 -6
  186. package/kits/docs/INDEX.md +2 -2
  187. package/kits/docs/aun/ABILITY_CALLING.md +10 -17
  188. package/kits/docs/context-assembly.md +1 -1
  189. package/kits/docs/evolcore/INDEX.md +5 -2
  190. package/kits/docs/evolcore/ability.md +4 -0
  191. package/kits/docs/evolcore/aid.md +1 -1
  192. package/kits/docs/evolcore/ctl.md +2 -1
  193. package/kits/docs/evolcore/event-center.md +207 -0
  194. package/kits/docs/evolcore/file-navigation.md +10 -264
  195. package/kits/docs/evolcore/fs.md +3 -2
  196. package/kits/docs/evolcore/group.md +2 -2
  197. package/kits/docs/evolcore/memory-architecture.md +2 -0
  198. package/kits/docs/evolcore/menu-exec-schema-commands.md +1 -1
  199. package/kits/docs/evolcore/menu-protocol.md +21 -0
  200. package/kits/docs/evolcore/msg.md +27 -8
  201. package/kits/docs/evolcore/provider.md +23 -3
  202. package/kits/docs/evolcore/response.md +5 -5
  203. package/kits/docs/evolcore/services.md +277 -0
  204. package/kits/docs/evolcore/task.md +2 -0
  205. package/kits/docs/evolcore/team-workspace.md +41 -0
  206. package/kits/eck_manifest.json +45 -7
  207. package/kits/eck_message_manifest.json +3 -3
  208. package/kits/rules/02-navigation.md +10 -1
  209. package/kits/rules/06-channel.md +5 -6
  210. package/kits/schemas/_meta.json +17 -6
  211. package/kits/schemas/agent-config.schema.19.json +5 -7
  212. package/kits/schemas/agent-config.schema.20.json +936 -0
  213. package/kits/schemas/daemon.schema.1.json +5 -0
  214. package/kits/schemas/daemon.schema.2.json +5 -0
  215. package/kits/schemas/daemon.schema.3.json +2 -1
  216. package/kits/schemas/daemon.schema.4.json +2 -1
  217. package/kits/schemas/daemon.schema.5.json +2 -1
  218. package/kits/schemas/daemon.schema.6.json +1 -1
  219. package/kits/schemas/daemon.schema.7.json +1 -1
  220. package/kits/schemas/daemon.schema.8.json +2 -1
  221. package/kits/schemas/daemon.schema.9.json +2 -1
  222. package/kits/schemas/relation-config.schema.12.json +2 -3
  223. package/kits/schemas/role-config.schema.2.json +4 -4
  224. package/kits/schemas/role-registry.schema.1.json +2 -2
  225. package/kits/schemas/single-session.schema.1.json +1 -1
  226. package/kits/schemas/single-session.schema.2.json +1 -1
  227. package/kits/schemas/single-session.schema.3.json +1 -1
  228. package/kits/skills/.switches.json +1 -5
  229. package/kits/skills/ability/SKILL.md +56 -0
  230. package/kits/skills/ability/references/calling.md +56 -0
  231. package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
  232. package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
  233. package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
  234. package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
  235. package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
  236. package/kits/skills/ec-agent-create/SKILL.md +0 -1
  237. package/kits/skills/ec-group/SKILL.md +8 -5
  238. package/kits/skills/ec-group-collaboration/SKILL.md +7 -7
  239. package/kits/skills/ec-service-proxy/SKILL.md +34 -5
  240. package/kits/skills/ec-trigger/SKILL.md +4 -4
  241. package/kits/skills/personal-assistant/SKILL.md +6 -6
  242. package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
  243. package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
  244. package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
  245. package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
  246. package/kits/skills/thread-ops/SKILL.md +10 -10
  247. package/kits/templates/system-fragments/channel.md +3 -3
  248. package/kits/templates/system-fragments/commands.md +9 -7
  249. package/kits/templates/system-fragments/reply.md +2 -6
  250. package/kits/templates/system-fragments/session.md +1 -1
  251. package/kits/templates/system-fragments/thread.md +11 -9
  252. package/package.json +5 -6
  253. package/dist/cli/pa-workspace-command.js +0 -225
  254. package/dist/core/command/pa-workspace-store.js +0 -468
  255. package/dist/core/relation/pa-team.js +0 -132
  256. package/kits/docs/evolcore/pa-workspace.md +0 -51
  257. package/kits/skills/aid-ability/SKILL.md +0 -244
  258. package/kits/skills/ec-ability/SKILL.md +0 -67
  259. package/kits/skills/ec-ability/references/workflows.md +0 -15
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { DataRootError, isPaHiddenPath, paWorkspaceStore } from './pa-workspace-store.js';
3
+ import { DataRootError, isTeamHiddenPath, teamWorkspaceStore } from './team-workspace-store.js';
4
4
  const MAX_RANGE_DAYS = 62;
5
5
  const MAX_FILES = 500;
6
6
  const MAX_RUNS_PER_TRIGGER = 200;
@@ -91,12 +91,12 @@ function collectFiles(state, navigation) {
91
91
  truncated = true;
92
92
  return;
93
93
  }
94
- if (seen.has(relativePath) || isPaHiddenPath(relativePath))
94
+ if (seen.has(relativePath) || isTeamHiddenPath(relativePath))
95
95
  return;
96
96
  seen.add(relativePath);
97
97
  let resolved;
98
98
  try {
99
- resolved = paWorkspaceStore.resolvePath(state, relativePath);
99
+ resolved = teamWorkspaceStore.resolvePath(state, relativePath);
100
100
  }
101
101
  catch {
102
102
  return;
@@ -120,7 +120,7 @@ function collectFiles(state, navigation) {
120
120
  return;
121
121
  }
122
122
  for (const name of names) {
123
- if (isPaHiddenPath(relativeChild(resolved.relativePath, name)))
123
+ if (isTeamHiddenPath(relativeChild(resolved.relativePath, name)))
124
124
  continue;
125
125
  const childPath = relativeChild(resolved.relativePath, name);
126
126
  visit({ ...entry, title: name, path: childPath, kind: 'file' }, childPath, rootEntryId);
@@ -131,7 +131,7 @@ function collectFiles(state, navigation) {
131
131
  }
132
132
  };
133
133
  for (const entry of navigation.entries) {
134
- if (entry.availability === 'unavailable' || isPaHiddenPath(entry.path))
134
+ if (entry.availability === 'unavailable' || isTeamHiddenPath(entry.path))
135
135
  continue;
136
136
  visit(entry, entry.path, entry.id);
137
137
  if (files.length >= MAX_FILES) {
@@ -141,7 +141,7 @@ function collectFiles(state, navigation) {
141
141
  }
142
142
  return { files, truncated };
143
143
  }
144
- export function queryPaWorkspaceCalendar({ state, navigation, scheduler, args }) {
144
+ export function queryTeamWorkspaceCalendar({ state, navigation, scheduler, args }) {
145
145
  const timezone = resolveTimezone(args?.timezone);
146
146
  const range = resolveRange(args, timezone);
147
147
  const byDate = new Map();
@@ -207,7 +207,7 @@ export function queryPaWorkspaceCalendar({ state, navigation, scheduler, args })
207
207
  items: items.sort((a, b) => a.at - b.at || a.title.localeCompare(b.title)),
208
208
  }));
209
209
  return {
210
- protocol: 'evol.pa-workspace',
210
+ protocol: 'evol.team-workspace',
211
211
  protocolVersion: 1,
212
212
  view: 'calendar',
213
213
  timezone,
@@ -0,0 +1,2 @@
1
+ /** Public Phase 1 entry point; implementation lives with bootstrap lifecycle code. */
2
+ export { TeamWorkspaceInitializer, TeamWorkspaceBootstrapError, resolveTeamWorkspaceIdentity, } from './team-workspace-bootstrap.js';
@@ -5,7 +5,7 @@ import { watch } from 'chokidar';
5
5
  import { parseDocument } from 'yaml';
6
6
  import { agentDataDir } from '../../paths.js';
7
7
  import { atomicWriteText } from '../../utils/atomic-write.js';
8
- import { DataRootError, isPaHiddenPath, paWorkspaceStore } from './pa-workspace-store.js';
8
+ import { DataRootError, isTeamHiddenPath, teamWorkspaceStore } from './team-workspace-store.js';
9
9
  const MAX_FILES = 10_000;
10
10
  const MAX_VISITED = 20_000;
11
11
  const MAX_PREVIEW_BYTES = 4096;
@@ -17,10 +17,10 @@ const IDLE_MS = 10 * 60_000;
17
17
  const FIELDS = ['title', 'summary', 'type', 'id', 'status', 'horizon', 'priority', 'date',
18
18
  'period', 'report_type', 'due_at', 'completed_at', 'owner_note', 'source', 'stale_checks',
19
19
  'memory_kind', 'superseded_by', 'url', 'peer', 'thread_id', 'count', 'tags'];
20
- export function validatePaWorkspaceItemsArgs(args) {
20
+ export function validateTeamWorkspaceItemsArgs(args) {
21
21
  if (typeof args.path !== 'string' || !args.path || args.path.length > 2048
22
22
  || args.path.includes('\\') || args.path.includes(':') || /[\x00-\x1f\x7f]/.test(args.path)
23
- || args.path.split('/').some(part => !part || part.startsWith('.')) || isPaHiddenPath(args.path)) {
23
+ || args.path.split('/').some(part => !part || part.startsWith('.')) || isTeamHiddenPath(args.path)) {
24
24
  throw new DataRootError('INVALID_ARGUMENT', 'items requires a user-facing relative path');
25
25
  }
26
26
  for (const [key, min, max] of [['offset', 0, MAX_FILES], ['limit', 1, 20]]) {
@@ -44,7 +44,7 @@ function within(parent, child) {
44
44
  }
45
45
  function published(state, relative) {
46
46
  return relative.length <= 2048 && !/[\\:\x00-\x1f\x7f]/.test(relative)
47
- && !isPaHiddenPath(relative) && state.entries.some(entry => entry.availability !== 'unavailable'
47
+ && !isTeamHiddenPath(relative) && state.entries.some(entry => entry.availability !== 'unavailable'
48
48
  && (entry.path === relative || entry.kind === 'directory' && within(entry.path, relative)));
49
49
  }
50
50
  function clip(value, bytes) {
@@ -103,18 +103,18 @@ async function preview(realPath, size) {
103
103
  }
104
104
  }
105
105
  /** Derived private cache. No Skill files, workspace content or directory layouts are modified. */
106
- export class PaWorkspaceItemsIndex {
106
+ export class TeamWorkspaceItemsIndex {
107
107
  store;
108
108
  indexes = new Map();
109
- constructor(store = paWorkspaceStore) {
109
+ constructor(store = teamWorkspaceStore) {
110
110
  this.store = store;
111
111
  }
112
- warm(paAid, state) {
112
+ warm(agentAid, state) {
113
113
  // Navigation must not wait for cache JSON parsing or filesystem discovery.
114
114
  setImmediate(() => {
115
115
  try {
116
- this.assertCurrent(paAid, state);
117
- const index = this.get(paAid, state);
116
+ this.assertCurrent(agentAid, state);
117
+ const index = this.get(agentAid, state);
118
118
  void this.refresh(index).then(async () => {
119
119
  // Only the first page of each entry needs to be ready before a click.
120
120
  const firstPages = state.entries.flatMap(entry => index.sorted.filter(item => within(entry.path, item.path)).slice(0, 20));
@@ -125,25 +125,26 @@ export class PaWorkspaceItemsIndex {
125
125
  catch { /* Binding may have changed since the navigation response. */ }
126
126
  }).unref();
127
127
  }
128
- assertCurrent(paAid, state) {
129
- const current = this.store.require(paAid);
128
+ assertCurrent(agentAid, state) {
129
+ const current = this.store.require(agentAid);
130
130
  if (current.workspaceId !== state.workspaceId || current.ownerAid !== state.ownerAid
131
- || current.rootPath !== state.rootPath || current.navigationRevision !== state.navigationRevision) {
132
- throw new DataRootError('WORKSPACE_CHANGED', 'PA workspace changed during query');
131
+ || current.rootPath !== state.rootPath || current.outputRootPath !== state.outputRootPath
132
+ || current.navigationRevision !== state.navigationRevision) {
133
+ throw new DataRootError('WORKSPACE_CHANGED', 'Team workspace changed during query');
133
134
  }
134
135
  }
135
- async query(paAid, state, args) {
136
- validatePaWorkspaceItemsArgs(args);
137
- this.assertCurrent(paAid, state);
136
+ async query(agentAid, state, args) {
137
+ validateTeamWorkspaceItemsArgs(args);
138
+ this.assertCurrent(agentAid, state);
138
139
  const requestedPath = args.path;
139
140
  if (!published(state, requestedPath))
140
- throw new DataRootError('FORBIDDEN', 'Path is not published in PA navigation');
141
+ throw new DataRootError('FORBIDDEN', 'Path is not published in Team navigation');
141
142
  this.store.resolvePath(state, requestedPath);
142
- const index = this.get(paAid, state);
143
+ const index = this.get(agentAid, state);
143
144
  await this.refresh(index);
144
- this.assertCurrent(paAid, state);
145
+ this.assertCurrent(agentAid, state);
145
146
  if (args.indexRevision !== undefined && args.indexRevision !== index.revision) {
146
- throw new DataRootError('INDEX_CHANGED', 'PA items changed; restart pagination');
147
+ throw new DataRootError('INDEX_CHANGED', 'Team workspace items changed; restart pagination');
147
148
  }
148
149
  const snapshotRevision = index.revision;
149
150
  const matching = index.sorted.filter(item => within(requestedPath, item.path));
@@ -151,9 +152,9 @@ export class PaWorkspaceItemsIndex {
151
152
  const limit = Number(args.limit ?? 20);
152
153
  const window = matching.slice(offset, offset + limit);
153
154
  const parsed = await this.prepare(index, window);
154
- this.assertCurrent(paAid, state);
155
+ this.assertCurrent(agentAid, state);
155
156
  if (index.closed || snapshotRevision !== index.revision) {
156
- throw new DataRootError('INDEX_CHANGED', 'PA items changed; restart pagination');
157
+ throw new DataRootError('INDEX_CHANGED', 'Team workspace items changed; restart pagination');
157
158
  }
158
159
  // Revalidate only the returned page, including canonical paths, before any
159
160
  // cached private text leaves Core. A missed watcher event cannot leak it.
@@ -166,7 +167,7 @@ export class PaWorkspaceItemsIndex {
166
167
  catch {
167
168
  index.dirty.add(item.path);
168
169
  await this.refresh(index);
169
- throw new DataRootError('INDEX_CHANGED', 'PA items changed; restart pagination');
170
+ throw new DataRootError('INDEX_CHANGED', 'Team workspace items changed; restart pagination');
170
171
  }
171
172
  }
172
173
  if (offset > matching.length)
@@ -175,7 +176,7 @@ export class PaWorkspaceItemsIndex {
175
176
  this.persist(index);
176
177
  const next = offset + window.length;
177
178
  const response = {
178
- protocol: 'evol.pa-workspace', protocolVersion: 1, view: 'items',
179
+ protocol: 'evol.team-workspace', protocolVersion: 1, view: 'items',
179
180
  workspaceId: state.workspaceId, navigationRevision: state.navigationRevision,
180
181
  indexRevision: index.revision, path: requestedPath, offset,
181
182
  total: matching.length, nextOffset: next < matching.length ? next : null,
@@ -191,17 +192,17 @@ export class PaWorkspaceItemsIndex {
191
192
  }
192
193
  return response;
193
194
  }
194
- get(paAid, state) {
195
- const key = crypto.createHash('sha256').update(JSON.stringify([paAid, state.ownerAid,
196
- state.workspaceId, this.store.root(state), state.navigationRevision, state.entries])).digest('hex');
197
- let index = this.indexes.get(paAid);
195
+ get(agentAid, state) {
196
+ const key = crypto.createHash('sha256').update(JSON.stringify([agentAid, state.ownerAid,
197
+ state.workspaceId, this.store.root(state), this.store.outputRoot(state), state.navigationRevision, state.entries])).digest('hex');
198
+ let index = this.indexes.get(agentAid);
198
199
  if (!index || index.key !== key) {
199
200
  if (index)
200
201
  this.release(index);
201
- index = { key, paAid, state, revision: crypto.randomBytes(12).toString('hex'), items: new Map(),
202
+ index = { key, agentAid, state, revision: crypto.randomBytes(12).toString('hex'), items: new Map(),
202
203
  sorted: [], truncated: false, scannedAt: 0, dirty: new Set(), rescan: true, closed: false,
203
204
  previewRequests: new Map(), previewQueue: [], activePreviews: 0 };
204
- this.indexes.set(paAid, index);
205
+ this.indexes.set(agentAid, index);
205
206
  // Disk is only a parse memo. Always reconcile directories before serving
206
207
  // it after restart; navigationRevision does not version file contents.
207
208
  try {
@@ -230,8 +231,8 @@ export class PaWorkspaceItemsIndex {
230
231
  clearTimeout(index.idle);
231
232
  index.idle = setTimeout(() => {
232
233
  this.release(index);
233
- if (this.indexes.get(paAid) === index)
234
- this.indexes.delete(paAid);
234
+ if (this.indexes.get(agentAid) === index)
235
+ this.indexes.delete(agentAid);
235
236
  }, IDLE_MS);
236
237
  index.idle.unref();
237
238
  // Bound watcher count even on a host with many PAs.
@@ -239,14 +240,14 @@ export class PaWorkspaceItemsIndex {
239
240
  const oldest = [...this.indexes.values()].find(candidate => candidate !== index && !candidate.pending);
240
241
  if (oldest) {
241
242
  this.release(oldest);
242
- this.indexes.delete(oldest.paAid);
243
+ this.indexes.delete(oldest.agentAid);
243
244
  }
244
245
  }
245
246
  return index;
246
247
  }
247
- cachePath(index) { return path.join(agentDataDir(index.paAid), 'pa-workspace-items-v1.json'); }
248
+ cachePath(index) { return path.join(agentDataDir(index.agentAid), 'team-workspace-items-v1.json'); }
248
249
  persist(index) {
249
- if (index.closed || this.indexes.get(index.paAid) !== index)
250
+ if (index.closed || this.indexes.get(index.agentAid) !== index)
250
251
  return;
251
252
  try {
252
253
  atomicWriteText(this.cachePath(index), JSON.stringify({ version: 1, key: index.key, items: index.sorted }));
@@ -265,18 +266,18 @@ export class PaWorkspaceItemsIndex {
265
266
  index.activePreviews++;
266
267
  void (async () => {
267
268
  if (index.closed)
268
- throw new DataRootError('WORKSPACE_CHANGED', 'PA workspace index was replaced');
269
+ throw new DataRootError('WORKSPACE_CHANGED', 'Team workspace index was replaced');
269
270
  let resolved;
270
271
  try {
271
272
  resolved = this.store.resolvePath(index.state, item.path);
272
273
  }
273
274
  catch {
274
275
  index.dirty.add(item.path);
275
- throw new DataRootError('INDEX_CHANGED', 'PA file changed during preview read');
276
+ throw new DataRootError('INDEX_CHANGED', 'Team workspace file changed during preview read');
276
277
  }
277
278
  if (resolved.realPath !== item.realPath || signature(resolved.stat) !== item.signature) {
278
279
  index.dirty.add(item.path);
279
- throw new DataRootError('INDEX_CHANGED', 'PA file changed during preview read');
280
+ throw new DataRootError('INDEX_CHANGED', 'Team workspace file changed during preview read');
280
281
  }
281
282
  try {
282
283
  item.previewSource = await preview(resolved.realPath, item.size);
@@ -304,41 +305,54 @@ export class PaWorkspaceItemsIndex {
304
305
  index.previewQueue.shift()();
305
306
  }
306
307
  observe(index) {
307
- const root = this.store.root(index.state);
308
- const allowed = index.state.entries.filter(entry => entry.availability !== 'unavailable');
309
- const watcher = watch(root, {
310
- persistent: false, ignoreInitial: true, followSymlinks: false,
311
- ignored: absolute => {
308
+ const workspaceRoot = this.store.root(index.state);
309
+ const outputRoot = this.store.outputRoot(index.state);
310
+ const roots = [
311
+ { root: workspaceRoot, output: false },
312
+ ...(outputRoot && outputRoot !== workspaceRoot ? [{ root: outputRoot, output: true }] : []),
313
+ ];
314
+ index.watchers = roots.map(({ root, output }) => {
315
+ const allowed = index.state.entries.filter(entry => entry.availability !== 'unavailable'
316
+ && (output ? entry.path === 'output' || entry.path.startsWith('output/') : !outputRoot || entry.path !== 'output' && !entry.path.startsWith('output/')));
317
+ const logicalPath = (relative) => output
318
+ ? relative ? `output/${relative}` : 'output'
319
+ : relative;
320
+ const watcher = watch(root, {
321
+ persistent: false, ignoreInitial: true, followSymlinks: false,
322
+ ignored: absolute => {
323
+ const relative = path.relative(root, absolute).split(path.sep).join('/');
324
+ const logical = logicalPath(relative);
325
+ return relative !== '' && (isTeamHiddenPath(logical) || !allowed.some(entry => within(logical, entry.path) || entry.kind === 'directory' && within(entry.path, logical)));
326
+ },
327
+ });
328
+ watcher.on('all', (event, absolute) => {
329
+ if (index.closed)
330
+ return;
312
331
  const relative = path.relative(root, absolute).split(path.sep).join('/');
313
- return relative !== '' && (isPaHiddenPath(relative) || !allowed.some(entry => within(relative, entry.path) || entry.kind === 'directory' && within(entry.path, relative)));
314
- },
315
- });
316
- index.watcher = watcher;
317
- watcher.on('all', (event, absolute) => {
318
- if (index.closed)
319
- return;
320
- const relative = path.relative(root, absolute).split(path.sep).join('/');
321
- if (event === 'addDir' || event === 'unlinkDir')
322
- index.rescan = true;
323
- else if (published(index.state, relative))
324
- index.dirty.add(relative);
325
- clearTimeout(index.timer);
326
- index.timer = setTimeout(() => { void this.refresh(index).catch(() => { index.rescan = true; }); }, 75);
327
- index.timer.unref();
332
+ const logical = logicalPath(relative);
333
+ if (event === 'addDir' || event === 'unlinkDir')
334
+ index.rescan = true;
335
+ else if (published(index.state, logical))
336
+ index.dirty.add(logical);
337
+ clearTimeout(index.timer);
338
+ index.timer = setTimeout(() => { void this.refresh(index).catch(() => { index.rescan = true; }); }, 75);
339
+ index.timer.unref();
340
+ });
341
+ watcher.on('ready', () => { index.rescan = true; });
342
+ watcher.on('error', () => { index.rescan = true; });
343
+ return watcher;
328
344
  });
329
- watcher.on('ready', () => { index.rescan = true; });
330
- watcher.on('error', () => { index.rescan = true; });
331
345
  }
332
346
  refresh(index) {
333
347
  try {
334
348
  if (index.closed)
335
- throw new DataRootError('WORKSPACE_CHANGED', 'PA workspace index was replaced');
336
- this.assertCurrent(index.paAid, index.state);
349
+ throw new DataRootError('WORKSPACE_CHANGED', 'Team workspace index was replaced');
350
+ this.assertCurrent(index.agentAid, index.state);
337
351
  }
338
352
  catch (error) {
339
353
  this.release(index);
340
- if (this.indexes.get(index.paAid) === index)
341
- this.indexes.delete(index.paAid);
354
+ if (this.indexes.get(index.agentAid) === index)
355
+ this.indexes.delete(index.agentAid);
342
356
  return Promise.reject(error);
343
357
  }
344
358
  if (index.pending)
@@ -352,7 +366,7 @@ export class PaWorkspaceItemsIndex {
352
366
  if (!index.rescan && !index.dirty.size)
353
367
  return;
354
368
  }
355
- throw new DataRootError('INDEX_CHANGED', 'PA items are changing; retry the first page');
369
+ throw new DataRootError('INDEX_CHANGED', 'Team workspace items are changing; retry the first page');
356
370
  })().catch(error => { index.rescan = true; throw error; })
357
371
  .finally(() => { index.pending = undefined; });
358
372
  return index.pending;
@@ -471,7 +485,8 @@ export class PaWorkspaceItemsIndex {
471
485
  index.closed = true;
472
486
  clearTimeout(index.timer);
473
487
  clearTimeout(index.idle);
474
- void index.watcher?.close();
488
+ for (const watcher of index.watchers ?? [])
489
+ void watcher.close();
475
490
  }
476
491
  async close() {
477
492
  const indexes = [...this.indexes.values()];
@@ -480,7 +495,7 @@ export class PaWorkspaceItemsIndex {
480
495
  this.indexes.clear();
481
496
  await Promise.all(indexes.map(index => index.pending?.catch(() => { })));
482
497
  await Promise.all(indexes.flatMap(index => [...index.previewRequests.values()].map(request => request.catch(() => { }))));
483
- await Promise.all(indexes.map(index => index.watcher?.close()));
498
+ await Promise.all(indexes.flatMap(index => (index.watchers ?? []).map(watcher => watcher.close())));
484
499
  }
485
500
  }
486
- export const paWorkspaceItemsIndex = new PaWorkspaceItemsIndex();
501
+ export const teamWorkspaceItemsIndex = new TeamWorkspaceItemsIndex();
@@ -0,0 +1,88 @@
1
+ import path from 'node:path';
2
+ import crypto from 'node:crypto';
3
+ import { agentDataDir } from '../../paths.js';
4
+ import { atomicReadJson, atomicWriteJson } from '../../utils/atomic-write.js';
5
+ import { isValidAid } from '../../aun/aid/validation.js';
6
+ export class TeamWorkspaceJobError extends Error {
7
+ code;
8
+ constructor(code, message) {
9
+ super(message);
10
+ this.code = code;
11
+ this.name = 'TeamWorkspaceJobError';
12
+ }
13
+ }
14
+ const JOB_FILE = 'team-workspace-jobs-v1.json';
15
+ const JOB_TTL_MS = 24 * 60 * 60 * 1000;
16
+ function jobPath(agentAid) { return path.join(agentDataDir(agentAid), JOB_FILE); }
17
+ export class TeamWorkspaceJobStore {
18
+ now;
19
+ constructor(now = () => Date.now()) {
20
+ this.now = now;
21
+ }
22
+ create(input) {
23
+ if (!isValidAid(input.agentAid) || !isValidAid(input.ownerAid) || !isValidAid(input.principalId)) {
24
+ throw new TeamWorkspaceJobError('INVALID_ARGUMENT', 'Invalid Team workspace job identity');
25
+ }
26
+ const now = this.now();
27
+ const jobs = this.readAll(input.agentAid).filter(job => job.expiresAt > now);
28
+ const existing = jobs.find(job => job.operationId === input.operationId);
29
+ if (existing) {
30
+ if (existing.fingerprint !== input.fingerprint || existing.principalId !== input.principalId) {
31
+ throw new TeamWorkspaceJobError('OPERATION_ID_REUSED', 'operationId was already used with different arguments');
32
+ }
33
+ return existing;
34
+ }
35
+ const job = {
36
+ ...input,
37
+ jobId: `teamj_${crypto.randomBytes(18).toString('base64url')}`,
38
+ status: 'accepted', progress: 0, createdAt: now, updatedAt: now, expiresAt: now + JOB_TTL_MS,
39
+ };
40
+ this.writeAll(input.agentAid, [...jobs, job]);
41
+ return job;
42
+ }
43
+ update(agentAid, jobId, patch) {
44
+ const jobs = this.readAll(agentAid);
45
+ const index = jobs.findIndex(job => job.jobId === jobId);
46
+ if (index < 0)
47
+ throw new TeamWorkspaceJobError('JOB_EXPIRED', 'Team workspace job is no longer available');
48
+ const job = { ...jobs[index], ...patch, updatedAt: this.now() };
49
+ jobs[index] = job;
50
+ this.writeAll(agentAid, jobs);
51
+ return job;
52
+ }
53
+ get(agentAid, jobId, principalId) {
54
+ const job = this.readAll(agentAid).find(candidate => candidate.jobId === jobId);
55
+ if (!job || job.expiresAt <= this.now())
56
+ throw new TeamWorkspaceJobError('JOB_EXPIRED', 'Team workspace job is no longer available');
57
+ if (job.principalId !== principalId)
58
+ throw new TeamWorkspaceJobError('FORBIDDEN', 'Team workspace job belongs to another principal');
59
+ return job;
60
+ }
61
+ readAll(agentAid) {
62
+ try {
63
+ const value = atomicReadJson(jobPath(agentAid));
64
+ if (!value || typeof value !== 'object' || Array.isArray(value))
65
+ return [];
66
+ const jobs = value.jobs;
67
+ return Array.isArray(jobs) ? jobs.filter(job => this.validJob(job)) : [];
68
+ }
69
+ catch {
70
+ return [];
71
+ }
72
+ }
73
+ writeAll(agentAid, jobs) {
74
+ atomicWriteJson(jobPath(agentAid), { version: 1, jobs: jobs.slice(-100) });
75
+ }
76
+ validJob(value) {
77
+ if (!value || typeof value !== 'object' || Array.isArray(value))
78
+ return false;
79
+ const job = value;
80
+ return typeof job.jobId === 'string' && typeof job.operationId === 'string'
81
+ && typeof job.fingerprint === 'string' && isValidAid(String(job.agentAid))
82
+ && isValidAid(String(job.ownerAid)) && isValidAid(String(job.principalId))
83
+ && job.type === 'initialize'
84
+ && ['accepted', 'running', 'succeeded', 'failed', 'expired'].includes(String(job.status))
85
+ && Number.isFinite(job.createdAt) && Number.isFinite(job.updatedAt) && Number.isFinite(job.expiresAt);
86
+ }
87
+ }
88
+ export const teamWorkspaceJobStore = new TeamWorkspaceJobStore();
@@ -0,0 +1,2 @@
1
+ /** Public Phase 2 entry point; kept separate for App/Core integration imports. */
2
+ export { TeamWorkspaceManagementService, TEAM_WORKSPACE_MANAGEMENT_PROTOCOL, TEAM_WORKSPACE_MANAGEMENT_VERSION, scanWorkspaceStatistics, teamWorkspaceManagementService, } from './team-workspace-management.js';
@@ -0,0 +1,96 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import crypto from 'node:crypto';
4
+ import { agentDataDir } from '../../paths.js';
5
+ import { atomicReadJson, atomicWriteJson } from '../../utils/atomic-write.js';
6
+ import { isValidAid } from '../../aun/aid/validation.js';
7
+ const STATE_FILE = 'team-workspace-management-v1.json';
8
+ function statePath(agentAid) {
9
+ return path.join(agentDataDir(agentAid), STATE_FILE);
10
+ }
11
+ export class TeamWorkspaceManagementStore {
12
+ read(agentAid) {
13
+ if (!isValidAid(agentAid))
14
+ return null;
15
+ let value;
16
+ try {
17
+ value = atomicReadJson(statePath(agentAid));
18
+ }
19
+ catch {
20
+ return null;
21
+ }
22
+ if (!value || typeof value !== 'object' || Array.isArray(value))
23
+ return null;
24
+ const record = value;
25
+ if (record.version !== 1 || record.agentAid !== agentAid || typeof record.ownerAid !== 'string'
26
+ || !['unconfigured', 'initializing', 'ready', 'failed', 'unavailable'].includes(String(record.status))
27
+ || !Number.isSafeInteger(record.attempts) || !Number.isFinite(record.updatedAt))
28
+ return null;
29
+ return {
30
+ version: 1,
31
+ agentAid,
32
+ ownerAid: record.ownerAid,
33
+ status: record.status,
34
+ attempts: Number(record.attempts),
35
+ ...(Number.isFinite(record.createdAt) ? { createdAt: Number(record.createdAt) } : {}),
36
+ ...(Number.isFinite(record.boundAt) ? { boundAt: Number(record.boundAt) } : {}),
37
+ updatedAt: Number(record.updatedAt),
38
+ ...(typeof record.activeJobId === 'string' ? { activeJobId: record.activeJobId } : {}),
39
+ ...(record.lastError && typeof record.lastError === 'object' && !Array.isArray(record.lastError)
40
+ ? { lastError: {
41
+ code: String(record.lastError.code || 'INITIALIZE_FAILED'),
42
+ message: String(record.lastError.message || 'Workspace initialization failed'),
43
+ retryable: record.lastError.retryable !== false,
44
+ } }
45
+ : {}),
46
+ };
47
+ }
48
+ ensure(agentAid, ownerAid, now = Date.now()) {
49
+ const current = this.read(agentAid);
50
+ if (current && current.ownerAid === ownerAid)
51
+ return current;
52
+ const next = {
53
+ version: 1, agentAid, ownerAid, status: 'unconfigured', attempts: 0, updatedAt: now,
54
+ };
55
+ this.write(agentAid, next);
56
+ return next;
57
+ }
58
+ update(agentAid, patch, now = Date.now()) {
59
+ const current = this.read(agentAid);
60
+ if (!current)
61
+ throw new Error(`Team workspace management state is unavailable: ${agentAid}`);
62
+ const next = { ...current, ...patch, updatedAt: now, version: 1, agentAid };
63
+ this.write(agentAid, next);
64
+ return next;
65
+ }
66
+ write(agentAid, value) {
67
+ atomicWriteJson(statePath(agentAid), value);
68
+ }
69
+ }
70
+ export const teamWorkspaceManagementStore = new TeamWorkspaceManagementStore();
71
+ export function workspaceMarkerPath(rootPath) {
72
+ return path.join(rootPath, '.workspace', 'marker.json');
73
+ }
74
+ export function readWorkspaceMarker(rootPath) {
75
+ try {
76
+ const value = JSON.parse(fs.readFileSync(workspaceMarkerPath(rootPath), 'utf8'));
77
+ if (value.schemaVersion !== 1 || !isValidAid(String(value.agentAid)) || !isValidAid(String(value.ownerAid))
78
+ || value.workspaceVersion !== 1 || !Number.isFinite(value.createdAt) || value.initializedBy !== 'evolcore')
79
+ return null;
80
+ return {
81
+ schemaVersion: 1,
82
+ agentAid: String(value.agentAid),
83
+ ownerAid: String(value.ownerAid),
84
+ workspaceVersion: 1,
85
+ createdAt: Number(value.createdAt),
86
+ initializedBy: 'evolcore',
87
+ ...(typeof value.workspaceId === 'string' ? { workspaceId: value.workspaceId } : {}),
88
+ };
89
+ }
90
+ catch {
91
+ return null;
92
+ }
93
+ }
94
+ export function newOpaqueWorkspaceId() {
95
+ return `tw1_${crypto.randomBytes(18).toString('base64url')}`;
96
+ }