granttap-mcp 0.8.178 → 0.8.180
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/README.md +14 -0
- package/apps/bridge/src/host/session-keys.ts +4 -1
- package/apps/bridge/src/mesh/README.md +8 -0
- package/apps/bridge/src/mesh/catalog/binding-state.ts +3 -1
- package/apps/bridge/src/mesh/catalog/index.ts +40 -28
- package/apps/bridge/src/mesh/repositories/candidates.ts +99 -0
- package/apps/bridge/src/mesh/repositories/checkout.ts +43 -0
- package/apps/bridge/src/mesh/repositories/edit.ts +118 -0
- package/apps/bridge/src/mesh/repositories/index.ts +161 -0
- package/apps/bridge/src/mesh/repositories/requests.ts +49 -0
- package/apps/bridge/src/mesh/store/index.ts +2 -2
- package/apps/bridge/src/mesh/store/repositories/index.ts +90 -0
- package/apps/bridge/src/mesh/store/state.ts +30 -1
- package/apps/bridge/src/mesh/store/sync.ts +4 -3
- package/apps/bridge/src/monitor/handlers/inbound.ts +4 -0
- package/apps/bridge/src/sessions/scan/claude/parse.ts +14 -2
- package/cursor-plugin/README.md +1 -1
- package/cursor-plugin/mcp.json +1 -1
- package/cursor-plugin/stdio-bootstrap.cjs +1 -1
- package/package.json +1 -1
- package/packages/protocol/messages/README.md +6 -0
- package/packages/protocol/messages/mesh/index.ts +1 -0
- package/packages/protocol/messages/mesh/repositories/index.ts +131 -0
- package/packages/protocol/schema.ts +8 -0
package/README.md
CHANGED
|
@@ -425,6 +425,20 @@ shows is what the mesh holds. A release is written to the store as a
|
|
|
425
425
|
tombstone, so a snapshot or a late event from a computer that was away cannot
|
|
426
426
|
bring the claim back.
|
|
427
427
|
|
|
428
|
+
### Repositories of a Mesh
|
|
429
|
+
|
|
430
|
+
The repositories a Mesh holds are changed from the phone, one computer at a
|
|
431
|
+
time. The phone asks a computer which checkouts it knows: the ones it binds
|
|
432
|
+
to any Mesh and the ones its chats work in, each repository once, with where
|
|
433
|
+
it is bound. Adding a checkout binds its Git work tree to the Mesh on that
|
|
434
|
+
computer; a repository already in another Mesh on the same computer stays
|
|
435
|
+
where it is. Removing takes out one of that computer's own bindings, never
|
|
436
|
+
another computer's, and never the Mesh's last repository — delete the Mesh
|
|
437
|
+
instead. A removed repository stays out: chats that keep working in it, and
|
|
438
|
+
snapshots that still list it, do not bind it again until it is added back.
|
|
439
|
+
Only a controller paired with the computer is answered, and the answer goes
|
|
440
|
+
to that controller alone.
|
|
441
|
+
|
|
428
442
|
### Task reports
|
|
429
443
|
|
|
430
444
|
<p align="center">
|
|
@@ -9,6 +9,8 @@ import type {
|
|
|
9
9
|
MeshEvent,
|
|
10
10
|
MeshSnapshot,
|
|
11
11
|
MeshInvocationPage,
|
|
12
|
+
MeshRepositoryEditResult,
|
|
13
|
+
MeshRepositoryList,
|
|
12
14
|
ProjectKnowledgePage,
|
|
13
15
|
Payload,
|
|
14
16
|
ProjectPolicyPayload,
|
|
@@ -56,7 +58,8 @@ export async function sendMeshPayload(
|
|
|
56
58
|
|
|
57
59
|
export async function sendProjectPayload(
|
|
58
60
|
client: RelayClient,
|
|
59
|
-
payload: ProjectPolicyPayload | MeshClaimReleaseResult | MeshInvocationPage | ProjectKnowledgePage
|
|
61
|
+
payload: ProjectPolicyPayload | MeshClaimReleaseResult | MeshInvocationPage | ProjectKnowledgePage
|
|
62
|
+
| MeshRepositoryList | MeshRepositoryEditResult,
|
|
60
63
|
to: Role | "all" = "phone",
|
|
61
64
|
options: SendOptions = {},
|
|
62
65
|
): Promise<void> {
|
|
@@ -79,6 +79,14 @@ not invent aliases. `task-queue.ts` holds a create until the offline deadline.
|
|
|
79
79
|
`instance-epoch` (bridge) rejects commands issued for a previous instance after
|
|
80
80
|
restore or clone. Display names and device aliases are never routing keys.
|
|
81
81
|
|
|
82
|
+
`repositories/` answers the phone's `mesh.repository.query` with the checkouts
|
|
83
|
+
this computer knows, one row per repository, and `mesh.repository.edit` by
|
|
84
|
+
binding one of them to a Mesh or removing one of this computer's own bindings.
|
|
85
|
+
A removal is kept in the store as `removedBindings`, local state that is never
|
|
86
|
+
published: the catalog and snapshot merges skip a removed binding for this
|
|
87
|
+
computer until the person adds it back. Edits are answered once per request id,
|
|
88
|
+
and a repeated request is given the first answer.
|
|
89
|
+
|
|
82
90
|
The Mesh brief guides an agent with Project scope, relevant restrictions,
|
|
83
91
|
repository topology, dependencies, and neighboring work. The local hook and
|
|
84
92
|
Engine enforce Governance decisions. GrantTap measures
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
ProjectBindingSummary,
|
|
3
3
|
type ProjectBindingSummary as BindingValue,
|
|
4
4
|
} from "../../../../../packages/protocol/schema";
|
|
5
|
-
import type
|
|
5
|
+
import { bindingRemoved, type StoreState } from "../store/state";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* The binding this endpoint owns for this repository, and nothing else.
|
|
@@ -36,11 +36,13 @@ export function bindingForRepository(
|
|
|
36
36
|
return projects.size === 1 ? matches[0] : undefined;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/** A binding the person removed on this computer is not bound again until they add it back. */
|
|
39
40
|
export function upsertBinding(
|
|
40
41
|
state: StoreState,
|
|
41
42
|
input: BindingValue,
|
|
42
43
|
): { bindings: BindingValue[]; changed: boolean } {
|
|
43
44
|
const binding = ProjectBindingSummary.parse(input);
|
|
45
|
+
if (bindingRemoved(state, binding)) return { bindings: state.bindings, changed: false };
|
|
44
46
|
const stableConflict = state.bindings.some((item) =>
|
|
45
47
|
item.bindingId === binding.bindingId
|
|
46
48
|
&& (item.projectId !== binding.projectId
|
|
@@ -200,34 +200,7 @@ function linkSession(input: {
|
|
|
200
200
|
createdAt: session.startedAt,
|
|
201
201
|
};
|
|
202
202
|
if (!knownProject) store.upsertProject(project);
|
|
203
|
-
|
|
204
|
-
const binding = {
|
|
205
|
-
bindingId: knownBinding?.bindingId
|
|
206
|
-
?? projectBindingIdentity(projectId, computerId, repository.canonicalRepositoryId),
|
|
207
|
-
projectId,
|
|
208
|
-
endpointId: computerId,
|
|
209
|
-
repositoryId: repository.canonicalRepositoryId,
|
|
210
|
-
displayName: knownBinding?.displayName ?? (basename(repository.root) || "Repository"),
|
|
211
|
-
localPathHint: repository.root,
|
|
212
|
-
available: true,
|
|
213
|
-
revision: repository.revision,
|
|
214
|
-
};
|
|
215
|
-
try {
|
|
216
|
-
store.upsertBinding(binding);
|
|
217
|
-
store.recordIntegrationPeers(
|
|
218
|
-
projectId, repository.canonicalRepositoryId, readIntegrationMap(repository.root),
|
|
219
|
-
);
|
|
220
|
-
void queueProjectBindingSync(project, {
|
|
221
|
-
summary: binding,
|
|
222
|
-
localRoot: repository.root,
|
|
223
|
-
canonicalRemote: repository.baseRemote
|
|
224
|
-
? sanitizedRepositoryRemote(repository.baseRemote)
|
|
225
|
-
: undefined,
|
|
226
|
-
lastSeenAt: session.lastActivityAt,
|
|
227
|
-
});
|
|
228
|
-
} catch {
|
|
229
|
-
// Reported as an absent binding rather than an absent Mesh.
|
|
230
|
-
}
|
|
203
|
+
bindSessionRepository(store, project, repository, computerId, session.lastActivityAt);
|
|
231
204
|
const taskId = knownTaskId ?? taskIdentity(projectId, agent, session.sessionId);
|
|
232
205
|
const task: MeshTask = {
|
|
233
206
|
taskId,
|
|
@@ -257,3 +230,42 @@ function linkSession(input: {
|
|
|
257
230
|
});
|
|
258
231
|
return { ...session, projectId, taskId, computerId, worktree: repository.worktree ?? previous?.worktree };
|
|
259
232
|
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Bind the chat's checkout to its Project on this computer. A repository the
|
|
236
|
+
* person took out of that Project here stays out, however many chats run in it.
|
|
237
|
+
*/
|
|
238
|
+
function bindSessionRepository(
|
|
239
|
+
store: MeshStore, project: Project, repository: RepositoryFacts, computerId: string, lastSeenAt: number,
|
|
240
|
+
): void {
|
|
241
|
+
const { projectId } = project;
|
|
242
|
+
if (store.bindingRemoved(projectId, computerId, repository.canonicalRepositoryId)) return;
|
|
243
|
+
const knownBinding = store.bindingForEndpoint(repository.canonicalRepositoryId, computerId);
|
|
244
|
+
const binding = {
|
|
245
|
+
bindingId: knownBinding?.bindingId
|
|
246
|
+
?? projectBindingIdentity(projectId, computerId, repository.canonicalRepositoryId),
|
|
247
|
+
projectId,
|
|
248
|
+
endpointId: computerId,
|
|
249
|
+
repositoryId: repository.canonicalRepositoryId,
|
|
250
|
+
displayName: knownBinding?.displayName ?? (basename(repository.root) || "Repository"),
|
|
251
|
+
localPathHint: repository.root,
|
|
252
|
+
available: true,
|
|
253
|
+
revision: repository.revision,
|
|
254
|
+
};
|
|
255
|
+
try {
|
|
256
|
+
store.upsertBinding(binding);
|
|
257
|
+
store.recordIntegrationPeers(
|
|
258
|
+
projectId, repository.canonicalRepositoryId, readIntegrationMap(repository.root),
|
|
259
|
+
);
|
|
260
|
+
void queueProjectBindingSync(project, {
|
|
261
|
+
summary: binding,
|
|
262
|
+
localRoot: repository.root,
|
|
263
|
+
canonicalRemote: repository.baseRemote
|
|
264
|
+
? sanitizedRepositoryRemote(repository.baseRemote)
|
|
265
|
+
: undefined,
|
|
266
|
+
lastSeenAt,
|
|
267
|
+
});
|
|
268
|
+
} catch {
|
|
269
|
+
// Reported as an absent binding rather than an absent Mesh.
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The checkouts this computer could bind to a Project: the ones it binds to
|
|
3
|
+
* any Project, and the ones its chats work in. A binding is one per
|
|
4
|
+
* repository on a computer, so each repository is listed once — at its bound
|
|
5
|
+
* checkout while that still exists, otherwise where a chat last worked.
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
MESH_REPOSITORY_LIST_LIMIT,
|
|
9
|
+
MeshRepositoryCandidate,
|
|
10
|
+
type MeshRepositoryList,
|
|
11
|
+
type MeshRepositoryQuery,
|
|
12
|
+
type ProjectBindingSummary,
|
|
13
|
+
type SessionInfo,
|
|
14
|
+
} from "../../../../../packages/protocol/schema";
|
|
15
|
+
import { helperRunFolder } from "../../helper-runs";
|
|
16
|
+
import type { MeshStore } from "../store";
|
|
17
|
+
import { checkoutName, existingPath, type InspectRepository } from "./checkout";
|
|
18
|
+
|
|
19
|
+
/** How many chat folders one listing reads with Git, most recently worked in first. */
|
|
20
|
+
export const MAX_LISTED_FOLDERS = 256;
|
|
21
|
+
|
|
22
|
+
type Checkout = { path: string; repositoryId: string; seenAt: number };
|
|
23
|
+
|
|
24
|
+
export type RepositoryListInput = {
|
|
25
|
+
store: MeshStore;
|
|
26
|
+
request: MeshRepositoryQuery;
|
|
27
|
+
endpointId: string;
|
|
28
|
+
sessions: SessionInfo[];
|
|
29
|
+
inspect: InspectRepository;
|
|
30
|
+
now: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export async function listMeshRepositories(input: RepositoryListInput): Promise<MeshRepositoryList> {
|
|
34
|
+
const { store, request, endpointId } = input;
|
|
35
|
+
const bindings = new Map(store.endpointBindings(endpointId).map((item) => [item.repositoryId, item]));
|
|
36
|
+
const checkouts = new Map<string, Checkout>();
|
|
37
|
+
const keep = (checkout: Checkout) => {
|
|
38
|
+
const known = checkouts.get(checkout.repositoryId);
|
|
39
|
+
if (!known || checkout.seenAt > known.seenAt) checkouts.set(checkout.repositoryId, checkout);
|
|
40
|
+
};
|
|
41
|
+
for (const binding of bindings.values()) {
|
|
42
|
+
const path = binding.localPathHint ? await existingPath(binding.localPathHint) : undefined;
|
|
43
|
+
if (path) keep({ path, repositoryId: binding.repositoryId, seenAt: Number.POSITIVE_INFINITY });
|
|
44
|
+
}
|
|
45
|
+
// Git reads share the runtime's bounded pool, so asking for all of them at once does not flood it.
|
|
46
|
+
const read = await Promise.all(chatFolders(input.sessions).map(async (folder) => {
|
|
47
|
+
const facts = await input.inspect(folder.path);
|
|
48
|
+
const path = facts.worktree ? await existingPath(facts.worktree) : undefined;
|
|
49
|
+
return path ? [{ path, repositoryId: facts.canonicalRepositoryId, seenAt: folder.seenAt }] : [];
|
|
50
|
+
}));
|
|
51
|
+
for (const checkout of read.flat()) keep(checkout);
|
|
52
|
+
const repositories = [...checkouts.values()]
|
|
53
|
+
.flatMap((checkout) => candidate(checkout, bindings.get(checkout.repositoryId), request.projectId, store))
|
|
54
|
+
.filter((item, index, all) => all.findIndex((other) => other.path === item.path) === index)
|
|
55
|
+
.sort((left, right) => Number(right.boundHere) - Number(left.boundHere)
|
|
56
|
+
|| left.name.localeCompare(right.name) || left.path.localeCompare(right.path))
|
|
57
|
+
.slice(0, MESH_REPOSITORY_LIST_LIMIT);
|
|
58
|
+
return {
|
|
59
|
+
type: "mesh.repository.list",
|
|
60
|
+
sessionId: request.projectId,
|
|
61
|
+
projectId: request.projectId,
|
|
62
|
+
requestId: request.requestId,
|
|
63
|
+
computerId: endpointId,
|
|
64
|
+
repositories,
|
|
65
|
+
generatedAt: input.now,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Each folder a chat worked in, once, latest first; a generator's throwaway folder is no checkout. */
|
|
70
|
+
function chatFolders(sessions: SessionInfo[]): Array<{ path: string; seenAt: number }> {
|
|
71
|
+
const seen = new Map<string, number>();
|
|
72
|
+
for (const session of sessions) {
|
|
73
|
+
const path = (session.worktree ?? session.cwd)?.trim();
|
|
74
|
+
if (!path || helperRunFolder(path)) continue;
|
|
75
|
+
seen.set(path, Math.max(seen.get(path) ?? 0, session.lastActivityAt));
|
|
76
|
+
}
|
|
77
|
+
return [...seen].map(([path, seenAt]) => ({ path, seenAt }))
|
|
78
|
+
.sort((left, right) => right.seenAt - left.seenAt)
|
|
79
|
+
.slice(0, MAX_LISTED_FOLDERS);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function candidate(
|
|
83
|
+
checkout: Checkout, binding: ProjectBindingSummary | undefined, projectId: string, store: MeshStore,
|
|
84
|
+
): MeshRepositoryCandidate[] {
|
|
85
|
+
const boundHere = binding != null && binding.projectId === projectId;
|
|
86
|
+
const elsewhere = binding != null && !boundHere ? binding : undefined;
|
|
87
|
+
const other = elsewhere ? store.project(elsewhere.projectId) : undefined;
|
|
88
|
+
const parsed = MeshRepositoryCandidate.safeParse({
|
|
89
|
+
path: checkout.path,
|
|
90
|
+
name: checkoutName(checkout.path),
|
|
91
|
+
repositoryId: checkout.repositoryId,
|
|
92
|
+
boundHere,
|
|
93
|
+
...(binding && boundHere ? { bindingId: binding.bindingId } : {}),
|
|
94
|
+
...(elsewhere ? { otherProjectId: elsewhere.projectId } : {}),
|
|
95
|
+
...(other ? { otherProjectName: other.name } : {}),
|
|
96
|
+
});
|
|
97
|
+
// A path the wire would alter, or one too long to carry, is left out rather than misnamed.
|
|
98
|
+
return parsed.success && parsed.data.path === checkout.path ? [parsed.data] : [];
|
|
99
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** A folder on this computer read as the Git checkout it belongs to. */
|
|
2
|
+
import { realpath, stat } from "node:fs/promises";
|
|
3
|
+
import { basename, isAbsolute } from "node:path";
|
|
4
|
+
import type { RepositoryFacts } from "../catalog";
|
|
5
|
+
|
|
6
|
+
export type InspectRepository = (cwd: string) => Promise<RepositoryFacts>;
|
|
7
|
+
|
|
8
|
+
export type CheckoutReading =
|
|
9
|
+
| { ok: true; root: string; facts: RepositoryFacts }
|
|
10
|
+
| { ok: false; reason: "not-found" | "not-a-repository" };
|
|
11
|
+
|
|
12
|
+
/** The real path of something that exists, or nothing. */
|
|
13
|
+
export async function existingPath(path: string): Promise<string | undefined> {
|
|
14
|
+
if (!isAbsolute(path)) return undefined;
|
|
15
|
+
try {
|
|
16
|
+
return await realpath(path);
|
|
17
|
+
} catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The work-tree root a path lies in, by its real path, and what Git says of
|
|
24
|
+
* it. A folder outside any work tree, or a file, is not a checkout.
|
|
25
|
+
*/
|
|
26
|
+
export async function readCheckout(path: string, inspect: InspectRepository): Promise<CheckoutReading> {
|
|
27
|
+
const real = await existingPath(path);
|
|
28
|
+
if (!real) return { ok: false, reason: "not-found" };
|
|
29
|
+
try {
|
|
30
|
+
if (!(await stat(real)).isDirectory()) return { ok: false, reason: "not-a-repository" };
|
|
31
|
+
} catch {
|
|
32
|
+
return { ok: false, reason: "not-found" };
|
|
33
|
+
}
|
|
34
|
+
const facts = await inspect(real);
|
|
35
|
+
const root = facts.worktree ? await existingPath(facts.worktree) : undefined;
|
|
36
|
+
if (!root) return { ok: false, reason: "not-a-repository" };
|
|
37
|
+
return { ok: true, root, facts: root === facts.root ? facts : { ...facts, root, worktree: root } };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** What a person calls a checkout: its folder's name. */
|
|
41
|
+
export function checkoutName(root: string): string {
|
|
42
|
+
return (basename(root).trim() || "Repository").slice(0, 160);
|
|
43
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add one of this computer's checkouts to a Project, or take one of its own
|
|
3
|
+
* bindings out. Nothing here moves a repository between Projects or reaches
|
|
4
|
+
* another computer's binding: what the person changes from the phone is what
|
|
5
|
+
* this computer holds.
|
|
6
|
+
*/
|
|
7
|
+
import { isAbsolute } from "node:path";
|
|
8
|
+
import type {
|
|
9
|
+
MeshRepositoryEdit,
|
|
10
|
+
MeshRepositoryEditReason,
|
|
11
|
+
Project,
|
|
12
|
+
ProjectBindingSummary,
|
|
13
|
+
} from "../../../../../packages/protocol/schema";
|
|
14
|
+
import { queueProjectBindingSync } from "../../engine/runtime/engine-projects";
|
|
15
|
+
import { projectBindingIdentity, sanitizedRepositoryRemote } from "../identity";
|
|
16
|
+
import { readIntegrationMap } from "../observed/integration-map";
|
|
17
|
+
import type { MeshStore } from "../store";
|
|
18
|
+
import { checkoutName, readCheckout, type InspectRepository } from "./checkout";
|
|
19
|
+
|
|
20
|
+
export type RepositoryEditOutcome = {
|
|
21
|
+
ok: boolean;
|
|
22
|
+
reason?: MeshRepositoryEditReason;
|
|
23
|
+
detail?: string;
|
|
24
|
+
bindingId?: string;
|
|
25
|
+
/** The binding that was added or removed, when the Mesh changed. */
|
|
26
|
+
changed?: ProjectBindingSummary;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function refusal(reason: MeshRepositoryEditReason, detail: string): RepositoryEditOutcome {
|
|
30
|
+
return { ok: false, reason, detail };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const FAILED = "The Mesh could not be changed on this computer. Try again.";
|
|
34
|
+
const UNKNOWN_MESH = "This computer does not have this Mesh.";
|
|
35
|
+
|
|
36
|
+
export async function addMeshRepository(
|
|
37
|
+
store: MeshStore, request: MeshRepositoryEdit, endpointId: string, inspect: InspectRepository,
|
|
38
|
+
): Promise<RepositoryEditOutcome> {
|
|
39
|
+
if (!request.path || !isAbsolute(request.path)) {
|
|
40
|
+
return refusal("invalid", "Adding a repository needs the full path of its checkout on this computer.");
|
|
41
|
+
}
|
|
42
|
+
const reading = await readCheckout(request.path, inspect);
|
|
43
|
+
if (!reading.ok) {
|
|
44
|
+
return reading.reason === "not-found"
|
|
45
|
+
? refusal("not-found", "There is no such folder on this computer.")
|
|
46
|
+
: refusal("not-a-repository", "That folder is not inside a Git checkout.");
|
|
47
|
+
}
|
|
48
|
+
const { root, facts } = reading;
|
|
49
|
+
const binding: ProjectBindingSummary = {
|
|
50
|
+
bindingId: projectBindingIdentity(request.projectId, endpointId, facts.canonicalRepositoryId),
|
|
51
|
+
projectId: request.projectId,
|
|
52
|
+
endpointId,
|
|
53
|
+
repositoryId: facts.canonicalRepositoryId,
|
|
54
|
+
displayName: checkoutName(root),
|
|
55
|
+
localPathHint: root,
|
|
56
|
+
available: true,
|
|
57
|
+
...(facts.revision ? { revision: facts.revision } : {}),
|
|
58
|
+
};
|
|
59
|
+
const outcome = store.bindRepository(binding);
|
|
60
|
+
switch (outcome.kind) {
|
|
61
|
+
case "bound": {
|
|
62
|
+
const project = store.project(request.projectId);
|
|
63
|
+
if (project) admitBinding(store, project, outcome.binding, facts.baseRemote);
|
|
64
|
+
return { ok: true, bindingId: outcome.binding.bindingId, changed: outcome.binding };
|
|
65
|
+
}
|
|
66
|
+
case "already-bound":
|
|
67
|
+
return { ok: true, reason: "already-bound", bindingId: outcome.binding.bindingId,
|
|
68
|
+
detail: "This repository is already in this Mesh on this computer." };
|
|
69
|
+
case "bound-elsewhere": {
|
|
70
|
+
const name = store.project(outcome.binding.projectId)?.name.slice(0, 160);
|
|
71
|
+
return refusal("bound-elsewhere", name
|
|
72
|
+
? `This repository is in the Mesh "${name}" on this computer. Remove it there first.`
|
|
73
|
+
: "This repository is in another Mesh on this computer. Remove it there first.");
|
|
74
|
+
}
|
|
75
|
+
case "unknown-mesh":
|
|
76
|
+
return refusal("unknown-mesh", UNKNOWN_MESH);
|
|
77
|
+
default:
|
|
78
|
+
return refusal("failed", FAILED);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function removeMeshRepository(
|
|
83
|
+
store: MeshStore, request: MeshRepositoryEdit, endpointId: string,
|
|
84
|
+
): RepositoryEditOutcome {
|
|
85
|
+
if (!request.bindingId) return refusal("invalid", "Removing a repository needs the id of its binding.");
|
|
86
|
+
const outcome = store.unbindRepository(request.projectId, request.bindingId, endpointId);
|
|
87
|
+
switch (outcome.kind) {
|
|
88
|
+
case "removed":
|
|
89
|
+
return { ok: true, bindingId: outcome.binding.bindingId, changed: outcome.binding };
|
|
90
|
+
case "not-found":
|
|
91
|
+
return refusal("not-found", "That repository is not bound to this Mesh.");
|
|
92
|
+
case "not-this-computer":
|
|
93
|
+
return refusal("not-this-computer",
|
|
94
|
+
"That repository is bound on another computer. Only that computer can remove it.");
|
|
95
|
+
case "last-repository":
|
|
96
|
+
return refusal("last-repository", "This is the last repository in the Mesh. Delete the Mesh instead.");
|
|
97
|
+
case "unknown-mesh":
|
|
98
|
+
return refusal("unknown-mesh", UNKNOWN_MESH);
|
|
99
|
+
default:
|
|
100
|
+
return refusal("failed", FAILED);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function unknownMesh(): RepositoryEditOutcome {
|
|
105
|
+
return refusal("unknown-mesh", UNKNOWN_MESH);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** What a chat's checkout gets when it is bound: its neighbours on record and the Engine told. */
|
|
109
|
+
function admitBinding(store: MeshStore, project: Project, binding: ProjectBindingSummary, remote?: string): void {
|
|
110
|
+
const root = binding.localPathHint!;
|
|
111
|
+
store.recordIntegrationPeers(project.projectId, binding.repositoryId, readIntegrationMap(root));
|
|
112
|
+
void queueProjectBindingSync(project, {
|
|
113
|
+
summary: binding,
|
|
114
|
+
localRoot: root,
|
|
115
|
+
canonicalRemote: remote ? sanitizedRepositoryRemote(remote) : undefined,
|
|
116
|
+
lastSeenAt: Date.now(),
|
|
117
|
+
}).catch(() => false);
|
|
118
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The phone reads and changes which repositories a Mesh holds on this
|
|
3
|
+
* computer. Only a controller paired with this computer is answered, and
|
|
4
|
+
* only with a request made in the last two minutes; the answer goes to that
|
|
5
|
+
* controller alone. It is sealed under the Project's key when this computer
|
|
6
|
+
* has the Project, and sent over the pairing otherwise.
|
|
7
|
+
*/
|
|
8
|
+
import type { RelayClient } from "../../../../../packages/core/relay-client";
|
|
9
|
+
import type {
|
|
10
|
+
MeshRepositoryEdit,
|
|
11
|
+
MeshRepositoryEditResult,
|
|
12
|
+
MeshRepositoryQuery,
|
|
13
|
+
SessionInfo,
|
|
14
|
+
} from "../../../../../packages/protocol/schema";
|
|
15
|
+
import { loadConfig, loadRuntimeConfig, machineConfigPath } from "../../config";
|
|
16
|
+
import { sendProjectPayload } from "../../host/session-keys";
|
|
17
|
+
import { publishedCatalog } from "../../session-catalog";
|
|
18
|
+
import { inspectRepositoryAsync } from "../catalog/repository-inspection";
|
|
19
|
+
import { computerId } from "../identity/computer";
|
|
20
|
+
import { localMeshStore } from "../local-remote/local";
|
|
21
|
+
import type { MeshStore } from "../store";
|
|
22
|
+
import { listMeshRepositories } from "./candidates";
|
|
23
|
+
import type { InspectRepository } from "./checkout";
|
|
24
|
+
import { addMeshRepository, refusal, removeMeshRepository, unknownMesh, type RepositoryEditOutcome } from "./edit";
|
|
25
|
+
import { EditRequests } from "./requests";
|
|
26
|
+
|
|
27
|
+
export const REQUEST_WINDOW_MS = 120_000;
|
|
28
|
+
|
|
29
|
+
export type RepositoryRequestDependencies = {
|
|
30
|
+
store: () => MeshStore;
|
|
31
|
+
endpoint: () => string;
|
|
32
|
+
meshEnabled: () => boolean;
|
|
33
|
+
paired: (room: string, peer: string) => boolean;
|
|
34
|
+
sessions: (client: RelayClient) => SessionInfo[];
|
|
35
|
+
inspect: InspectRepository;
|
|
36
|
+
now: () => number;
|
|
37
|
+
log: (line: string) => void;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const requests = new EditRequests();
|
|
41
|
+
|
|
42
|
+
/** A controller this computer was paired with, on the route it was paired on. */
|
|
43
|
+
export function pairedController(room: string, peer: string): boolean {
|
|
44
|
+
try {
|
|
45
|
+
const machine = loadConfig(machineConfigPath());
|
|
46
|
+
return machine.role === "machine" && machine.room === room
|
|
47
|
+
&& (machine.peerPublicKey === peer || machine.extraPeerPublicKeys?.includes(peer) === true);
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const defaultRepositoryDependencies: RepositoryRequestDependencies = {
|
|
54
|
+
store: localMeshStore,
|
|
55
|
+
endpoint: () => computerId(),
|
|
56
|
+
meshEnabled: () => loadRuntimeConfig().meshEnabled,
|
|
57
|
+
paired: pairedController,
|
|
58
|
+
sessions: (client) => {
|
|
59
|
+
const catalog = publishedCatalog(client);
|
|
60
|
+
return catalog ? [...catalog.sessions, ...(catalog.history ?? [])] : [];
|
|
61
|
+
},
|
|
62
|
+
inspect: inspectRepositoryAsync,
|
|
63
|
+
now: Date.now,
|
|
64
|
+
log: (line) => { process.stderr.write(`[monitor] mesh: ${line}\n`); },
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export async function handleMeshRepositoryRequest(
|
|
68
|
+
client: RelayClient,
|
|
69
|
+
payload: MeshRepositoryQuery | MeshRepositoryEdit,
|
|
70
|
+
peer: string | undefined,
|
|
71
|
+
publish: () => Promise<void>,
|
|
72
|
+
deps: RepositoryRequestDependencies = defaultRepositoryDependencies,
|
|
73
|
+
): Promise<boolean> {
|
|
74
|
+
if (!peer || !Number.isFinite(payload.createdAt)
|
|
75
|
+
|| Math.abs(deps.now() - payload.createdAt) > REQUEST_WINDOW_MS || !deps.paired(client.room, peer)) return false;
|
|
76
|
+
return payload.type === "mesh.repository.query"
|
|
77
|
+
? answerQuery(client, payload, peer, deps)
|
|
78
|
+
: answerEdit(client, payload, peer, publish, deps);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function answerQuery(
|
|
82
|
+
client: RelayClient, request: MeshRepositoryQuery, peer: string, deps: RepositoryRequestDependencies,
|
|
83
|
+
): Promise<boolean> {
|
|
84
|
+
if (!deps.meshEnabled()) return false;
|
|
85
|
+
const store = deps.store();
|
|
86
|
+
if (!store.project(request.projectId)) return false;
|
|
87
|
+
const list = await listMeshRepositories({
|
|
88
|
+
store, request, endpointId: deps.endpoint(), sessions: deps.sessions(client), inspect: deps.inspect, now: deps.now(),
|
|
89
|
+
});
|
|
90
|
+
await sendProjectPayload(client, list, "phone", { peerPublicKey: peer, reliable: false, ttlMs: 60_000 })
|
|
91
|
+
.catch(() => {});
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function answerEdit(
|
|
96
|
+
client: RelayClient, request: MeshRepositoryEdit, peer: string,
|
|
97
|
+
publish: () => Promise<void>, deps: RepositoryRequestDependencies,
|
|
98
|
+
): Promise<boolean> {
|
|
99
|
+
const recall = requests.recall(`${client.room}\0${peer}`, request, deps.now());
|
|
100
|
+
if (recall.kind === "conflict") return false;
|
|
101
|
+
if (recall.kind === "replay") {
|
|
102
|
+
await send(client, peer, await recall.result, deps);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
const work = edit(request, deps).then((outcome) => {
|
|
106
|
+
if (outcome.changed) {
|
|
107
|
+
deps.log(`repository ${outcome.changed.repositoryId} ${request.action === "add" ? "added to" : "removed from"} `
|
|
108
|
+
+ `${request.projectId} by the person`);
|
|
109
|
+
void publish().catch(() => {});
|
|
110
|
+
}
|
|
111
|
+
return editResult(request, outcome, deps.now());
|
|
112
|
+
});
|
|
113
|
+
recall.remember(work);
|
|
114
|
+
await send(client, peer, await work, deps);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async function edit(request: MeshRepositoryEdit, deps: RepositoryRequestDependencies): Promise<RepositoryEditOutcome> {
|
|
119
|
+
try {
|
|
120
|
+
if (!deps.meshEnabled()) return refusal("mesh-disabled", "The Mesh is turned off on this computer.");
|
|
121
|
+
const store = deps.store();
|
|
122
|
+
if (!store.project(request.projectId)) return unknownMesh();
|
|
123
|
+
return request.action === "add"
|
|
124
|
+
? await addMeshRepository(store, request, deps.endpoint(), deps.inspect)
|
|
125
|
+
: removeMeshRepository(store, request, deps.endpoint());
|
|
126
|
+
} catch {
|
|
127
|
+
return refusal("failed", "The Mesh could not be changed on this computer. Try again.");
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function editResult(
|
|
132
|
+
request: MeshRepositoryEdit, outcome: RepositoryEditOutcome, now: number,
|
|
133
|
+
): MeshRepositoryEditResult {
|
|
134
|
+
return {
|
|
135
|
+
type: "mesh.repository.edit.result",
|
|
136
|
+
sessionId: request.projectId,
|
|
137
|
+
projectId: request.projectId,
|
|
138
|
+
requestId: request.requestId,
|
|
139
|
+
action: request.action,
|
|
140
|
+
ok: outcome.ok,
|
|
141
|
+
...(outcome.reason ? { reason: outcome.reason } : {}),
|
|
142
|
+
...(outcome.detail ? { detail: outcome.detail.slice(0, 300) } : {}),
|
|
143
|
+
...(outcome.bindingId ? { bindingId: outcome.bindingId } : {}),
|
|
144
|
+
generatedAt: now,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** A Project this computer has is answered under its key; any other is answered over the pairing, minting no key. */
|
|
149
|
+
async function send(
|
|
150
|
+
client: RelayClient, peer: string, result: MeshRepositoryEditResult, deps: RepositoryRequestDependencies,
|
|
151
|
+
): Promise<void> {
|
|
152
|
+
const options = { peerPublicKey: peer, ttlMs: 15 * 60_000 };
|
|
153
|
+
const known = deps.store().project(result.projectId) != null;
|
|
154
|
+
await (known ? sendProjectPayload(client, result, "phone", options) : client.sendToPeer(result, peer, options))
|
|
155
|
+
.catch(() => {});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Forget every remembered edit; for a fresh runtime state. */
|
|
159
|
+
export function resetRepositoryRequests(): void {
|
|
160
|
+
requests.clear();
|
|
161
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One answer per edit request. A phone that did not hear back asks again
|
|
3
|
+
* with the same request id; it is given the answer the first request got,
|
|
4
|
+
* and the edit is not made twice. A different edit under a used id is not
|
|
5
|
+
* answered at all.
|
|
6
|
+
*/
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import type { MeshRepositoryEdit, MeshRepositoryEditResult } from "../../../../../packages/protocol/schema";
|
|
9
|
+
|
|
10
|
+
export const EDIT_MEMORY_MS = 10 * 60_000;
|
|
11
|
+
export const MAX_REMEMBERED_EDITS = 128;
|
|
12
|
+
|
|
13
|
+
type Entry = { fingerprint: string; at: number; result: Promise<MeshRepositoryEditResult> };
|
|
14
|
+
|
|
15
|
+
export type EditRecall =
|
|
16
|
+
| { kind: "new"; remember: (result: Promise<MeshRepositoryEditResult>) => void }
|
|
17
|
+
| { kind: "replay"; result: Promise<MeshRepositoryEditResult> }
|
|
18
|
+
| { kind: "conflict" };
|
|
19
|
+
|
|
20
|
+
/** What makes two requests the same edit: not when they were sent, only what they ask. */
|
|
21
|
+
export function editFingerprint(request: MeshRepositoryEdit): string {
|
|
22
|
+
return createHash("sha256").update(JSON.stringify([
|
|
23
|
+
request.projectId, request.action, request.path ?? null, request.bindingId ?? null,
|
|
24
|
+
])).digest("hex");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class EditRequests {
|
|
28
|
+
private readonly entries = new Map<string, Entry>();
|
|
29
|
+
|
|
30
|
+
recall(scope: string, request: MeshRepositoryEdit, now: number): EditRecall {
|
|
31
|
+
for (const [key, entry] of this.entries) if (now - entry.at > EDIT_MEMORY_MS) this.entries.delete(key);
|
|
32
|
+
const key = `${scope}\0${request.requestId}`;
|
|
33
|
+
const fingerprint = editFingerprint(request);
|
|
34
|
+
const known = this.entries.get(key);
|
|
35
|
+
if (known) return known.fingerprint === fingerprint ? { kind: "replay", result: known.result } : { kind: "conflict" };
|
|
36
|
+
return {
|
|
37
|
+
kind: "new",
|
|
38
|
+
remember: (result) => {
|
|
39
|
+
// The oldest answer gives way; Map keeps insertion order.
|
|
40
|
+
while (this.entries.size >= MAX_REMEMBERED_EDITS) this.entries.delete(this.entries.keys().next().value!);
|
|
41
|
+
this.entries.set(key, { fingerprint, at: now, result });
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
clear(): void {
|
|
47
|
+
this.entries.clear();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -28,7 +28,7 @@ import { projectSharedSkills } from "../../capabilities/skills";
|
|
|
28
28
|
import { loadExecutionPolicy } from "../runtime/execution-policy";
|
|
29
29
|
import { loadEnvironment, redactEnvironment } from "../context/env";
|
|
30
30
|
import { loadRestrictions } from "../restrictions";
|
|
31
|
-
import {
|
|
31
|
+
import { MeshRepositoryStore } from "./repositories";
|
|
32
32
|
import { activeProjectKnowledge, supersededProjectKnowledgeIds } from "../knowledge/active";
|
|
33
33
|
import { restoreHandoffResult, validStoredReceipt } from './receipts';
|
|
34
34
|
import {
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
} from "../catalog/project/requests";
|
|
37
37
|
import { helperRunProject } from "../../helper-runs";
|
|
38
38
|
|
|
39
|
-
export class MeshStore extends
|
|
39
|
+
export class MeshStore extends MeshRepositoryStore {
|
|
40
40
|
recordReceipt(input: ReceiptValue): void {
|
|
41
41
|
this.sync();
|
|
42
42
|
const receipt = HandoffReceipt.parse(input);
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The person's changes to which repositories a Project holds on this
|
|
3
|
+
* computer. Each is checked and written as one step under the store's lock,
|
|
4
|
+
* so the binding it is checked against is the binding it changes.
|
|
5
|
+
*/
|
|
6
|
+
import type { ProjectBindingSummary as BindingValue } from "../../../../../../packages/protocol/schema";
|
|
7
|
+
import { upsertBinding } from "../../catalog/binding-state";
|
|
8
|
+
import { MeshPreparedStore } from "../receipts/prepared-availability";
|
|
9
|
+
import { bindingRemoved, MAX_REMOVED_BINDINGS, type RemovedBinding } from "../state";
|
|
10
|
+
|
|
11
|
+
export type RepositoryBindOutcome =
|
|
12
|
+
| { kind: "bound" | "already-bound"; binding: BindingValue }
|
|
13
|
+
| { kind: "bound-elsewhere"; binding: BindingValue }
|
|
14
|
+
| { kind: "unknown-mesh" | "conflict" | "busy" };
|
|
15
|
+
|
|
16
|
+
export type RepositoryUnbindOutcome =
|
|
17
|
+
| { kind: "removed" | "not-this-computer"; binding: BindingValue }
|
|
18
|
+
| { kind: "unknown-mesh" | "not-found" | "last-repository" | "busy" };
|
|
19
|
+
|
|
20
|
+
function sameRepository(item: RemovedBinding, binding: BindingValue): boolean {
|
|
21
|
+
return item.projectId === binding.projectId && item.endpointId === binding.endpointId
|
|
22
|
+
&& item.repositoryId === binding.repositoryId;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class MeshRepositoryStore extends MeshPreparedStore {
|
|
26
|
+
/** Every binding this endpoint holds, in any Project. */
|
|
27
|
+
endpointBindings(endpointId: string): BindingValue[] {
|
|
28
|
+
this.sync();
|
|
29
|
+
return this.state.bindings.filter((item) => item.endpointId === endpointId).map((item) => ({ ...item }));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Whether the person took this repository out of the Project on this endpoint. */
|
|
33
|
+
bindingRemoved(projectId: string, endpointId: string, repositoryId: string): boolean {
|
|
34
|
+
this.sync();
|
|
35
|
+
return bindingRemoved(this.state, { projectId, endpointId, repositoryId });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Bind one of this endpoint's checkouts to a Project. A repository this
|
|
40
|
+
* endpoint already binds to another Project stays there; the removal on
|
|
41
|
+
* record for this one, if any, is forgotten.
|
|
42
|
+
*/
|
|
43
|
+
bindRepository(input: BindingValue): RepositoryBindOutcome {
|
|
44
|
+
const result = this.transact((): RepositoryBindOutcome => {
|
|
45
|
+
if (!this.state.projects.some((item) => item.projectId === input.projectId)) return { kind: "unknown-mesh" };
|
|
46
|
+
const own = this.state.bindings.find((item) =>
|
|
47
|
+
item.endpointId === input.endpointId && item.repositoryId === input.repositoryId);
|
|
48
|
+
if (own) return { kind: own.projectId === input.projectId ? "already-bound" : "bound-elsewhere", binding: own };
|
|
49
|
+
const removedBindings = this.state.removedBindings.filter((item) => !sameRepository(item, input));
|
|
50
|
+
let bindings: BindingValue[];
|
|
51
|
+
try {
|
|
52
|
+
bindings = upsertBinding({ ...this.state, removedBindings }, input).bindings;
|
|
53
|
+
} catch {
|
|
54
|
+
return { kind: "conflict" };
|
|
55
|
+
}
|
|
56
|
+
this.state.removedBindings = removedBindings;
|
|
57
|
+
this.state.bindings = bindings;
|
|
58
|
+
return { kind: "bound", binding: input };
|
|
59
|
+
});
|
|
60
|
+
return result.applied ? result.value : { kind: "busy" };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Take one of this endpoint's bindings out of a Project and keep a record
|
|
65
|
+
* that it was taken out. Another computer's binding is that computer's to
|
|
66
|
+
* remove, and a Project keeps at least one repository it can work in.
|
|
67
|
+
*/
|
|
68
|
+
unbindRepository(projectId: string, bindingId: string, endpointId: string): RepositoryUnbindOutcome {
|
|
69
|
+
const result = this.transact((): RepositoryUnbindOutcome => {
|
|
70
|
+
if (!this.state.projects.some((item) => item.projectId === projectId)) return { kind: "unknown-mesh" };
|
|
71
|
+
const binding = this.state.bindings.find((item) => item.bindingId === bindingId && item.projectId === projectId);
|
|
72
|
+
if (!binding) return { kind: "not-found" };
|
|
73
|
+
if (binding.endpointId !== endpointId) return { kind: "not-this-computer", binding };
|
|
74
|
+
const others = this.state.bindings.filter((item) => item.projectId === projectId && item.bindingId !== bindingId);
|
|
75
|
+
if (!others.some((item) => item.available)) return { kind: "last-repository" };
|
|
76
|
+
this.state.bindings = this.state.bindings.filter((item) => item.bindingId !== bindingId);
|
|
77
|
+
this.state.removedBindings = [
|
|
78
|
+
...this.state.removedBindings.filter((item) => !sameRepository(item, binding)),
|
|
79
|
+
{ projectId, endpointId, repositoryId: binding.repositoryId, at: this.now() },
|
|
80
|
+
].slice(-MAX_REMOVED_BINDINGS);
|
|
81
|
+
// What the repository said about its neighbours leaves with it, unless another computer still binds it.
|
|
82
|
+
if (!others.some((item) => item.repositoryId === binding.repositoryId)) {
|
|
83
|
+
this.state.peers = this.state.peers.filter((item) =>
|
|
84
|
+
!(item.projectId === projectId && item.repositoryId === binding.repositoryId));
|
|
85
|
+
}
|
|
86
|
+
return { kind: "removed", binding };
|
|
87
|
+
});
|
|
88
|
+
return result.applied ? result.value : { kind: "busy" };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -54,6 +54,27 @@ export const ReleasedClaim = z.object({
|
|
|
54
54
|
}).strict();
|
|
55
55
|
export type ReleasedClaim = z.infer<typeof ReleasedClaim>;
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* A repository the person took out of a Project on this computer, on record
|
|
59
|
+
* until they add it back. A chat in the checkout, or a snapshot that still
|
|
60
|
+
* lists the binding, would otherwise bind it again on the next catalog.
|
|
61
|
+
*/
|
|
62
|
+
export const RemovedBinding = z.object({
|
|
63
|
+
projectId: z.string().min(1).max(128),
|
|
64
|
+
endpointId: z.string().min(1).max(128),
|
|
65
|
+
repositoryId: z.string().min(1).max(512),
|
|
66
|
+
at: z.number().nonnegative(),
|
|
67
|
+
}).strict();
|
|
68
|
+
export type RemovedBinding = z.infer<typeof RemovedBinding>;
|
|
69
|
+
|
|
70
|
+
export function bindingRemoved(
|
|
71
|
+
state: Pick<StoreState, "removedBindings">,
|
|
72
|
+
binding: { projectId: string; endpointId: string; repositoryId: string },
|
|
73
|
+
): boolean {
|
|
74
|
+
return (state.removedBindings ?? []).some((item) => item.projectId === binding.projectId
|
|
75
|
+
&& item.endpointId === binding.endpointId && item.repositoryId === binding.repositoryId);
|
|
76
|
+
}
|
|
77
|
+
|
|
57
78
|
export type StoreState = {
|
|
58
79
|
version: 1;
|
|
59
80
|
projects: ProjectValue[];
|
|
@@ -68,16 +89,19 @@ export type StoreState = {
|
|
|
68
89
|
receipts: ReceiptValue[];
|
|
69
90
|
migrations: CapsuleMigration[];
|
|
70
91
|
releasedClaims: ReleasedClaim[];
|
|
92
|
+
removedBindings: RemovedBinding[];
|
|
71
93
|
};
|
|
72
94
|
|
|
73
95
|
const EMPTY: StoreState = {
|
|
74
96
|
version: 1, projects: [], bindings: [], peers: [], tasks: [], executions: [], claims: [],
|
|
75
97
|
dependencies: [], events: [], knowledge: [], receipts: [], migrations: [], releasedClaims: [],
|
|
98
|
+
removedBindings: [],
|
|
76
99
|
};
|
|
77
100
|
|
|
78
101
|
export const MAX_STORE_PEERS = 256;
|
|
79
102
|
export const MAX_STORE_MIGRATIONS = 64;
|
|
80
103
|
export const MAX_RELEASED_CLAIMS = 256;
|
|
104
|
+
export const MAX_REMOVED_BINDINGS = 256;
|
|
81
105
|
|
|
82
106
|
function parsedArray<T>(value: unknown, schema: { safeParse: (input: unknown) => { success: boolean; data?: T } }): T[] {
|
|
83
107
|
if (!Array.isArray(value)) return [];
|
|
@@ -115,10 +139,14 @@ export function readStoreState(path: string): StoreLoad {
|
|
|
115
139
|
return { status: "corrupt", state: emptyStoreState() };
|
|
116
140
|
}
|
|
117
141
|
const projects = parsedArray(value.projects, Project);
|
|
142
|
+
const removedBindings = parsedArray(value.removedBindings, RemovedBinding)
|
|
143
|
+
.filter((item) => projects.some((project) => project.projectId === item.projectId))
|
|
144
|
+
.slice(-MAX_REMOVED_BINDINGS);
|
|
145
|
+
// A binding written back by a writer that does not know the removal stays removed.
|
|
118
146
|
const bindings = validBindings(
|
|
119
147
|
parsedArray(value.bindings, ProjectBindingSummary),
|
|
120
148
|
new Set(projects.map((project) => project.projectId)),
|
|
121
|
-
);
|
|
149
|
+
).filter((binding) => !bindingRemoved({ removedBindings }, binding));
|
|
122
150
|
return {
|
|
123
151
|
status: "ok",
|
|
124
152
|
state: collapseSplitChats({
|
|
@@ -139,6 +167,7 @@ export function readStoreState(path: string): StoreLoad {
|
|
|
139
167
|
receipts: parsedArray(value.receipts, HandoffReceipt),
|
|
140
168
|
migrations: parsedArray(value.migrations, CapsuleMigration).slice(-MAX_STORE_MIGRATIONS),
|
|
141
169
|
releasedClaims: parsedArray(value.releasedClaims, ReleasedClaim).slice(-MAX_RELEASED_CLAIMS),
|
|
170
|
+
removedBindings,
|
|
142
171
|
}, path, MAX_STORE_MIGRATIONS),
|
|
143
172
|
};
|
|
144
173
|
} catch {
|
|
@@ -22,18 +22,18 @@ import { preferExecution, preferTask } from "../admin/convergence";
|
|
|
22
22
|
import { preferScopedExecution } from './receipts/execution-merge';
|
|
23
23
|
import { integrationPeerKey } from "../handoff/other-side";
|
|
24
24
|
import {
|
|
25
|
-
MAX_RELEASED_CLAIMS, MAX_STORE_MIGRATIONS, MAX_STORE_PEERS, type StoreState,
|
|
25
|
+
MAX_RELEASED_CLAIMS, MAX_REMOVED_BINDINGS, MAX_STORE_MIGRATIONS, MAX_STORE_PEERS, type StoreState,
|
|
26
26
|
} from "./state";
|
|
27
27
|
|
|
28
28
|
type Collection = Exclude<keyof StoreState, "version">;
|
|
29
29
|
|
|
30
30
|
const COLLECTIONS: Collection[] = [
|
|
31
31
|
"projects", "bindings", "peers", "tasks", "executions", "claims", "dependencies", "events",
|
|
32
|
-
"knowledge", "receipts", "migrations", "releasedClaims",
|
|
32
|
+
"knowledge", "receipts", "migrations", "releasedClaims", "removedBindings",
|
|
33
33
|
];
|
|
34
34
|
const BOUNDS: Partial<Record<Collection, number>> = {
|
|
35
35
|
peers: MAX_STORE_PEERS, events: 512, receipts: 256, migrations: MAX_STORE_MIGRATIONS,
|
|
36
|
-
knowledge: 256, releasedClaims: MAX_RELEASED_CLAIMS,
|
|
36
|
+
knowledge: 256, releasedClaims: MAX_RELEASED_CLAIMS, removedBindings: MAX_REMOVED_BINDINGS,
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
39
|
* A write takes milliseconds, so a lock held for seconds belongs to a
|
|
@@ -56,6 +56,7 @@ function rowKey(name: Collection, item: unknown): string {
|
|
|
56
56
|
case "receipts": return row.capsuleHash ?? "";
|
|
57
57
|
case "migrations": return row.capsuleHashFrom ?? "";
|
|
58
58
|
case "releasedClaims": return row.claimId ?? "";
|
|
59
|
+
case "removedBindings": return [row.projectId, row.endpointId, row.repositoryId].join("\0");
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
invalidateMeshSessionHistory,
|
|
20
20
|
} from "../../mesh/runtime";
|
|
21
21
|
import { releaseClaimByPerson, releaseResult } from "../../mesh/admin";
|
|
22
|
+
import { handleMeshRepositoryRequest } from "../../mesh/repositories";
|
|
22
23
|
import { handleInvocationQuery } from "../../engine/invocation/query";
|
|
23
24
|
import { handleProjectKnowledgeQuery } from "../../mesh/knowledge/runtime-read";
|
|
24
25
|
import { applyPairingJoin } from "../../pairing";
|
|
@@ -132,6 +133,9 @@ export async function handleMonitorMessage(
|
|
|
132
133
|
return handleTaskTransferCommand(client, payload, () => { void publish().catch(() => {}); });
|
|
133
134
|
} else if (payload.type === "mesh.claim.release" && loadRuntimeConfig().meshEnabled) {
|
|
134
135
|
return handleInboundClaimRelease(client, payload, publish);
|
|
136
|
+
} else if (payload.type === "mesh.repository.query" || payload.type === "mesh.repository.edit") {
|
|
137
|
+
// Answers an edit with "mesh-disabled" when the Mesh is off; a query then goes unanswered.
|
|
138
|
+
return handleMeshRepositoryRequest(client, payload, input.peerPublicKey, () => publish());
|
|
135
139
|
}
|
|
136
140
|
return false;
|
|
137
141
|
}
|
|
@@ -30,6 +30,10 @@ type ClaudeParseState = ClaudeTurnClock & {
|
|
|
30
30
|
branch?: string;
|
|
31
31
|
model?: string;
|
|
32
32
|
title?: string;
|
|
33
|
+
/** The name the person gave the chat in Claude; the latest one counts. */
|
|
34
|
+
customTitle?: string;
|
|
35
|
+
/** The name Claude generated for the chat; the latest one counts. */
|
|
36
|
+
aiTitle?: string;
|
|
33
37
|
summary?: string;
|
|
34
38
|
startedAt: number;
|
|
35
39
|
lastActivityAt: number;
|
|
@@ -43,6 +47,12 @@ type ClaudeParseState = ClaudeTurnClock & {
|
|
|
43
47
|
turnEnded: boolean;
|
|
44
48
|
};
|
|
45
49
|
|
|
50
|
+
function claudeName(value: unknown): string | undefined {
|
|
51
|
+
if (typeof value !== "string") return undefined;
|
|
52
|
+
const name = value.replace(/\s+/g, " ").trim();
|
|
53
|
+
return name ? name.slice(0, 120) : undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
function applyClaudeLine(d: any, state: ClaudeParseState): void {
|
|
47
57
|
if (!claudeTranscriptRecord(d)) return;
|
|
48
58
|
observeClaudeTurn(d, state);
|
|
@@ -60,7 +70,8 @@ function applyClaudeLine(d: any, state: ClaudeParseState): void {
|
|
|
60
70
|
}
|
|
61
71
|
if (typeof d.gitBranch === "string" && d.gitBranch.trim()) state.branch = d.gitBranch;
|
|
62
72
|
}
|
|
63
|
-
if (d.type === "
|
|
73
|
+
if (d.type === "custom-title") state.customTitle = claudeName(d.customTitle) ?? state.customTitle;
|
|
74
|
+
if (d.type === "ai-title") state.aiTitle = claudeName(d.aiTitle ?? d.content) ?? state.aiTitle;
|
|
64
75
|
if (!state.title && (d.type === "user" || d.message?.role === "user")) {
|
|
65
76
|
const raw =
|
|
66
77
|
typeof d.message?.content === "string"
|
|
@@ -242,7 +253,8 @@ export function* parseClaudeFileSteps(file: string): Generator<void, ClaudeParse
|
|
|
242
253
|
const ownSession: SessionInfo = {
|
|
243
254
|
sessionId: state.sessionId,
|
|
244
255
|
agent: "claude",
|
|
245
|
-
|
|
256
|
+
// The chat keeps the name Claude shows for it: the person's, then Claude's, then the first message.
|
|
257
|
+
title: state.customTitle ?? state.aiTitle ?? state.title,
|
|
246
258
|
cwd: state.cwd,
|
|
247
259
|
worktree: state.cwd ? claudeCheckout({ ...state, cwd: state.cwd }) : undefined,
|
|
248
260
|
branch: state.branch,
|
package/cursor-plugin/README.md
CHANGED
|
@@ -10,7 +10,7 @@ keeps each phone response tied to the exact originating chat and prompt.
|
|
|
10
10
|
Install the supported CLI on this computer, then run:
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
-
npm install -g granttap-mcp@0.8.
|
|
13
|
+
npm install -g granttap-mcp@0.8.180
|
|
14
14
|
granttap setup
|
|
15
15
|
granttap status
|
|
16
16
|
```
|
package/cursor-plugin/mcp.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"command": "node",
|
|
5
5
|
"args": [
|
|
6
6
|
"-e",
|
|
7
|
-
"\"use strict\";\n\n// Cursor may start this MCP from any cwd. Execute JavaScript entry points with\n// Node itself: Windows batch shims require shell quoting that differs by host.\nconst { spawn } = require(\"node:child_process\");\nconst { existsSync } = require(\"node:fs\");\nconst { delimiter, dirname, join } = require(\"node:path\");\n\nconst PACKAGE = \"granttap-mcp@0.8.
|
|
7
|
+
"\"use strict\";\n\n// Cursor may start this MCP from any cwd. Execute JavaScript entry points with\n// Node itself: Windows batch shims require shell quoting that differs by host.\nconst { spawn } = require(\"node:child_process\");\nconst { existsSync } = require(\"node:fs\");\nconst { delimiter, dirname, join } = require(\"node:path\");\n\nconst PACKAGE = \"granttap-mcp@0.8.180\";\nconst dryRun = process.env.GRANTTAP_BOOTSTRAP_DRY_RUN === \"1\";\nconst platform = dryRun && process.env.GRANTTAP_BOOTSTRAP_PLATFORM\n ? process.env.GRANTTAP_BOOTSTRAP_PLATFORM : process.platform;\nconst nodeRoot = dryRun && process.env.GRANTTAP_BOOTSTRAP_NODE_ROOT\n ? process.env.GRANTTAP_BOOTSTRAP_NODE_ROOT : dirname(process.execPath);\nconst pathRoots = (process.env.PATH || \"\").split(delimiter).filter(Boolean);\nconst appData = process.env.APPDATA;\nconst roots = [nodeRoot, ...pathRoots, ...(appData ? [join(appData, \"npm\")] : [])];\nconst first = (paths) => paths.find((path) => existsSync(path));\n\nfunction launch() {\n if (platform !== \"win32\") {\n const installed = first(roots.map((root) => join(root, \"granttap-mcp\")));\n if (installed) return { command: installed, args: [] };\n const npx = first(roots.map((root) => join(root, \"npx\"))) || \"npx\";\n return { command: npx, args: [\"-y\", PACKAGE] };\n }\n const installed = first(roots.map((root) =>\n join(root, \"node_modules\", \"granttap-mcp\", \"bin\", \"granttap-mcp.mjs\")));\n if (installed) return { command: process.execPath, args: [installed] };\n const npx = first(roots.map((root) =>\n join(root, \"node_modules\", \"npm\", \"bin\", \"npx-cli.js\")));\n if (npx) return { command: process.execPath, args: [npx, \"-y\", PACKAGE] };\n throw new Error(\"Node.js/npm 22.13.0+ is required on this Windows device. Install npm and retry GrantTap.\");\n}\n\nlet target;\ntry { target = launch(); }\ncatch (error) {\n process.stderr.write(`[granttap] ${error.message}\\n`);\n process.exit(1);\n}\n\nif (dryRun) {\n process.stdout.write(JSON.stringify(target));\n process.exit(0);\n}\n\nconst child = spawn(target.command, target.args, { stdio: \"inherit\", windowsHide: true });\nchild.on(\"error\", (error) => {\n process.stderr.write(`[granttap] ${error.message}\\n`);\n process.exit(1);\n});\nchild.on(\"exit\", (code, signal) => {\n if (signal && platform !== \"win32\") {\n try { process.kill(process.pid, signal); } catch { process.exit(code ?? 1); }\n return;\n }\n process.exit(code ?? 1);\n});\n"
|
|
8
8
|
]
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -7,7 +7,7 @@ const { spawn } = require("node:child_process");
|
|
|
7
7
|
const { existsSync } = require("node:fs");
|
|
8
8
|
const { delimiter, dirname, join } = require("node:path");
|
|
9
9
|
|
|
10
|
-
const PACKAGE = "granttap-mcp@0.8.
|
|
10
|
+
const PACKAGE = "granttap-mcp@0.8.180";
|
|
11
11
|
const dryRun = process.env.GRANTTAP_BOOTSTRAP_DRY_RUN === "1";
|
|
12
12
|
const platform = dryRun && process.env.GRANTTAP_BOOTSTRAP_PLATFORM
|
|
13
13
|
? process.env.GRANTTAP_BOOTSTRAP_PLATFORM : process.platform;
|
package/package.json
CHANGED
|
@@ -25,6 +25,12 @@ computer for another one-time controller credential. The reply is sealed only
|
|
|
25
25
|
to the requester. It is device-network pairing, not Project membership.
|
|
26
26
|
`mesh/knowledge/write.ts` carries a Task-bound human decision or correction and a
|
|
27
27
|
separate Engine-confirmed result.
|
|
28
|
+
`mesh/repositories/index.ts` carries `mesh.repository.query` and its
|
|
29
|
+
`mesh.repository.list` of a computer's checkouts (at most 200, bound ones
|
|
30
|
+
first), and `mesh.repository.edit` (`add` a checkout by absolute path,
|
|
31
|
+
`remove` one of the computer's bindings by id) with its
|
|
32
|
+
`mesh.repository.edit.result`. Each is Project-scoped (`sessionId` is the
|
|
33
|
+
`projectId`); a refusal always names its reason.
|
|
28
34
|
|
|
29
35
|
`sign-in/index.ts` carries a browser sign-in done on the phone: `signin.request`
|
|
30
36
|
names an https page, the service, and optionally the loopback port a command
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The repositories a Mesh holds on one computer, read and changed from the
|
|
3
|
+
* phone. A computer lists the checkouts it knows and answers for its own
|
|
4
|
+
* bindings only: it adds one of its checkouts to the Mesh, or takes one of
|
|
5
|
+
* its own out. Every message is scoped to the Project and sent under the
|
|
6
|
+
* Project's key.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { Identifier, Label, Path } from "../endpoint";
|
|
10
|
+
|
|
11
|
+
/** A path that names its own root: POSIX, a drive letter, or a UNC share. */
|
|
12
|
+
export const MeshRepositoryPath = Path.refine(
|
|
13
|
+
(value) => value.startsWith("/") || /^[A-Za-z]:[\\/]/.test(value) || value.startsWith("\\\\"),
|
|
14
|
+
"absolute path required",
|
|
15
|
+
);
|
|
16
|
+
const RepositoryId = z.string().trim().min(1).max(512);
|
|
17
|
+
const Moment = z.number().nonnegative();
|
|
18
|
+
|
|
19
|
+
export const MESH_REPOSITORY_LIST_LIMIT = 200;
|
|
20
|
+
export const MESH_REPOSITORY_DETAIL_LIMIT = 300;
|
|
21
|
+
|
|
22
|
+
function projectScope(value: { sessionId: string; projectId: string }, ctx: z.RefinementCtx): void {
|
|
23
|
+
if (value.sessionId !== value.projectId) {
|
|
24
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["sessionId"], message: "project scope mismatch" });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The phone asks one computer which checkouts it could bind to the Project, and which it has. */
|
|
29
|
+
export const MeshRepositoryQuery = z.object({
|
|
30
|
+
type: z.literal("mesh.repository.query"),
|
|
31
|
+
sessionId: Identifier,
|
|
32
|
+
projectId: Identifier,
|
|
33
|
+
requestId: Identifier,
|
|
34
|
+
createdAt: Moment,
|
|
35
|
+
}).strict().superRefine(projectScope);
|
|
36
|
+
export type MeshRepositoryQuery = z.infer<typeof MeshRepositoryQuery>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* One checkout on the answering computer. `boundHere` says the repository is
|
|
40
|
+
* bound to the asking Project on this computer, under `bindingId`; a checkout
|
|
41
|
+
* bound to another Project on this computer names that Project instead.
|
|
42
|
+
*/
|
|
43
|
+
export const MeshRepositoryCandidate = z.object({
|
|
44
|
+
path: MeshRepositoryPath,
|
|
45
|
+
name: Label,
|
|
46
|
+
repositoryId: RepositoryId,
|
|
47
|
+
boundHere: z.boolean(),
|
|
48
|
+
bindingId: Identifier.optional(),
|
|
49
|
+
otherProjectId: Identifier.optional(),
|
|
50
|
+
otherProjectName: Label.optional(),
|
|
51
|
+
}).strict().superRefine((value, ctx) => {
|
|
52
|
+
if (value.boundHere !== (value.bindingId != null)) {
|
|
53
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["bindingId"], message: "a binding id names a binding here" });
|
|
54
|
+
}
|
|
55
|
+
if (value.boundHere && value.otherProjectId != null) {
|
|
56
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["otherProjectId"], message: "bound here and elsewhere" });
|
|
57
|
+
}
|
|
58
|
+
if (value.otherProjectName != null && value.otherProjectId == null) {
|
|
59
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["otherProjectName"], message: "a name without its Project" });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
export type MeshRepositoryCandidate = z.infer<typeof MeshRepositoryCandidate>;
|
|
63
|
+
|
|
64
|
+
/** The answer to a query: bound checkouts first, then the rest by name. */
|
|
65
|
+
export const MeshRepositoryList = z.object({
|
|
66
|
+
type: z.literal("mesh.repository.list"),
|
|
67
|
+
sessionId: Identifier,
|
|
68
|
+
projectId: Identifier,
|
|
69
|
+
requestId: Identifier,
|
|
70
|
+
computerId: Identifier,
|
|
71
|
+
repositories: z.array(MeshRepositoryCandidate).max(MESH_REPOSITORY_LIST_LIMIT),
|
|
72
|
+
generatedAt: Moment,
|
|
73
|
+
}).strict().superRefine((value, ctx) => {
|
|
74
|
+
projectScope(value, ctx);
|
|
75
|
+
if (new Set(value.repositories.map((item) => item.path)).size !== value.repositories.length) {
|
|
76
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["repositories"], message: "duplicate checkout path" });
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
export type MeshRepositoryList = z.infer<typeof MeshRepositoryList>;
|
|
80
|
+
|
|
81
|
+
export const MeshRepositoryEditAction = z.enum(["add", "remove"]);
|
|
82
|
+
export type MeshRepositoryEditAction = z.infer<typeof MeshRepositoryEditAction>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Add a checkout of this computer to the Project (`path`), or take one of
|
|
86
|
+
* this computer's bindings out of it (`bindingId`). The computer checks the
|
|
87
|
+
* field the action needs and answers `invalid` when it is missing.
|
|
88
|
+
*/
|
|
89
|
+
export const MeshRepositoryEdit = z.object({
|
|
90
|
+
type: z.literal("mesh.repository.edit"),
|
|
91
|
+
sessionId: Identifier,
|
|
92
|
+
projectId: Identifier,
|
|
93
|
+
requestId: Identifier,
|
|
94
|
+
createdAt: Moment,
|
|
95
|
+
action: MeshRepositoryEditAction,
|
|
96
|
+
path: Path.optional(),
|
|
97
|
+
bindingId: Identifier.optional(),
|
|
98
|
+
}).strict().superRefine(projectScope);
|
|
99
|
+
export type MeshRepositoryEdit = z.infer<typeof MeshRepositoryEdit>;
|
|
100
|
+
|
|
101
|
+
export const MeshRepositoryEditReason = z.enum([
|
|
102
|
+
"invalid", "mesh-disabled", "unknown-mesh", "not-found", "not-a-repository",
|
|
103
|
+
"already-bound", "bound-elsewhere", "not-this-computer", "last-repository", "failed",
|
|
104
|
+
]);
|
|
105
|
+
export type MeshRepositoryEditReason = z.infer<typeof MeshRepositoryEditReason>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* What became of an edit. A refusal says why; a success may still carry
|
|
109
|
+
* `already-bound`, when the repository was in the Project before the request.
|
|
110
|
+
*/
|
|
111
|
+
export const MeshRepositoryEditResult = z.object({
|
|
112
|
+
type: z.literal("mesh.repository.edit.result"),
|
|
113
|
+
sessionId: Identifier,
|
|
114
|
+
projectId: Identifier,
|
|
115
|
+
requestId: Identifier,
|
|
116
|
+
action: MeshRepositoryEditAction,
|
|
117
|
+
ok: z.boolean(),
|
|
118
|
+
reason: MeshRepositoryEditReason.optional(),
|
|
119
|
+
detail: z.string().trim().min(1).max(MESH_REPOSITORY_DETAIL_LIMIT).optional(),
|
|
120
|
+
bindingId: Identifier.optional(),
|
|
121
|
+
generatedAt: Moment,
|
|
122
|
+
}).strict().superRefine((value, ctx) => {
|
|
123
|
+
projectScope(value, ctx);
|
|
124
|
+
if (!value.ok && value.reason == null) {
|
|
125
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["reason"], message: "a refusal says why" });
|
|
126
|
+
}
|
|
127
|
+
if (value.ok && value.reason != null && value.reason !== "already-bound") {
|
|
128
|
+
ctx.addIssue({ code: z.ZodIssueCode.custom, path: ["reason"], message: "a success carries no refusal" });
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
export type MeshRepositoryEditResult = z.infer<typeof MeshRepositoryEditResult>;
|
|
@@ -45,6 +45,10 @@ import {
|
|
|
45
45
|
MeshClaimRelease,
|
|
46
46
|
MeshClaimReleaseResult,
|
|
47
47
|
MeshHandoffPrepare,
|
|
48
|
+
MeshRepositoryEdit,
|
|
49
|
+
MeshRepositoryEditResult,
|
|
50
|
+
MeshRepositoryList,
|
|
51
|
+
MeshRepositoryQuery,
|
|
48
52
|
MeshSnapshot,
|
|
49
53
|
ProjectCapabilityRequestSet,
|
|
50
54
|
} from "./messages/mesh";
|
|
@@ -184,6 +188,10 @@ export const Payload = z.union([
|
|
|
184
188
|
MeshEvent,
|
|
185
189
|
MeshClaimRelease,
|
|
186
190
|
MeshClaimReleaseResult,
|
|
191
|
+
MeshRepositoryQuery,
|
|
192
|
+
MeshRepositoryList,
|
|
193
|
+
MeshRepositoryEdit,
|
|
194
|
+
MeshRepositoryEditResult,
|
|
187
195
|
MeshHandoffPrepare,
|
|
188
196
|
MeshSnapshot,
|
|
189
197
|
ProjectCapabilityRequestSet,
|