evolcore 0.0.43-test.6 → 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 (197) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/bin/ecmsg.js +171 -54
  3. package/dist/agents/baseagent-availability.js +1 -1
  4. package/dist/agents/codex/app-server-client.js +22 -0
  5. package/dist/agents/codex-runner.js +69 -2
  6. package/dist/aun/msg/p2p.js +6 -1
  7. package/dist/channels/aun.js +234 -21
  8. package/dist/cli/agent-create.js +2 -2
  9. package/dist/cli/daemon-commands.js +6 -66
  10. package/dist/cli/daemon-lifecycle-client.js +61 -0
  11. package/dist/cli/ecmsg-gateway.js +35 -2
  12. package/dist/cli/events-command.js +73 -0
  13. package/dist/cli/index.js +31 -14
  14. package/dist/cli/invoke-command.js +182 -0
  15. package/dist/cli/managed-command-guard.js +6 -1
  16. package/dist/cli/restart-monitor.js +45 -47
  17. package/dist/cli/services-command.js +111 -0
  18. package/dist/cli/team-workspace-command.js +134 -0
  19. package/dist/cli/thread-command.js +6 -2
  20. package/dist/cli/watch-msg.js +1 -1
  21. package/dist/config/config-field-policy.js +2 -2
  22. package/dist/config/config-manager.js +0 -7
  23. package/dist/config/invoke-ipc-service.js +118 -0
  24. package/dist/config/schema-migration.js +6 -1
  25. package/dist/config-store.js +2 -1
  26. package/dist/core/agent-reload-coordinator.js +6 -4
  27. package/dist/core/agent-runtime.js +104 -10
  28. package/dist/core/auth/delegation-authorization.js +66 -0
  29. package/dist/core/auth/operation-catalog.js +20 -0
  30. package/dist/core/baseagent-loader.js +60 -130
  31. package/dist/core/channel-loader.js +10 -1
  32. package/dist/core/channel-runtime.js +4 -3
  33. package/dist/core/command/agent-control.js +1 -1
  34. package/dist/core/command/agent-storage-menu.js +1 -1
  35. package/dist/core/command/chatmode-config.js +2 -36
  36. package/dist/core/command/command-handler.js +53 -11
  37. package/dist/core/command/data-root-resolver.js +32 -23
  38. package/dist/core/command/eventcenter-menu.js +338 -0
  39. package/dist/core/command/menu-catalog.js +8 -0
  40. package/dist/core/command/menu-handler.js +198 -84
  41. package/dist/core/command/menu-protocol.js +60 -11
  42. package/dist/core/command/menu-query-batch.js +194 -0
  43. package/dist/core/command/slash-gate.js +1 -1
  44. package/dist/core/command/slash-handler.js +34 -42
  45. package/dist/core/command/team-workspace-bootstrap.js +350 -0
  46. package/dist/core/command/{pa-workspace-calendar.js → team-workspace-calendar.js} +7 -7
  47. package/dist/core/command/team-workspace-initializer.js +2 -0
  48. package/dist/core/command/{pa-workspace-items.js → team-workspace-items.js} +83 -68
  49. package/dist/core/command/team-workspace-job-store.js +88 -0
  50. package/dist/core/command/team-workspace-management-service.js +2 -0
  51. package/dist/core/command/team-workspace-management-store.js +96 -0
  52. package/dist/core/command/team-workspace-management.js +265 -0
  53. package/dist/core/command/team-workspace-members-menu.js +88 -0
  54. package/dist/core/command/team-workspace-store.js +612 -0
  55. package/dist/core/command/team-workspace-team.js +193 -0
  56. package/dist/core/daemon-control.js +8 -5
  57. package/dist/core/daemon-lifecycle.js +132 -73
  58. package/dist/core/handoff/runtime.js +3 -3
  59. package/dist/core/invoke/executors/index.js +13 -0
  60. package/dist/core/invoke/executors/media.js +283 -0
  61. package/dist/core/invoke/executors/text.js +198 -0
  62. package/dist/core/invoke/invoke-service.js +157 -0
  63. package/dist/core/invoke/style-router.js +48 -0
  64. package/dist/core/invoke/types.js +19 -0
  65. package/dist/core/ipc-registration.js +46 -7
  66. package/dist/core/memory/consolidation.js +7 -5
  67. package/dist/core/message/aun-ipc-sender.js +147 -17
  68. package/dist/core/message/im-renderer.js +28 -84
  69. package/dist/core/message/message-bridge.js +4 -0
  70. package/dist/core/message/message-utils.js +10 -2
  71. package/dist/core/message/peer-mode.js +7 -34
  72. package/dist/core/message/response-engine.js +157 -54
  73. package/dist/core/message/send-options.js +7 -4
  74. package/dist/core/message/send-routing.js +43 -5
  75. package/dist/core/ownership/owner-resolver.js +7 -0
  76. package/dist/core/permission/ec-command-parser.js +3 -2
  77. package/dist/core/permission/protected-paths.js +12 -2
  78. package/dist/core/permission/shell-environment.js +9 -0
  79. package/dist/core/session/session-file-health.js +243 -0
  80. package/dist/core/session/session-fs-store.js +2 -3
  81. package/dist/core/task/task-recovery-service.js +13 -2
  82. package/dist/core/thread/command-parser.js +9 -2
  83. package/dist/core/thread/thread-operation.js +21 -2
  84. package/dist/core/thread/thread-route.js +13 -2
  85. package/dist/directory/owner-directory-admission.js +40 -53
  86. package/dist/directory/owner-directory-cache.js +89 -113
  87. package/dist/directory/owner-directory-query-operation.js +8 -10
  88. package/dist/eck/kit-renderer.js +7 -5
  89. package/dist/ecweb/basic-settings-service.js +1 -1
  90. package/dist/ecweb/message-context-service.js +0 -4
  91. package/dist/ecweb/runtime/lifecycle.js +6 -2
  92. package/dist/ecweb/runtime/supervisor.js +19 -4
  93. package/dist/event-center/admission-materializer.js +114 -0
  94. package/dist/event-center/bus-gate.js +136 -0
  95. package/dist/event-center/bus-host.js +290 -0
  96. package/dist/event-center/bus-resolver.js +120 -0
  97. package/dist/event-center/center-config.js +100 -0
  98. package/dist/event-center/client-factory.js +50 -0
  99. package/dist/event-center/daemon.js +45 -0
  100. package/dist/event-center/directory-source.js +53 -0
  101. package/dist/event-center/dispatcher.js +157 -0
  102. package/dist/event-center/event-log.js +110 -0
  103. package/dist/event-center/index-generator.js +63 -0
  104. package/dist/event-center/ipc-operation.js +308 -0
  105. package/dist/event-center/ledger.js +52 -0
  106. package/dist/event-center/pack-loader.js +202 -0
  107. package/dist/event-center/pack-manager.js +85 -0
  108. package/dist/event-center/registry.js +238 -0
  109. package/dist/event-center/runtime.js +641 -0
  110. package/dist/event-center/script-runner.js +356 -0
  111. package/dist/event-center/types.js +35 -0
  112. package/dist/event-center/validation.js +413 -0
  113. package/dist/index.js +285 -99
  114. package/dist/ipc.js +66 -12
  115. package/dist/paths.js +20 -0
  116. package/dist/product.js +14 -0
  117. package/dist/proxy/manager.js +5 -1
  118. package/dist/proxy/service-supervisor.js +13 -4
  119. package/dist/response-system/engines/v1/index.js +0 -1
  120. package/dist/response-system/modes/single-session/index.js +1 -1
  121. package/dist/services/dispatcher.js +100 -0
  122. package/dist/services/idempotency.js +90 -0
  123. package/dist/services/identity.js +52 -0
  124. package/dist/services/index-generator.js +70 -0
  125. package/dist/services/index.js +449 -0
  126. package/dist/services/ipc-operation.js +458 -0
  127. package/dist/services/ledger.js +52 -0
  128. package/dist/services/message-log.js +112 -0
  129. package/dist/services/pack-manager.js +204 -0
  130. package/dist/services/reply.js +55 -0
  131. package/dist/services/router.js +95 -0
  132. package/dist/services/script-runner.js +422 -0
  133. package/dist/services/service-payload.js +70 -0
  134. package/dist/services/types.js +18 -0
  135. package/dist/services/validation.js +297 -0
  136. package/dist/trigger/application-service.js +18 -0
  137. package/dist/trigger/event-source.js +1 -1
  138. package/dist/trigger/ipc-service.js +3 -1
  139. package/dist/trigger/script-sandbox.js +118 -22
  140. package/dist/utils/cross-platform.js +24 -10
  141. package/dist/utils/evolcore-version.js +69 -27
  142. package/dist/utils/instance-registry.js +19 -13
  143. package/dist/utils/process-introspect.js +45 -9
  144. package/dist/utils/startup-trace.js +74 -37
  145. package/dist/utils/windows-shell-trust.js +80 -6
  146. package/kits/docs/INDEX.md +2 -2
  147. package/kits/docs/aun/ABILITY_CALLING.md +7 -14
  148. package/kits/docs/context-assembly.md +1 -1
  149. package/kits/docs/evolcore/INDEX.md +2 -0
  150. package/kits/docs/evolcore/ability.md +4 -0
  151. package/kits/docs/evolcore/aid.md +1 -1
  152. package/kits/docs/evolcore/event-center.md +207 -0
  153. package/kits/docs/evolcore/file-navigation.md +10 -264
  154. package/kits/docs/evolcore/fs.md +3 -2
  155. package/kits/docs/evolcore/group.md +1 -1
  156. package/kits/docs/evolcore/memory-architecture.md +2 -0
  157. package/kits/docs/evolcore/menu-protocol.md +21 -0
  158. package/kits/docs/evolcore/msg.md +15 -3
  159. package/kits/docs/evolcore/provider.md +3 -1
  160. package/kits/docs/evolcore/response.md +5 -5
  161. package/kits/docs/evolcore/services.md +277 -0
  162. package/kits/docs/evolcore/task.md +2 -0
  163. package/kits/docs/evolcore/team-workspace.md +41 -0
  164. package/kits/eck_manifest.json +26 -0
  165. package/kits/rules/02-navigation.md +10 -1
  166. package/kits/schemas/_meta.json +17 -6
  167. package/kits/schemas/agent-config.schema.19.json +5 -7
  168. package/kits/schemas/agent-config.schema.20.json +936 -0
  169. package/kits/schemas/relation-config.schema.12.json +2 -3
  170. package/kits/schemas/role-config.schema.2.json +4 -4
  171. package/kits/skills/.switches.json +1 -5
  172. package/kits/skills/ability/SKILL.md +56 -0
  173. package/kits/skills/ability/references/calling.md +56 -0
  174. package/kits/skills/{ec-ability → ability}/references/contract-checklist.md +1 -1
  175. package/kits/skills/{ec-ability → ability}/references/development.md +9 -33
  176. package/kits/skills/{ec-ability → ability}/references/management.md +2 -2
  177. package/kits/skills/{ec-ability → ability}/references/recovery.md +1 -1
  178. package/kits/skills/{ec-ability → ability}/references/runtime-protocol.md +2 -0
  179. package/kits/skills/ec-agent-create/SKILL.md +0 -1
  180. package/kits/skills/ec-service-proxy/SKILL.md +34 -5
  181. package/kits/skills/personal-assistant/SKILL.md +6 -6
  182. package/kits/skills/personal-assistant/references/02-bootstrap.md +4 -4
  183. package/kits/skills/personal-assistant/scripts/clean.mjs +4 -4
  184. package/kits/skills/personal-assistant/scripts/init.mjs +2 -2
  185. package/kits/skills/personal-assistant/scripts/pa.mjs +4 -4
  186. package/kits/templates/system-fragments/channel.md +3 -3
  187. package/kits/templates/system-fragments/commands.md +5 -3
  188. package/kits/templates/system-fragments/reply.md +0 -5
  189. package/kits/templates/system-fragments/thread.md +10 -8
  190. package/package.json +3 -5
  191. package/dist/cli/pa-workspace-command.js +0 -225
  192. package/dist/core/command/pa-workspace-store.js +0 -468
  193. package/dist/core/relation/pa-team.js +0 -132
  194. package/kits/docs/evolcore/pa-workspace.md +0 -51
  195. package/kits/skills/aid-ability/SKILL.md +0 -244
  196. package/kits/skills/ec-ability/SKILL.md +0 -67
  197. package/kits/skills/ec-ability/references/workflows.md +0 -15
@@ -0,0 +1,350 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { atomicWriteJson } from '../../utils/atomic-write.js';
4
+ import { agentDataDir, agentOutputDir, agentWorkspaceDir, legacyTeamWorkspaceDir } from '../../paths.js';
5
+ import { isValidAid } from '../../aun/aid/validation.js';
6
+ import { teamWorkspaceStore } from './team-workspace-store.js';
7
+ import { ownerResolver } from '../ownership/owner-resolver.js';
8
+ import { ConfigTarget, read } from '../../config/config-manager.js';
9
+ import { teamWorkspaceManagementStore, readWorkspaceMarker, workspaceMarkerPath, } from './team-workspace-management-store.js';
10
+ import { teamWorkspaceJobStore } from './team-workspace-job-store.js';
11
+ export class TeamWorkspaceBootstrapError extends Error {
12
+ code;
13
+ retryable;
14
+ constructor(code, message, retryable = true) {
15
+ super(message);
16
+ this.code = code;
17
+ this.retryable = retryable;
18
+ this.name = 'TeamWorkspaceBootstrapError';
19
+ }
20
+ }
21
+ export function resolveTeamWorkspaceIdentity(agentAid) {
22
+ if (!isValidAid(agentAid))
23
+ return null;
24
+ const config = read(ConfigTarget.Agent, { self: agentAid }, { cache: false });
25
+ if (!config)
26
+ return null;
27
+ const ownerAid = ownerResolver.owner(agentAid) ?? config.owner ?? config.owners?.[0];
28
+ if (!ownerAid || !isValidAid(ownerAid))
29
+ return null;
30
+ return { agentAid, ownerAid };
31
+ }
32
+ const initializationWait = new Int32Array(new SharedArrayBuffer(4));
33
+ export class TeamWorkspaceInitializer {
34
+ initialize(identity, rootPath = agentWorkspaceDir(identity.agentAid), options = {}) {
35
+ if (!path.isAbsolute(rootPath))
36
+ throw new TeamWorkspaceBootstrapError('INVALID_ARGUMENT', 'Team workspace path must be absolute', false);
37
+ teamWorkspaceStore.importPersonalAssistantRegistration(identity.agentAid, identity.ownerAid);
38
+ const root = path.resolve(rootPath);
39
+ const current = teamWorkspaceStore.read(identity.agentAid);
40
+ if (current && current.ownerAid !== identity.ownerAid) {
41
+ throw new TeamWorkspaceBootstrapError('WORKSPACE_IDENTITY_MISMATCH', 'Workspace registration belongs to another Owner', false);
42
+ }
43
+ fs.mkdirSync(path.dirname(root), { recursive: true });
44
+ if (fs.existsSync(root) && !fs.statSync(root).isDirectory())
45
+ throw new TeamWorkspaceBootstrapError('WORKSPACE_UNAVAILABLE', 'Team workspace is not a directory');
46
+ fs.mkdirSync(root, { recursive: true });
47
+ const marker = readWorkspaceMarker(root);
48
+ if (marker && (marker.agentAid !== identity.agentAid || marker.ownerAid !== identity.ownerAid)) {
49
+ throw new TeamWorkspaceBootstrapError('WORKSPACE_IDENTITY_MISMATCH', 'Workspace marker belongs to another Agent or Owner', false);
50
+ }
51
+ if (!marker && !options.allowExistingContent && fs.readdirSync(root).length > 0) {
52
+ throw new TeamWorkspaceBootstrapError('DIRECTORY_OCCUPIED', 'The default Team workspace directory is not empty', false);
53
+ }
54
+ const createdAt = marker?.createdAt ?? Date.now();
55
+ const outputRoot = agentOutputDir(identity.agentAid);
56
+ const fromOutput = path.relative(outputRoot, root);
57
+ if (fromOutput === '' || !fromOutput.startsWith(`..${path.sep}`) && fromOutput !== '..' && !path.isAbsolute(fromOutput)) {
58
+ throw new TeamWorkspaceBootstrapError('OUTPUT_MIGRATION_CONFLICT', 'Workspace cannot be inside the Agent output directory', false);
59
+ }
60
+ migrateWorkspaceOutput(path.join(root, 'output'), outputRoot);
61
+ fs.mkdirSync(path.join(root, 'capture'), { recursive: true });
62
+ fs.mkdirSync(path.dirname(outputRoot), { recursive: true });
63
+ fs.mkdirSync(outputRoot, { recursive: true });
64
+ ensureOutputAlias(path.join(root, 'output'), outputRoot);
65
+ fs.mkdirSync(path.join(root, '.workspace'), { recursive: true });
66
+ const markerPath = workspaceMarkerPath(root);
67
+ if (!marker)
68
+ atomicWriteJson(markerPath, { schemaVersion: 1, agentAid: identity.agentAid, ownerAid: identity.ownerAid, workspaceVersion: 1, createdAt, initializedBy: 'evolcore' });
69
+ const state = teamWorkspaceStore.bind(identity.agentAid, identity.ownerAid, root, outputRoot);
70
+ if (!readWorkspaceMarker(root)?.workspaceId)
71
+ atomicWriteJson(markerPath, { schemaVersion: 1, agentAid: identity.agentAid, ownerAid: identity.ownerAid, workspaceVersion: 1, createdAt, initializedBy: 'evolcore', workspaceId: state.workspaceId });
72
+ return { state, createdAt };
73
+ }
74
+ }
75
+ function migrateWorkspaceOutput(source, target) {
76
+ const targetStat = existingStat(target);
77
+ if (targetStat && (!targetStat.isDirectory() || targetStat.isSymbolicLink())) {
78
+ throw new TeamWorkspaceBootstrapError('OUTPUT_MIGRATION_CONFLICT', 'Agent output is not a plain directory; neither directory was changed', false);
79
+ }
80
+ if (samePath(source, target))
81
+ return;
82
+ const sourceStat = existingStat(source);
83
+ if (!sourceStat)
84
+ return;
85
+ if (sourceStat.isSymbolicLink()) {
86
+ try {
87
+ if (samePath(fs.realpathSync(source), fs.realpathSync(target)))
88
+ return;
89
+ }
90
+ catch { /* A broken or unrelated link is a migration conflict. */ }
91
+ throw new TeamWorkspaceBootstrapError('OUTPUT_MIGRATION_CONFLICT', 'Workspace output is linked to an unexpected location; neither directory was changed', false);
92
+ }
93
+ if (!sourceStat.isDirectory()) {
94
+ throw new TeamWorkspaceBootstrapError('OUTPUT_MIGRATION_CONFLICT', 'Workspace output is not a plain directory; it was not moved', false);
95
+ }
96
+ assertOutputMergeHasNoConflicts(source, target);
97
+ if (!targetStat) {
98
+ fs.mkdirSync(path.dirname(target), { recursive: true });
99
+ try {
100
+ fs.renameSync(source, target);
101
+ return;
102
+ }
103
+ catch (error) {
104
+ if (error.code !== 'EXDEV')
105
+ throw error;
106
+ }
107
+ fs.mkdirSync(target);
108
+ }
109
+ moveOutputEntries(source, target);
110
+ fs.rmdirSync(source);
111
+ }
112
+ function assertOutputMergeHasNoConflicts(source, target) {
113
+ for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
114
+ const sourcePath = path.join(source, entry.name);
115
+ const targetPath = path.join(target, entry.name);
116
+ if (!entry.isDirectory() && !entry.isFile()) {
117
+ throw new TeamWorkspaceBootstrapError('OUTPUT_MIGRATION_CONFLICT', 'Workspace output contains a non-regular entry; neither directory was changed', false);
118
+ }
119
+ const targetStat = existingStat(targetPath);
120
+ if (entry.isDirectory() && (!targetStat || targetStat.isDirectory() && !targetStat.isSymbolicLink())) {
121
+ assertOutputMergeHasNoConflicts(sourcePath, targetPath);
122
+ continue;
123
+ }
124
+ if (!targetStat)
125
+ continue;
126
+ throw new TeamWorkspaceBootstrapError('OUTPUT_MIGRATION_CONFLICT', `Workspace output conflicts with Agent output at ${entry.name}; neither directory was changed`, false);
127
+ }
128
+ }
129
+ function moveOutputEntries(source, target) {
130
+ for (const entry of fs.readdirSync(source, { withFileTypes: true })) {
131
+ const sourcePath = path.join(source, entry.name);
132
+ const targetPath = path.join(target, entry.name);
133
+ if (entry.isDirectory()) {
134
+ fs.mkdirSync(targetPath, { recursive: true });
135
+ moveOutputEntries(sourcePath, targetPath);
136
+ fs.rmdirSync(sourcePath);
137
+ }
138
+ else {
139
+ try {
140
+ fs.renameSync(sourcePath, targetPath);
141
+ }
142
+ catch (error) {
143
+ if (error.code !== 'EXDEV')
144
+ throw error;
145
+ fs.copyFileSync(sourcePath, targetPath, fs.constants.COPYFILE_EXCL);
146
+ const stat = fs.statSync(sourcePath);
147
+ fs.utimesSync(targetPath, stat.atime, stat.mtime);
148
+ fs.unlinkSync(sourcePath);
149
+ }
150
+ }
151
+ }
152
+ }
153
+ function ensureOutputAlias(alias, target) {
154
+ if (samePath(alias, target))
155
+ return;
156
+ const stat = existingStat(alias);
157
+ if (stat) {
158
+ if (stat.isSymbolicLink()) {
159
+ try {
160
+ if (samePath(fs.realpathSync(alias), fs.realpathSync(target)))
161
+ return;
162
+ }
163
+ catch { /* Broken alias is a conflict. */ }
164
+ throw new TeamWorkspaceBootstrapError('OUTPUT_MIGRATION_CONFLICT', 'Workspace output alias points to another location; it was not replaced', false);
165
+ }
166
+ throw new TeamWorkspaceBootstrapError('OUTPUT_MIGRATION_CONFLICT', 'Workspace output directory remains after migration; it was not replaced', false);
167
+ }
168
+ fs.symlinkSync(target, alias, process.platform === 'win32' ? 'junction' : 'dir');
169
+ }
170
+ function existingStat(filePath) {
171
+ try {
172
+ return fs.lstatSync(filePath);
173
+ }
174
+ catch (error) {
175
+ if (error.code === 'ENOENT')
176
+ return undefined;
177
+ throw error;
178
+ }
179
+ }
180
+ export class TeamWorkspaceBootstrapService {
181
+ initializer;
182
+ flights = new Map();
183
+ constructor(initializer = new TeamWorkspaceInitializer()) {
184
+ this.initializer = initializer;
185
+ }
186
+ migrateOutput(identity) {
187
+ teamWorkspaceStore.importPersonalAssistantRegistration(identity.agentAid, identity.ownerAid);
188
+ const binding = teamWorkspaceStore.read(identity.agentAid);
189
+ if (!binding || binding.outputRootPath || binding.ownerAid !== identity.ownerAid)
190
+ return;
191
+ withInitializationLock(identity.agentAid, () => this.initializer.initialize(identity, binding.rootPath, { allowExistingContent: true }));
192
+ }
193
+ migrateLegacyDefault(identity) {
194
+ return withInitializationLock(identity.agentAid, () => {
195
+ const state = teamWorkspaceStore.read(identity.agentAid);
196
+ if (!state || state.ownerAid !== identity.ownerAid)
197
+ return false;
198
+ const legacyRoot = path.resolve(legacyTeamWorkspaceDir(identity.agentAid));
199
+ if (!samePath(state.rootPath, legacyRoot))
200
+ return false;
201
+ const workspaceRoot = path.resolve(agentWorkspaceDir(identity.agentAid));
202
+ const legacyExists = fs.existsSync(legacyRoot);
203
+ const workspaceExists = fs.existsSync(workspaceRoot);
204
+ if (legacyExists && workspaceExists) {
205
+ throw new TeamWorkspaceBootstrapError('WORKSPACE_MIGRATION_CONFLICT', 'Both legacy and Agent workspace directories exist; neither was changed', false);
206
+ }
207
+ if (legacyExists) {
208
+ const stat = fs.lstatSync(legacyRoot);
209
+ if (!stat.isDirectory() || stat.isSymbolicLink()) {
210
+ throw new TeamWorkspaceBootstrapError('WORKSPACE_MIGRATION_CONFLICT', 'Legacy workspace is not a plain directory; it was not moved', false);
211
+ }
212
+ const markerPath = workspaceMarkerPath(legacyRoot);
213
+ const markerExists = fs.existsSync(markerPath);
214
+ const marker = markerExists ? readWorkspaceMarker(legacyRoot) : null;
215
+ if (markerExists && !marker) {
216
+ throw new TeamWorkspaceBootstrapError('WORKSPACE_IDENTITY_MISMATCH', 'Legacy workspace marker is invalid; it was not moved', false);
217
+ }
218
+ if (marker && (marker.agentAid !== identity.agentAid || marker.ownerAid !== identity.ownerAid)) {
219
+ throw new TeamWorkspaceBootstrapError('WORKSPACE_IDENTITY_MISMATCH', 'Legacy workspace marker belongs to another Agent or Owner', false);
220
+ }
221
+ if (marker?.workspaceId && marker.workspaceId !== state.workspaceId) {
222
+ throw new TeamWorkspaceBootstrapError('WORKSPACE_IDENTITY_MISMATCH', 'Legacy workspace marker does not match the stored workspace binding', false);
223
+ }
224
+ const createdAt = marker?.createdAt ?? Date.now();
225
+ fs.mkdirSync(path.dirname(markerPath), { recursive: true });
226
+ atomicWriteJson(markerPath, {
227
+ schemaVersion: 1, agentAid: identity.agentAid, ownerAid: identity.ownerAid,
228
+ workspaceVersion: 1, createdAt, initializedBy: 'evolcore', workspaceId: state.workspaceId,
229
+ });
230
+ fs.mkdirSync(path.dirname(workspaceRoot), { recursive: true });
231
+ fs.renameSync(legacyRoot, workspaceRoot);
232
+ }
233
+ else if (!workspaceExists) {
234
+ throw new TeamWorkspaceBootstrapError('WORKSPACE_UNAVAILABLE', 'Neither the legacy nor Agent workspace directory exists');
235
+ }
236
+ else {
237
+ const marker = readWorkspaceMarker(workspaceRoot);
238
+ if (!marker || marker.agentAid !== identity.agentAid || marker.ownerAid !== identity.ownerAid || marker.workspaceId !== state.workspaceId) {
239
+ throw new TeamWorkspaceBootstrapError('WORKSPACE_MIGRATION_CONFLICT', 'Agent workspace exists without a matching workspace marker; it was not adopted', false);
240
+ }
241
+ }
242
+ teamWorkspaceStore.rebindRoot(identity.agentAid, identity.ownerAid, workspaceRoot);
243
+ return true;
244
+ });
245
+ }
246
+ start(identity, operationId = `startup:${identity.agentAid}`) {
247
+ teamWorkspaceStore.importPersonalAssistantRegistration(identity.agentAid, identity.ownerAid);
248
+ this.migrateLegacyDefault(identity);
249
+ let existingBinding = teamWorkspaceStore.read(identity.agentAid);
250
+ if (existingBinding && existingBinding.ownerAid === identity.ownerAid) {
251
+ // Keep the registered columns and workspace identity while moving only
252
+ // deliverables into the same Agent-owned output used by other Agents.
253
+ existingBinding = withInitializationLock(identity.agentAid, () => this.initializer.initialize(identity, existingBinding.rootPath, { allowExistingContent: true }).state);
254
+ const legacyState = teamWorkspaceManagementStore.ensure(identity.agentAid, identity.ownerAid);
255
+ if (legacyState.status !== 'ready') {
256
+ return Promise.resolve(teamWorkspaceManagementStore.update(identity.agentAid, {
257
+ status: 'ready', createdAt: legacyState.createdAt ?? Date.now(), boundAt: legacyState.boundAt ?? Date.now(),
258
+ activeJobId: undefined, lastError: undefined,
259
+ }));
260
+ }
261
+ return Promise.resolve(legacyState);
262
+ }
263
+ const current = teamWorkspaceManagementStore.read(identity.agentAid);
264
+ if (current?.status === 'ready' && teamWorkspaceStore.read(identity.agentAid))
265
+ return Promise.resolve(current);
266
+ const active = this.flights.get(identity.agentAid);
267
+ if (active)
268
+ return active;
269
+ const state = teamWorkspaceManagementStore.ensure(identity.agentAid, identity.ownerAid);
270
+ const job = teamWorkspaceJobStore.create({ agentAid: identity.agentAid, ownerAid: identity.ownerAid, principalId: identity.ownerAid, operationId, type: 'initialize', fingerprint: JSON.stringify({ agentAid: identity.agentAid, ownerAid: identity.ownerAid }) });
271
+ teamWorkspaceManagementStore.update(identity.agentAid, { status: 'initializing', attempts: state.attempts + 1, activeJobId: job.jobId, lastError: undefined });
272
+ const flight = this.run(identity, job).finally(() => this.flights.delete(identity.agentAid));
273
+ this.flights.set(identity.agentAid, flight);
274
+ return flight;
275
+ }
276
+ async run(identity, job) {
277
+ teamWorkspaceJobStore.update(identity.agentAid, job.jobId, { status: 'running', progress: 10 });
278
+ try {
279
+ const result = withInitializationLock(identity.agentAid, () => this.initializer.initialize(identity));
280
+ const next = teamWorkspaceManagementStore.update(identity.agentAid, { status: 'ready', createdAt: result.createdAt, boundAt: Date.now(), activeJobId: undefined, lastError: undefined });
281
+ teamWorkspaceJobStore.update(identity.agentAid, job.jobId, { status: 'succeeded', progress: 100, result: { workspaceId: result.state.workspaceId } });
282
+ return next;
283
+ }
284
+ catch (error) {
285
+ const code = error instanceof TeamWorkspaceBootstrapError ? error.code : 'INITIALIZE_FAILED';
286
+ const message = error instanceof TeamWorkspaceBootstrapError
287
+ ? error.message
288
+ : initializationFailureMessage(error);
289
+ const retryable = error instanceof TeamWorkspaceBootstrapError ? error.retryable : true;
290
+ const next = teamWorkspaceManagementStore.update(identity.agentAid, { status: 'failed', activeJobId: undefined, lastError: { code, message, retryable } });
291
+ teamWorkspaceJobStore.update(identity.agentAid, job.jobId, { status: 'failed', progress: 100, error: { code, message } });
292
+ return next;
293
+ }
294
+ }
295
+ flight(agentAid) { return this.flights.get(agentAid); }
296
+ }
297
+ function withInitializationLock(agentAid, action) {
298
+ const directory = agentDataDir(agentAid);
299
+ fs.mkdirSync(directory, { recursive: true });
300
+ const lockPath = path.join(directory, 'team-workspace-initialize.lock');
301
+ let fd;
302
+ const deadline = Date.now() + 10_000;
303
+ while (fd === undefined) {
304
+ try {
305
+ fd = fs.openSync(lockPath, 'wx', 0o600);
306
+ }
307
+ catch (error) {
308
+ if (error.code !== 'EEXIST')
309
+ throw error;
310
+ try {
311
+ if (Date.now() - fs.statSync(lockPath).mtimeMs > 120_000)
312
+ fs.rmSync(lockPath, { force: true });
313
+ }
314
+ catch { }
315
+ if (Date.now() >= deadline)
316
+ throw new TeamWorkspaceBootstrapError('CONFLICT', 'Team workspace initialization is busy');
317
+ Atomics.wait(initializationWait, 0, 0, 20);
318
+ }
319
+ }
320
+ try {
321
+ return action();
322
+ }
323
+ finally {
324
+ try {
325
+ fs.closeSync(fd);
326
+ }
327
+ catch { }
328
+ try {
329
+ fs.rmSync(lockPath, { force: true });
330
+ }
331
+ catch { }
332
+ }
333
+ }
334
+ function samePath(left, right) {
335
+ const normalize = (value) => {
336
+ const resolved = path.resolve(value);
337
+ return process.platform === 'win32' ? resolved.toLowerCase() : resolved;
338
+ };
339
+ return normalize(left) === normalize(right);
340
+ }
341
+ function initializationFailureMessage(error) {
342
+ const code = error && typeof error === 'object' && typeof error.code === 'string'
343
+ ? error.code
344
+ : '';
345
+ if (code === 'ENOSPC')
346
+ return 'Insufficient disk space for the Team workspace';
347
+ if (code === 'EACCES' || code === 'EPERM')
348
+ return 'Permission denied while creating the Team workspace';
349
+ return 'Team workspace initialization failed';
350
+ }
@@ -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';