@myagentroam/node 0.11.1 → 0.11.3
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.
- package/dist/connector.js +1 -1
- package/dist/database.js +53 -31
- package/dist/migrations/v021.js +64 -0
- package/dist/native-session-history.js +31 -1
- package/dist/runner/claude/conversation-parser.js +42 -0
- package/dist/runner/claude/managed-run-controller.js +78 -60
- package/dist/runner/claude/tool-normalizer.js +10 -0
- package/dist/runner/codex/conversation-parser.js +18 -3
- package/dist/runner/codex/managed-run-controller.js +25 -10
- package/dist/runner/mar-agent/conversation-normalizer.js +23 -9
- package/dist/runner/mar-agent/history-projection.js +3 -3
- package/dist/runner/mar-agent/managed-run-controller.js +1 -0
- package/dist/runner/opencode/conversation-parser.js +16 -3
- package/dist/runner/opencode/managed-run-controller.js +9 -4
- package/dist/runner/opencode/tool-normalizer.js +10 -0
- package/dist/runtime-state.js +47 -4
- package/dist/service/conversation-history-service.js +2 -1
- package/dist/service/conversation-segment-service.js +3 -1
- package/dist/service/conversation-work-process.js +102 -0
- package/dist/service/node-workspace-coordinator.js +21 -3
- package/dist/service/run-event-service.js +9 -2
- package/dist/service/skill-directory-service.js +2 -2
- package/dist/service/skill-install-service.js +15 -7
- package/dist/service/skill-node-operation-service.js +5 -4
- package/dist/service/workbench-event-projection.js +2 -0
- package/dist/service/workbench-manifest-service.js +1 -1
- package/dist/service/workspace-change-service.js +29 -13
- package/dist/service/workspace-file-service.js +3 -1
- package/dist/service/workspace-git-exclude-service.js +59 -32
- package/dist/service/workspace-service.js +34 -9
- package/dist/service/workspace-watch-snapshot-service.js +35 -5
- package/dist/service/workspace-workbench-service.js +23 -11
- package/dist/util/node-operation-parsers.js +0 -10
- package/dist/util/runner-native-session-parsers.js +15 -6
- package/dist/workspace.js +27 -3
- package/package.json +4 -4
|
@@ -159,8 +159,15 @@ export class RunEventService {
|
|
|
159
159
|
const createdTurn = targetsCurrentTurn && targetTurn === undefined && currentTurn === undefined
|
|
160
160
|
? this.options.runtime.conversationTurnForRun(runId)
|
|
161
161
|
: undefined;
|
|
162
|
+
const projectedTurn = this.options.runtime.conversationTurnForExecution(executionId) ??
|
|
163
|
+
this.options.runtime.conversationTurnForRun(runId);
|
|
164
|
+
const previousGroups = new Map(targetTurn?.items.map((item) => [item.id, item.processGroup]));
|
|
165
|
+
const correctedGroups = projectedTurn !== undefined &&
|
|
166
|
+
projectedTurn.items.some((item) => previousGroups.has(item.id) &&
|
|
167
|
+
(previousGroups.get(item.id)?.id !== item.processGroup?.id ||
|
|
168
|
+
previousGroups.get(item.id)?.isStart !== item.processGroup?.isStart));
|
|
162
169
|
if (targetsCurrentTurn)
|
|
163
|
-
this.options.emitWorkbench('conversation', createdTurn === undefined
|
|
170
|
+
this.options.emitWorkbench('conversation', createdTurn === undefined && !correctedGroups
|
|
164
171
|
? {
|
|
165
172
|
event: {
|
|
166
173
|
...event,
|
|
@@ -168,7 +175,7 @@ export class RunEventService {
|
|
|
168
175
|
createdAt: recorded?.createdAt ?? Date.now()
|
|
169
176
|
}
|
|
170
177
|
}
|
|
171
|
-
: { turn: createdTurn });
|
|
178
|
+
: { turn: createdTurn ?? projectedTurn });
|
|
172
179
|
else {
|
|
173
180
|
const projectedTurn = this.options.runtime.conversationTurnForExecution(executionId);
|
|
174
181
|
if (projectedTurn !== undefined)
|
|
@@ -22,11 +22,11 @@ export class SkillDirectoryService {
|
|
|
22
22
|
: agents.map(withoutSource)
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
async inspectWorkspace(workspace) {
|
|
25
|
+
async inspectWorkspace(workspace, includeParentRepository = true) {
|
|
26
26
|
const agents = await scanRoot(path.join(workspace, '.agents', 'skills'), 'AGENTS');
|
|
27
27
|
const claude = await scanRoot(path.join(workspace, '.claude', 'skills'), 'CLAUDE');
|
|
28
28
|
const skills = mergeWorkspaceCopies(agents, claude);
|
|
29
|
-
const gitExcludeBroken = await hasBrokenWorkspaceSkillGitExclude(workspace, skills.map((skill) => skill.name));
|
|
29
|
+
const gitExcludeBroken = await hasBrokenWorkspaceSkillGitExclude(workspace, skills.map((skill) => skill.name), includeParentRepository);
|
|
30
30
|
return {
|
|
31
31
|
targetKind: 'WORKSPACE',
|
|
32
32
|
compatibilityMode: 'MANAGED_COPY',
|
|
@@ -4,6 +4,7 @@ import { promisify } from 'node:util';
|
|
|
4
4
|
import { lstat, mkdir, readFile, readdir, readlink, realpath, rename, rm, symlink, writeFile } from 'node:fs/promises';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { skillInstallMetadataSchema } from '@myagentroam/protocol';
|
|
7
|
+
import { GitCommandError, resolveWorkspaceGitRoot } from '../workspace.js';
|
|
7
8
|
import { rewriteWorkspaceGitExclude, updateWorkspaceSkillGitExclude } from './workspace-git-exclude-service.js';
|
|
8
9
|
export class SkillInstallService {
|
|
9
10
|
async recoverNodeHome(home) {
|
|
@@ -59,15 +60,15 @@ export class SkillInstallService {
|
|
|
59
60
|
await mkdir(claudeRoot, { recursive: true });
|
|
60
61
|
await assertContainedDirectory(workspace, agentsRoot);
|
|
61
62
|
await assertContainedDirectory(workspace, claudeRoot);
|
|
62
|
-
await replacePair(agentsRoot, claudeRoot, name, bundle, metadata, () => updateWorkspaceSkillGitExclude(workspace, name, true), () => updateWorkspaceSkillGitExclude(workspace, name, false));
|
|
63
|
+
await replacePair(agentsRoot, claudeRoot, name, bundle, metadata, () => updateWorkspaceSkillGitExclude(workspace, name, true, options.includeParentRepository ?? true), () => updateWorkspaceSkillGitExclude(workspace, name, false, options.includeParentRepository ?? true));
|
|
63
64
|
}
|
|
64
|
-
async removeWorkspace(workspace, name) {
|
|
65
|
+
async removeWorkspace(workspace, name, includeParentRepository = true) {
|
|
65
66
|
assertName(name);
|
|
66
67
|
const agentsRoot = path.join(workspace, '.agents', 'skills');
|
|
67
68
|
const claudeRoot = path.join(workspace, '.claude', 'skills');
|
|
68
69
|
await assertExistingContainedDirectory(workspace, agentsRoot);
|
|
69
70
|
await assertExistingContainedDirectory(workspace, claudeRoot);
|
|
70
|
-
await removePair(agentsRoot, claudeRoot, name, () => updateWorkspaceSkillGitExclude(workspace, name, false), () => updateWorkspaceSkillGitExclude(workspace, name, true));
|
|
71
|
+
await removePair(agentsRoot, claudeRoot, name, () => updateWorkspaceSkillGitExclude(workspace, name, false, includeParentRepository), () => updateWorkspaceSkillGitExclude(workspace, name, true, includeParentRepository));
|
|
71
72
|
}
|
|
72
73
|
async removeNodeHome(home, name) {
|
|
73
74
|
assertName(name);
|
|
@@ -81,7 +82,7 @@ export class SkillInstallService {
|
|
|
81
82
|
else
|
|
82
83
|
await removeSingle(agentsRoot, name);
|
|
83
84
|
}
|
|
84
|
-
async repairWorkspaceGitExclude(workspace) {
|
|
85
|
+
async repairWorkspaceGitExclude(workspace, includeParentRepository = true) {
|
|
85
86
|
const root = path.join(workspace, '.agents', 'skills');
|
|
86
87
|
const names = new Set();
|
|
87
88
|
try {
|
|
@@ -101,13 +102,20 @@ export class SkillInstallService {
|
|
|
101
102
|
if (!isMissing(error))
|
|
102
103
|
throw error;
|
|
103
104
|
}
|
|
104
|
-
await rewriteWorkspaceGitExclude(workspace, names);
|
|
105
|
+
await rewriteWorkspaceGitExclude(workspace, names, includeParentRepository);
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
export async function workspaceSkillTracked(workspace, name) {
|
|
108
109
|
assertName(name);
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
try {
|
|
111
|
+
await resolveWorkspaceGitRoot(workspace);
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
if ((error instanceof GitCommandError && error.code === 128) ||
|
|
115
|
+
error.code === 'ENOENT')
|
|
116
|
+
return false;
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
111
119
|
try {
|
|
112
120
|
const result = await promisify(execFile)('git', ['-C', workspace, 'ls-files', '--', `.agents/skills/${name}`, `.claude/skills/${name}`], { timeout: 5_000, windowsHide: true });
|
|
113
121
|
return result.stdout.trim() !== '';
|
|
@@ -28,14 +28,14 @@ export class SkillNodeOperationService {
|
|
|
28
28
|
'workspace.skills.inspect': async (data) => {
|
|
29
29
|
const workspace = this.workspacePath(record(data)['workspaceId']);
|
|
30
30
|
await this.installer.recoverWorkspace(workspace);
|
|
31
|
-
return this.directories.inspectWorkspace(workspace);
|
|
31
|
+
return this.directories.inspectWorkspace(workspace, this.database().getWorkspaceByPath(workspace)?.includeParentRepository ?? true);
|
|
32
32
|
},
|
|
33
33
|
'workspace.skills.install': (data) => this.install('WORKSPACE', data),
|
|
34
34
|
'workspace.skills.remove': (data) => this.remove('WORKSPACE', data),
|
|
35
35
|
'workspace.skills.git-exclude-repair': async (data) => {
|
|
36
36
|
const workspace = this.workspacePath(record(data)['workspaceId']);
|
|
37
37
|
await this.installer.recoverWorkspace(workspace);
|
|
38
|
-
await this.installer.repairWorkspaceGitExclude(workspace);
|
|
38
|
+
await this.installer.repairWorkspaceGitExclude(workspace, this.database().getWorkspaceByPath(workspace)?.includeParentRepository ?? true);
|
|
39
39
|
return { repaired: true };
|
|
40
40
|
},
|
|
41
41
|
'skill.install.job.get': (data) => this.job(data)
|
|
@@ -113,7 +113,8 @@ export class SkillNodeOperationService {
|
|
|
113
113
|
await this.installer.installNodeHome(homedir(), input.name, bundle, input.metadata);
|
|
114
114
|
else
|
|
115
115
|
await this.installer.installWorkspace(input.workspace, input.name, bundle, input.metadata, {
|
|
116
|
-
confirmTracked: true
|
|
116
|
+
confirmTracked: true,
|
|
117
|
+
includeParentRepository: this.database().getWorkspaceByPath(input.workspace)?.includeParentRepository ?? true
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
120
|
async remove(target, data) {
|
|
@@ -131,7 +132,7 @@ export class SkillNodeOperationService {
|
|
|
131
132
|
}
|
|
132
133
|
else {
|
|
133
134
|
await this.installer.recoverWorkspace(workspace);
|
|
134
|
-
await this.installer.removeWorkspace(workspace, name);
|
|
135
|
+
await this.installer.removeWorkspace(workspace, name, this.database().getWorkspaceByPath(workspace)?.includeParentRepository ?? true);
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
finally {
|
|
@@ -90,6 +90,8 @@ export function projectWorkbenchPayload(queries, category, payload) {
|
|
|
90
90
|
payload: item.payload,
|
|
91
91
|
startedAt: item.startedAt,
|
|
92
92
|
completedAt: item.completedAt,
|
|
93
|
+
parentItemId: item.parentItemId,
|
|
94
|
+
...(item.processGroup === undefined ? {} : { processGroup: item.processGroup }),
|
|
93
95
|
segmentId: segment.id,
|
|
94
96
|
segmentIndex: segment.index
|
|
95
97
|
}
|
|
@@ -2,7 +2,7 @@ import { lstat } from 'node:fs/promises';
|
|
|
2
2
|
import { basename, posix, resolve } from 'node:path';
|
|
3
3
|
import { publicErrorMessage } from '@myagentroam/protocol';
|
|
4
4
|
import { nodeLog } from '../operational.js';
|
|
5
|
-
import { GitCommandError, isWorkspaceChangeVisible, listGitWorktrees, listGitSubmodules, readCurrentChangesSummary, resolveGitRepository } from '../workspace.js';
|
|
5
|
+
import { GitCommandError, isWorkspaceChangeVisible, listGitWorktrees, listGitSubmodules, readCurrentChangesSummary, resolveGitRepository, resolveWorkspaceGitRoot } from '../workspace.js';
|
|
6
6
|
const CACHE_TTL_MS = 5_000;
|
|
7
7
|
const REPOSITORY_READ_CONCURRENCY = 4;
|
|
8
8
|
const WORKTREE_READ_CONCURRENCY = 4;
|
|
@@ -13,6 +13,9 @@ export class WorkspaceChangeService {
|
|
|
13
13
|
constructor(state) {
|
|
14
14
|
this.state = state;
|
|
15
15
|
}
|
|
16
|
+
revision(workspaceId) {
|
|
17
|
+
return this.state.changesVersions.get(workspaceId) ?? 0;
|
|
18
|
+
}
|
|
16
19
|
invalidate(workspaceId) {
|
|
17
20
|
this.state.changesReads.delete(workspaceId);
|
|
18
21
|
this.state.changesCache.delete(workspaceId);
|
|
@@ -34,7 +37,9 @@ export class WorkspaceChangeService {
|
|
|
34
37
|
return existing;
|
|
35
38
|
// Invalidation may arrive during this shared read; its old result must not repopulate the cache.
|
|
36
39
|
const version = this.state.changesVersions.get(workspace.id) ?? 0;
|
|
37
|
-
const request = this.state.changesLimiter
|
|
40
|
+
const request = this.state.changesLimiter
|
|
41
|
+
.run(async () => {
|
|
42
|
+
const repositoryRoot = await resolveWorkspaceGitRoot(workspace.path, workspace.includeParentRepository ?? true);
|
|
38
43
|
const startedAt = performance.now();
|
|
39
44
|
const errors = [];
|
|
40
45
|
const failure = (code, error) => ({
|
|
@@ -66,7 +71,7 @@ export class WorkspaceChangeService {
|
|
|
66
71
|
};
|
|
67
72
|
const readRepository = async (repositoryPath, repositoryOverride) => {
|
|
68
73
|
const repository = repositoryOverride ??
|
|
69
|
-
(await resolveGitRepository(
|
|
74
|
+
(await resolveGitRepository(repositoryRoot, repositoryPath, [repositoryPath]));
|
|
70
75
|
if (repositoryPath !== '' || repositoryOverride !== undefined) {
|
|
71
76
|
const marker = await lstat(resolve(repository, '.git'));
|
|
72
77
|
if (marker.isSymbolicLink() || (!marker.isFile() && !marker.isDirectory()))
|
|
@@ -89,19 +94,14 @@ export class WorkspaceChangeService {
|
|
|
89
94
|
changes
|
|
90
95
|
};
|
|
91
96
|
};
|
|
92
|
-
const root = await readRepository('')
|
|
93
|
-
if (error?.code === 'ENOENT' &&
|
|
94
|
-
error.syscall?.startsWith('spawn') === true)
|
|
95
|
-
throw new Error('GIT_NOT_FOUND');
|
|
96
|
-
throw error;
|
|
97
|
-
});
|
|
97
|
+
const root = await readRepository('');
|
|
98
98
|
const children = [];
|
|
99
99
|
let parents = [''];
|
|
100
100
|
let submodulesLimited = false;
|
|
101
101
|
while (parents.length > 0 && !submodulesLimited) {
|
|
102
102
|
const discovered = await mapWithConcurrency(parents, REPOSITORY_READ_CONCURRENCY, async (parent) => {
|
|
103
103
|
try {
|
|
104
|
-
const path = await resolveGitRepository(
|
|
104
|
+
const path = await resolveGitRepository(repositoryRoot, parent, [parent]);
|
|
105
105
|
return (await listGitSubmodules(path)).map((entry) => ({
|
|
106
106
|
...entry,
|
|
107
107
|
path: parent === '' ? entry.path : `${parent}/${entry.path}`
|
|
@@ -152,7 +152,7 @@ export class WorkspaceChangeService {
|
|
|
152
152
|
.map((entry) => entry.repositoryPath);
|
|
153
153
|
}
|
|
154
154
|
children.sort((left, right) => left.repositoryPath.localeCompare(right.repositoryPath));
|
|
155
|
-
const worktreeList = await listGitWorktrees(
|
|
155
|
+
const worktreeList = await listGitWorktrees(repositoryRoot).catch((error) => {
|
|
156
156
|
discoveryFailure('WORKTREE', '', 'GIT_WORKTREE_DISCOVERY_FAILED', error);
|
|
157
157
|
return { entries: [], truncated: false };
|
|
158
158
|
});
|
|
@@ -229,6 +229,13 @@ export class WorkspaceChangeService {
|
|
|
229
229
|
diffAvailable: true
|
|
230
230
|
});
|
|
231
231
|
const value = {
|
|
232
|
+
repositoryRoot,
|
|
233
|
+
workspace: {
|
|
234
|
+
id: workspace.id,
|
|
235
|
+
path: workspace.path,
|
|
236
|
+
kind: 'GIT_WORKSPACE',
|
|
237
|
+
gitSummary: { branch: root.branch, repositoryRoot }
|
|
238
|
+
},
|
|
232
239
|
partial: errors.length > 0 ||
|
|
233
240
|
children.some((group) => group.status === 'UNAVAILABLE') ||
|
|
234
241
|
linkedRepositories.some((group) => group.status === 'UNAVAILABLE') ||
|
|
@@ -240,7 +247,7 @@ export class WorkspaceChangeService {
|
|
|
240
247
|
{
|
|
241
248
|
...root,
|
|
242
249
|
source: 'ROOT',
|
|
243
|
-
physicalPath: currentWorktree?.path ??
|
|
250
|
+
physicalPath: currentWorktree?.path ?? repositoryRoot,
|
|
244
251
|
current: true,
|
|
245
252
|
...(currentWorktree === undefined ? {} : { head: currentWorktree.head }),
|
|
246
253
|
status: root.dirty ? 'DIRTY' : 'CLEAN',
|
|
@@ -267,8 +274,17 @@ export class WorkspaceChangeService {
|
|
|
267
274
|
durationMs: Math.round(performance.now() - startedAt)
|
|
268
275
|
});
|
|
269
276
|
if ((this.state.changesVersions.get(workspace.id) ?? 0) === version)
|
|
270
|
-
this.state.changesCache.set(workspace.id, {
|
|
277
|
+
this.state.changesCache.set(workspace.id, {
|
|
278
|
+
value,
|
|
279
|
+
expiresAt: Date.now() + CACHE_TTL_MS
|
|
280
|
+
});
|
|
271
281
|
return value;
|
|
282
|
+
})
|
|
283
|
+
.catch((error) => {
|
|
284
|
+
if (error?.code === 'ENOENT' &&
|
|
285
|
+
error.syscall?.startsWith('spawn') === true)
|
|
286
|
+
throw new Error('GIT_NOT_FOUND');
|
|
287
|
+
throw error;
|
|
272
288
|
});
|
|
273
289
|
this.state.changesReads.set(workspace.id, request);
|
|
274
290
|
try {
|
|
@@ -176,7 +176,9 @@ export class WorkspaceFileService {
|
|
|
176
176
|
return { size: metadata.size, revision: metadata.sourceRevision };
|
|
177
177
|
}
|
|
178
178
|
async write(workspace, input) {
|
|
179
|
-
if (
|
|
179
|
+
if (input.repositoryPath !== undefined ||
|
|
180
|
+
input.worktreePath !== undefined ||
|
|
181
|
+
typeof input.path !== 'string' ||
|
|
180
182
|
typeof input.content !== 'string' ||
|
|
181
183
|
typeof input.expectedRevision !== 'string')
|
|
182
184
|
throw new Error('FILE_WRITE_INVALID');
|
|
@@ -1,53 +1,91 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { execFile } from 'node:child_process';
|
|
3
|
-
import { lstat, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { lstat, mkdir, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { promisify } from 'node:util';
|
|
6
|
+
import { GitCommandError, resolveWorkspaceGitRoot } from '../workspace.js';
|
|
6
7
|
const MAR_TEMP_DIRECTORY = '/.mar/';
|
|
7
8
|
const BLOCK_BEGIN = '# BEGIN MyAgentRoam';
|
|
8
9
|
const BLOCK_END = '# END MyAgentRoam';
|
|
9
10
|
const LEGACY_BLOCK_BEGIN = '# BEGIN MyAgentRoam Skills';
|
|
10
11
|
const LEGACY_BLOCK_END = '# END MyAgentRoam Skills';
|
|
11
|
-
export async function ensureWorkspaceGitExclude(workspace) {
|
|
12
|
-
await mutateGitExclude(workspace, () => undefined);
|
|
12
|
+
export async function ensureWorkspaceGitExclude(workspace, includeParentRepository = true) {
|
|
13
|
+
await mutateGitExclude(workspace, () => undefined, includeParentRepository);
|
|
13
14
|
}
|
|
14
|
-
export async function updateWorkspaceSkillGitExclude(workspace, name, add) {
|
|
15
|
-
await mutateGitExclude(workspace, (entries) => {
|
|
15
|
+
export async function updateWorkspaceSkillGitExclude(workspace, name, add, includeParentRepository = true) {
|
|
16
|
+
await mutateGitExclude(workspace, (entries, prefix) => {
|
|
16
17
|
for (const root of ['.agents', '.claude']) {
|
|
17
|
-
const line =
|
|
18
|
+
const line = `${prefix}${root}/skills/${name}/`;
|
|
18
19
|
if (add)
|
|
19
20
|
entries.add(line);
|
|
20
21
|
else
|
|
21
22
|
entries.delete(line);
|
|
22
23
|
}
|
|
23
|
-
});
|
|
24
|
+
}, includeParentRepository);
|
|
24
25
|
}
|
|
25
|
-
export async function rewriteWorkspaceGitExclude(workspace, names) {
|
|
26
|
-
await mutateGitExclude(workspace, (entries) => {
|
|
27
|
-
entries
|
|
26
|
+
export async function rewriteWorkspaceGitExclude(workspace, names, includeParentRepository = true) {
|
|
27
|
+
await mutateGitExclude(workspace, (entries, prefix) => {
|
|
28
|
+
for (const entry of entries)
|
|
29
|
+
if (['.agents', '.claude'].some((root) => entry.startsWith(`${prefix}${root}/skills/`)))
|
|
30
|
+
entries.delete(entry);
|
|
28
31
|
for (const name of names)
|
|
29
32
|
for (const root of ['.agents', '.claude'])
|
|
30
|
-
entries.add(
|
|
31
|
-
});
|
|
33
|
+
entries.add(`${prefix}${root}/skills/${name}/`);
|
|
34
|
+
}, includeParentRepository);
|
|
32
35
|
}
|
|
33
|
-
export async function hasBrokenWorkspaceSkillGitExclude(workspace, names) {
|
|
34
|
-
if (!(await exists(path.join(workspace, '.git'))))
|
|
35
|
-
return false;
|
|
36
|
+
export async function hasBrokenWorkspaceSkillGitExclude(workspace, names, includeParentRepository = true) {
|
|
36
37
|
try {
|
|
37
|
-
const
|
|
38
|
+
const target = await gitExcludeTarget(workspace, includeParentRepository);
|
|
39
|
+
if (target === undefined)
|
|
40
|
+
return false;
|
|
41
|
+
const { exclude, prefix } = target;
|
|
38
42
|
const content = await readFile(exclude, 'utf8');
|
|
39
43
|
return names
|
|
40
|
-
.flatMap((name) => [
|
|
44
|
+
.flatMap((name) => [`${prefix}.agents/skills/${name}/`, `${prefix}.claude/skills/${name}/`])
|
|
41
45
|
.some((entry) => !content.includes(entry));
|
|
42
46
|
}
|
|
43
47
|
catch {
|
|
44
48
|
return true;
|
|
45
49
|
}
|
|
46
50
|
}
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
const mutationTails = new Map();
|
|
52
|
+
async function gitExcludeTarget(workspace, includeParentRepository) {
|
|
53
|
+
let root;
|
|
54
|
+
try {
|
|
55
|
+
root = await resolveWorkspaceGitRoot(workspace, includeParentRepository);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
if ((error instanceof GitCommandError && error.code === 128) ||
|
|
59
|
+
(error instanceof Error && error.message === 'WORKSPACE_NOT_GIT') ||
|
|
60
|
+
error.code === 'ENOENT')
|
|
61
|
+
return undefined;
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
const relative = path
|
|
65
|
+
.relative(root, await realpath(workspace))
|
|
66
|
+
.split(path.sep)
|
|
67
|
+
.join('/');
|
|
68
|
+
const escaped = relative.replace(/[\\*?\[\]#! ]/g, '\\$&');
|
|
69
|
+
return { exclude: await resolveGitExclude(root), prefix: relative === '' ? '/' : `/${escaped}/` };
|
|
70
|
+
}
|
|
71
|
+
async function mutateGitExclude(workspace, mutate, includeParentRepository) {
|
|
72
|
+
const target = await gitExcludeTarget(workspace, includeParentRepository);
|
|
73
|
+
if (target === undefined)
|
|
49
74
|
return;
|
|
50
|
-
const exclude =
|
|
75
|
+
const { exclude, prefix } = target;
|
|
76
|
+
const request = (mutationTails.get(exclude) ?? Promise.resolve())
|
|
77
|
+
.catch(() => undefined)
|
|
78
|
+
.then(() => writeGitExclude(exclude, (entries) => mutate(entries, prefix)));
|
|
79
|
+
mutationTails.set(exclude, request);
|
|
80
|
+
try {
|
|
81
|
+
await request;
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
if (mutationTails.get(exclude) === request)
|
|
85
|
+
mutationTails.delete(exclude);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async function writeGitExclude(exclude, mutate) {
|
|
51
89
|
await mkdir(path.dirname(exclude), { recursive: true });
|
|
52
90
|
let content = '';
|
|
53
91
|
try {
|
|
@@ -62,7 +100,7 @@ async function mutateGitExclude(workspace, mutate) {
|
|
|
62
100
|
}
|
|
63
101
|
const pattern = managedBlockPattern();
|
|
64
102
|
const existing = [...content.matchAll(pattern)].map((match) => match[0]).join('\n');
|
|
65
|
-
const entries = new Set(existing.split(/\r?\n/u).filter((line) => line.startsWith('
|
|
103
|
+
const entries = new Set(existing.split(/\r?\n/u).filter((line) => line.startsWith('/')));
|
|
66
104
|
entries.delete(MAR_TEMP_DIRECTORY);
|
|
67
105
|
mutate(entries);
|
|
68
106
|
const block = entries.size === 0 ? '' : `${BLOCK_BEGIN}\n${[...entries].sort().join('\n')}\n${BLOCK_END}\n`;
|
|
@@ -97,17 +135,6 @@ async function resolveGitExclude(workspace) {
|
|
|
97
135
|
throw new Error('WORKSPACE_SKILL_GIT_EXCLUDE_FAILED');
|
|
98
136
|
}
|
|
99
137
|
}
|
|
100
|
-
async function exists(value) {
|
|
101
|
-
try {
|
|
102
|
-
await lstat(value);
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
if (isMissing(error))
|
|
107
|
-
return false;
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
138
|
function isMissing(error) {
|
|
112
139
|
return (error instanceof Error && 'code' in error && error.code === 'ENOENT');
|
|
113
140
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rmdir } from 'node:fs/promises';
|
|
1
|
+
import { realpath, rmdir } from 'node:fs/promises';
|
|
2
2
|
import { createWorkspaceDirectory, inspectWorkspace, listWorkspaceDirectories } from '../workspace.js';
|
|
3
3
|
import { ensureWorkspaceGitExclude } from './workspace-git-exclude-service.js';
|
|
4
4
|
import { workspaceGitSettingsSchema } from '@myagentroam/protocol';
|
|
@@ -7,11 +7,13 @@ export class WorkspaceService {
|
|
|
7
7
|
config;
|
|
8
8
|
runtime;
|
|
9
9
|
onRemoved;
|
|
10
|
-
|
|
10
|
+
onGitPolicyChanged;
|
|
11
|
+
constructor(database, config, runtime, onRemoved, onGitPolicyChanged = () => undefined) {
|
|
11
12
|
this.database = database;
|
|
12
13
|
this.config = config;
|
|
13
14
|
this.runtime = runtime;
|
|
14
15
|
this.onRemoved = onRemoved;
|
|
16
|
+
this.onGitPolicyChanged = onGitPolicyChanged;
|
|
15
17
|
}
|
|
16
18
|
operations() {
|
|
17
19
|
return {
|
|
@@ -36,14 +38,28 @@ export class WorkspaceService {
|
|
|
36
38
|
const path = typeof input.createDirectoryName === 'string'
|
|
37
39
|
? (createdPath = await createWorkspaceDirectory(input.path, input.createDirectoryName, this.config().allowedRoots))
|
|
38
40
|
: input.path;
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
+
const canonicalPath = await realpath(path);
|
|
42
|
+
const current = this.database().getWorkspaceByPath(canonicalPath);
|
|
43
|
+
const includeParentRepository = current?.includeParentRepository ?? true;
|
|
44
|
+
const inspected = await inspectWorkspace(canonicalPath, this.config().allowedRoots, includeParentRepository);
|
|
45
|
+
let latest = this.database().getWorkspaceByPath(canonicalPath);
|
|
46
|
+
if (latest !== undefined &&
|
|
47
|
+
(latest.includeParentRepository ?? true) !== includeParentRepository)
|
|
48
|
+
return { workspace: latest };
|
|
49
|
+
if (inspected.kind === 'GIT_WORKSPACE') {
|
|
50
|
+
await ensureWorkspaceGitExclude(inspected.path, includeParentRepository);
|
|
51
|
+
latest = this.database().getWorkspaceByPath(canonicalPath);
|
|
52
|
+
if (latest !== undefined &&
|
|
53
|
+
(latest.includeParentRepository ?? true) !== includeParentRepository)
|
|
54
|
+
return { workspace: latest };
|
|
55
|
+
}
|
|
41
56
|
return {
|
|
42
57
|
workspace: this.database().saveWorkspace({
|
|
43
58
|
path: inspected.path,
|
|
44
59
|
kind: inspected.kind,
|
|
45
60
|
gitSummary: inspected.gitSummary ?? null,
|
|
46
|
-
preserveGitConfig: input.preserveGitConfig === true
|
|
61
|
+
preserveGitConfig: input.preserveGitConfig === true,
|
|
62
|
+
includeParentRepository
|
|
47
63
|
})
|
|
48
64
|
};
|
|
49
65
|
}
|
|
@@ -80,13 +96,22 @@ export class WorkspaceService {
|
|
|
80
96
|
if (current === undefined)
|
|
81
97
|
throw new Error('WORKSPACE_NOT_FOUND');
|
|
82
98
|
if (!update)
|
|
83
|
-
return {
|
|
99
|
+
return {
|
|
100
|
+
preserveGitConfig: current.preserveGitConfig ?? true,
|
|
101
|
+
includeParentRepository: current.includeParentRepository ?? true
|
|
102
|
+
};
|
|
84
103
|
const parsed = workspaceGitSettingsSchema.safeParse({
|
|
85
|
-
preserveGitConfig: input.preserveGitConfig
|
|
104
|
+
preserveGitConfig: input.preserveGitConfig,
|
|
105
|
+
includeParentRepository: input.includeParentRepository
|
|
86
106
|
});
|
|
87
107
|
if (!parsed.success)
|
|
88
108
|
throw new Error('GIT_CONFIGURATION_INVALID');
|
|
89
|
-
const result = this.database().setWorkspaceGitPolicy(input.workspaceId, parsed.data.preserveGitConfig);
|
|
90
|
-
|
|
109
|
+
const result = this.database().setWorkspaceGitPolicy(input.workspaceId, parsed.data.preserveGitConfig, parsed.data.includeParentRepository);
|
|
110
|
+
if (result.includeParentRepository !== current.includeParentRepository)
|
|
111
|
+
this.onGitPolicyChanged(current.id);
|
|
112
|
+
return {
|
|
113
|
+
preserveGitConfig: result.preserveGitConfig,
|
|
114
|
+
includeParentRepository: result.includeParentRepository
|
|
115
|
+
};
|
|
91
116
|
}
|
|
92
117
|
}
|
|
@@ -15,15 +15,23 @@ export class WorkspaceWatchSnapshotService {
|
|
|
15
15
|
if (watch.topics.files !== undefined)
|
|
16
16
|
this.ensureFilesRefreshTimer();
|
|
17
17
|
await Promise.all(this.subscribedTopics(watch).map(async (topic) => {
|
|
18
|
+
const revision = this.readRevision(workspace.id, topic);
|
|
18
19
|
try {
|
|
19
20
|
const payload = await this.read(workspace, topic, watch);
|
|
20
21
|
if (!this.matches(workspace.id, watch))
|
|
21
22
|
return;
|
|
23
|
+
if (revision !== this.readRevision(workspace.id, topic)) {
|
|
24
|
+
void this.invalidate(workspace.id, topic);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
22
27
|
this.signatures.set(this.viewKey(workspace.id, topic, watch), signature(payload));
|
|
23
28
|
this.deliver(workspace, watch, topic, payload);
|
|
24
29
|
}
|
|
25
30
|
catch {
|
|
26
|
-
this.
|
|
31
|
+
if (revision === this.readRevision(workspace.id, topic))
|
|
32
|
+
this.fail(workspace.id, watch, topic);
|
|
33
|
+
else
|
|
34
|
+
void this.invalidate(workspace.id, topic);
|
|
27
35
|
}
|
|
28
36
|
}));
|
|
29
37
|
}
|
|
@@ -119,7 +127,22 @@ export class WorkspaceWatchSnapshotService {
|
|
|
119
127
|
const first = subscribers[0];
|
|
120
128
|
if (first === undefined)
|
|
121
129
|
return;
|
|
122
|
-
const
|
|
130
|
+
const revision = this.readRevision(workspaceId, topic);
|
|
131
|
+
let payload;
|
|
132
|
+
try {
|
|
133
|
+
payload = await this.read(workspace, topic, first);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
if (revision !== this.readRevision(workspaceId, topic)) {
|
|
137
|
+
void this.invalidate(workspaceId, topic);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
if (revision !== this.readRevision(workspaceId, topic)) {
|
|
143
|
+
void this.invalidate(workspaceId, topic);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
123
146
|
const activeSubscribers = subscribers.filter((watch) => this.matches(workspaceId, watch));
|
|
124
147
|
if (activeSubscribers.length === 0)
|
|
125
148
|
return;
|
|
@@ -157,7 +180,7 @@ export class WorkspaceWatchSnapshotService {
|
|
|
157
180
|
read(workspace, topic, watch) {
|
|
158
181
|
const key = topic === 'files'
|
|
159
182
|
? `${workspace.id}:files:${JSON.stringify(watch.topics.files)}`
|
|
160
|
-
: `${workspace.id}:${topic}`;
|
|
183
|
+
: `${workspace.id}:${topic}:${this.readRevision(workspace.id, topic)}`;
|
|
161
184
|
const active = this.reads.get(key);
|
|
162
185
|
if (active !== undefined)
|
|
163
186
|
return active;
|
|
@@ -166,8 +189,12 @@ export class WorkspaceWatchSnapshotService {
|
|
|
166
189
|
: topic === 'changes'
|
|
167
190
|
? workspace.kind === 'GIT_WORKSPACE'
|
|
168
191
|
? this.options.changes.current(workspace)
|
|
169
|
-
: Promise.resolve(
|
|
170
|
-
|
|
192
|
+
: Promise.resolve(workspace.includeParentRepository === false
|
|
193
|
+
? { workspace, changes: [], repositories: [] }
|
|
194
|
+
: null)
|
|
195
|
+
: this.options.files
|
|
196
|
+
.list(workspace, watch.topics.files)
|
|
197
|
+
.then((files) => ({ files, workspace: this.options.requireWorkspace(workspace.id) }))).finally(() => {
|
|
171
198
|
if (this.reads.get(key) === read)
|
|
172
199
|
this.reads.delete(key);
|
|
173
200
|
});
|
|
@@ -181,6 +208,9 @@ export class WorkspaceWatchSnapshotService {
|
|
|
181
208
|
this.signatures.set(key, next);
|
|
182
209
|
return true;
|
|
183
210
|
}
|
|
211
|
+
readRevision(workspaceId, topic) {
|
|
212
|
+
return topic === 'changes' ? this.options.changes.revision(workspaceId) : 0;
|
|
213
|
+
}
|
|
184
214
|
viewKey(workspaceId, topic, watch) {
|
|
185
215
|
return topic === 'files'
|
|
186
216
|
? `${workspaceId}:files:${JSON.stringify(watch.topics.files)}`
|