@agentshouse/kit 0.2.1-cd646adba3f64 → 0.2.1-cdc381ebf021f
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 +42 -48
- package/dist/acp.js +102 -108
- package/dist/afk.js +17 -0
- package/dist/agents.js +227 -68
- package/dist/api.js +19 -10
- package/dist/app-git.js +10 -26
- package/dist/bridge.js +18 -47
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +49 -0
- package/dist/clis.js +157 -100
- package/dist/codex-main.js +58 -0
- package/dist/connect.js +108 -0
- package/dist/connection.js +120 -0
- package/dist/content.js +106 -0
- package/dist/conversations.js +815 -335
- package/dist/copies.js +439 -232
- package/dist/earlier.js +263 -0
- package/dist/end.js +23 -5
- package/dist/events.js +793 -0
- package/dist/files.js +139 -17
- package/dist/git.js +57 -21
- package/dist/grok.js +39 -0
- package/dist/home.js +122 -8
- package/dist/house-cli.js +359 -0
- package/dist/house-main.js +7 -159
- package/dist/instructions.js +7 -11
- package/dist/kit-cli.js +78 -0
- package/dist/kit-main.js +8 -22
- package/dist/login.js +132 -107
- package/dist/logout.js +15 -17
- package/dist/mcp.js +6 -2
- package/dist/owner.js +46 -0
- package/dist/placement.js +25 -0
- package/dist/relay.js +33 -2
- package/dist/resident.js +160 -58
- package/dist/scope.js +214 -0
- package/dist/scripts.js +303 -0
- package/dist/secret-input.js +1 -1
- package/dist/settings.js +188 -0
- package/dist/sign-in.js +40 -33
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +90 -47
- package/dist/translate.js +19 -16
- package/dist/update.js +119 -102
- package/dist/wire.js +32 -0
- package/dist/work.js +353 -0
- package/dist/workspace.js +103 -0
- package/package.json +25 -21
- package/dist/authority-main.js +0 -22
- package/dist/blocks.js +0 -51
- package/dist/bootstrap.json +0 -24
- package/dist/clis-main.js +0 -23
- package/dist/configure-main.js +0 -6
- package/dist/enrol-main.js +0 -4
- package/dist/stream.js +0 -72
- package/how-we-work.md +0 -23
- package/skills/ask-matt/LICENSE +0 -21
- package/skills/ask-matt/PHASE-BOUNDARIES.md +0 -55
- package/skills/ask-matt/SKILL.md +0 -91
- package/skills/ask-matt/agents/openai.yaml +0 -4
- package/skills/code-review/LICENSE +0 -21
- package/skills/code-review/SKILL.md +0 -89
- package/skills/code-review/agents/openai.yaml +0 -3
- package/skills/codebase-design/DEEPENING.md +0 -37
- package/skills/codebase-design/DESIGN-IT-TWICE.md +0 -44
- package/skills/codebase-design/LICENSE +0 -21
- package/skills/codebase-design/SKILL.md +0 -116
- package/skills/codebase-design/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/LICENSE +0 -21
- package/skills/diagnosing-bugs/SKILL.md +0 -140
- package/skills/diagnosing-bugs/agents/openai.yaml +0 -3
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +0 -44
- package/skills/domain-modeling/ADR-FORMAT.md +0 -47
- package/skills/domain-modeling/CONTEXT-FORMAT.md +0 -60
- package/skills/domain-modeling/LICENSE +0 -21
- package/skills/domain-modeling/SKILL.md +0 -76
- package/skills/domain-modeling/agents/openai.yaml +0 -3
- package/skills/grill-me/LICENSE +0 -21
- package/skills/grill-me/SKILL.md +0 -8
- package/skills/grill-me/agents/openai.yaml +0 -4
- package/skills/grill-with-docs/LICENSE +0 -21
- package/skills/grill-with-docs/SKILL.md +0 -8
- package/skills/grill-with-docs/agents/openai.yaml +0 -4
- package/skills/grilling/LICENSE +0 -21
- package/skills/grilling/SKILL.md +0 -30
- package/skills/grilling/agents/openai.yaml +0 -3
- package/skills/handoff/LICENSE +0 -21
- package/skills/handoff/SKILL.md +0 -17
- package/skills/handoff/agents/openai.yaml +0 -4
- package/skills/implement/LICENSE +0 -21
- package/skills/implement/SKILL.md +0 -16
- package/skills/implement/agents/openai.yaml +0 -4
- package/skills/improve-codebase-architecture/HTML-REPORT.md +0 -123
- package/skills/improve-codebase-architecture/LICENSE +0 -21
- package/skills/improve-codebase-architecture/SKILL.md +0 -72
- package/skills/improve-codebase-architecture/agents/openai.yaml +0 -4
- package/skills/prototype/LICENSE +0 -21
- package/skills/prototype/LOGIC.md +0 -67
- package/skills/prototype/SKILL.md +0 -28
- package/skills/prototype/UI.md +0 -112
- package/skills/prototype/agents/openai.yaml +0 -3
- package/skills/research/LICENSE +0 -21
- package/skills/research/SKILL.md +0 -14
- package/skills/research/agents/openai.yaml +0 -3
- package/skills/resolving-merge-conflicts/LICENSE +0 -21
- package/skills/resolving-merge-conflicts/SKILL.md +0 -16
- package/skills/resolving-merge-conflicts/agents/openai.yaml +0 -3
- package/skills/tdd/LICENSE +0 -21
- package/skills/tdd/SKILL.md +0 -40
- package/skills/tdd/agents/openai.yaml +0 -3
- package/skills/tdd/mocking.md +0 -59
- package/skills/tdd/tests.md +0 -77
- package/skills/teach/GLOSSARY-FORMAT.md +0 -35
- package/skills/teach/LEARNING-RECORD-FORMAT.md +0 -46
- package/skills/teach/LICENSE +0 -21
- package/skills/teach/MISSION-FORMAT.md +0 -31
- package/skills/teach/RESOURCES-FORMAT.md +0 -32
- package/skills/teach/SKILL.md +0 -141
- package/skills/teach/agents/openai.yaml +0 -4
- package/skills/to-questionnaire/LICENSE +0 -21
- package/skills/to-questionnaire/SKILL.md +0 -55
- package/skills/to-questionnaire/agents/openai.yaml +0 -4
- package/skills/to-spec/LICENSE +0 -21
- package/skills/to-spec/SKILL.md +0 -76
- package/skills/to-spec/agents/openai.yaml +0 -4
- package/skills/to-tickets/LICENSE +0 -21
- package/skills/to-tickets/SKILL.md +0 -106
- package/skills/to-tickets/agents/openai.yaml +0 -4
- package/skills/wait-what/LICENSE +0 -21
- package/skills/wait-what/SKILL.md +0 -8
- package/skills/wait-what/agents/openai.yaml +0 -4
- package/skills/wayfinder/LICENSE +0 -21
- package/skills/wayfinder/SKILL.md +0 -129
- package/skills/wayfinder/agents/openai.yaml +0 -4
- package/skills/writing-for-agents/LICENSE +0 -21
- package/skills/writing-for-agents/SKILL-MECHANICS.md +0 -22
- package/skills/writing-for-agents/SKILL.md +0 -83
- package/skills/writing-for-agents/agents/openai.yaml +0 -3
package/dist/copies.js
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { randomUUID } from 'node:crypto';
|
|
1
|
+
import { HOUSE_ROOM_TYPES, readTypes } from '@agentshouse/mdmodel';
|
|
2
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
3
3
|
import { mkdir, readFile, readdir, realpath, rename, rm, rmdir, stat, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { finalRefusal, HouseRefusal, retrying } from './api.js';
|
|
6
|
-
import {
|
|
6
|
+
import { chunkTexts, stagedChunks } from './chunks.js';
|
|
7
|
+
import { blobId, blobText, git, isText, HOUSE_REF, importCommits, localCopies, revision, run, succeeded, tree, } from './git.js';
|
|
8
|
+
import { paused } from './files.js';
|
|
7
9
|
import { kitHome } from './home.js';
|
|
8
10
|
import { operationId } from './operation.js';
|
|
9
11
|
import { refusalOf } from './refusals.js';
|
|
10
|
-
import { changed } from './translate.js';
|
|
11
|
-
import { relayed } from './relay.js';
|
|
12
|
+
import { changed, readDocument } from './translate.js';
|
|
12
13
|
const BRANCH = 'main';
|
|
13
14
|
const PROVENANCE = '_provenance';
|
|
14
|
-
const IDENTITY = { GIT_COMMITTER_NAME: '
|
|
15
|
+
const IDENTITY = { GIT_COMMITTER_NAME: 'Kit', GIT_COMMITTER_EMAIL: 'house-kit@localhost' };
|
|
16
|
+
const ROOMS = 'rooms/';
|
|
17
|
+
const NOT_READY = 'not ready yet; Kit copies it once House has built it';
|
|
18
|
+
const STAGED_CHUNKS = 'house-chunks';
|
|
19
|
+
const SCHEMA = 'settings/schema.yaml';
|
|
20
|
+
// A Room answered not ready is asked again on this schedule: its chunk build usually catches up within seconds, so the first asks come soon and the last repeats until it does.
|
|
21
|
+
const ASKED_AGAIN_MS = [1000, 2000, 3000, 5000, 8000, 11_000, 15_000];
|
|
22
|
+
class NotReady extends Error {
|
|
23
|
+
rooms;
|
|
24
|
+
constructor(rooms) {
|
|
25
|
+
super(NOT_READY);
|
|
26
|
+
this.rooms = rooms;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
15
29
|
function causeOf(error) {
|
|
16
30
|
return error instanceof Error ? error.message : String(error);
|
|
17
31
|
}
|
|
32
|
+
function houseCause(error) {
|
|
33
|
+
return error instanceof HouseRefusal ? (refusalOf(error.text)?.text ?? causeOf(error)) : causeOf(error);
|
|
34
|
+
}
|
|
18
35
|
function logged(error) {
|
|
19
36
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
20
37
|
}
|
|
@@ -29,9 +46,35 @@ const REBASED = new Set([
|
|
|
29
46
|
function rebaseFixes(refusal) {
|
|
30
47
|
return refusal.code === 'edit_conflict' && refusal.conflicts.some((code) => REBASED.has(code));
|
|
31
48
|
}
|
|
49
|
+
function textOnly(paths) {
|
|
50
|
+
const [named, them] = paths.length === 1 ? [`${paths[0]} is`, 'it'] : [`${paths.join(', ')} are`, 'them'];
|
|
51
|
+
return `${named} not text, and house push sends text only; remove ${them} from the commit and place ${them} with house upload`;
|
|
52
|
+
}
|
|
53
|
+
function outside(path) {
|
|
54
|
+
return { refused: true, text: `${path} is not a House Local copy; run house push inside one` };
|
|
55
|
+
}
|
|
32
56
|
function short(commit) {
|
|
33
57
|
return commit.slice(0, 12);
|
|
34
58
|
}
|
|
59
|
+
function moved(before, after) {
|
|
60
|
+
if (before.house !== after.house)
|
|
61
|
+
return [`${rootOf(after.room_handle)}: ${HOUSE_REF} is at ${short(after.house)}`];
|
|
62
|
+
return before.position === after.position ? [] : [`${rootOf(after.room_handle)}: read-only files refreshed`];
|
|
63
|
+
}
|
|
64
|
+
function expiredAuthority(error) {
|
|
65
|
+
if (!(error instanceof HouseRefusal))
|
|
66
|
+
return undefined;
|
|
67
|
+
try {
|
|
68
|
+
const { error: refused } = JSON.parse(error.text);
|
|
69
|
+
return refused?.code === 'expired' && typeof refused.authority === 'string' ? refused.authority : undefined;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function grouped(items, size) {
|
|
76
|
+
return items.flatMap((_, index) => (index % size === 0 ? [items.slice(index, index + size)] : []));
|
|
77
|
+
}
|
|
35
78
|
function covers(path, prefix) {
|
|
36
79
|
return prefix === '' || path === prefix || path.startsWith(`${prefix}/`);
|
|
37
80
|
}
|
|
@@ -40,6 +83,12 @@ function sidecar(path) {
|
|
|
40
83
|
segments.splice(-1, 0, PROVENANCE);
|
|
41
84
|
return segments.join('/');
|
|
42
85
|
}
|
|
86
|
+
function recordOf(key) {
|
|
87
|
+
return join(kitHome(), 'local-copies', `${key}.json`);
|
|
88
|
+
}
|
|
89
|
+
function stagingPrefix() {
|
|
90
|
+
return `.${createHash('sha256').update(kitHome()).digest('hex').slice(0, 16)}-`;
|
|
91
|
+
}
|
|
43
92
|
function rootOf(handle) {
|
|
44
93
|
return `/rooms/${handle}`;
|
|
45
94
|
}
|
|
@@ -67,32 +116,59 @@ async function removeFile(repository, path) {
|
|
|
67
116
|
return;
|
|
68
117
|
}
|
|
69
118
|
}
|
|
70
|
-
async function
|
|
119
|
+
async function readOnlyFiles(repository, held) {
|
|
71
120
|
const tracked = new Set((await git(repository, ['ls-files', '-z'])).split('\0'));
|
|
72
121
|
const holding = new Set(held);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
122
|
+
return {
|
|
123
|
+
remove: async (path) => {
|
|
124
|
+
if (!holding.has(path))
|
|
125
|
+
return;
|
|
126
|
+
if (!tracked.has(path))
|
|
127
|
+
await removeFile(repository, path);
|
|
128
|
+
holding.delete(path);
|
|
129
|
+
},
|
|
130
|
+
place: async (path, content) => {
|
|
131
|
+
if (tracked.has(path))
|
|
132
|
+
return;
|
|
133
|
+
if (!holding.has(path) && (await exists(join(repository, path))))
|
|
134
|
+
return;
|
|
135
|
+
await writeText(join(repository, path), content);
|
|
136
|
+
holding.add(path);
|
|
137
|
+
},
|
|
138
|
+
held: () => [...holding].sort(),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async function readOnlyPlaced(repository, held, written, removed) {
|
|
142
|
+
const files = await readOnlyFiles(repository, held);
|
|
143
|
+
for (const path of removed)
|
|
144
|
+
await files.remove(path);
|
|
145
|
+
for (const [path, content] of written)
|
|
146
|
+
await files.place(path, content);
|
|
147
|
+
return files.held();
|
|
148
|
+
}
|
|
149
|
+
async function importedWhole(repository, scope, texts, commit, readOnly) {
|
|
150
|
+
const revisions = {};
|
|
151
|
+
async function* tracked() {
|
|
152
|
+
for await (const { path, content, revision: held, provenance } of texts) {
|
|
153
|
+
if (declaredWritable(path, scope)) {
|
|
154
|
+
revisions[path] = held;
|
|
155
|
+
yield [path, content];
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
await readOnly.place(path, content);
|
|
159
|
+
}
|
|
160
|
+
if (provenance !== undefined)
|
|
161
|
+
await readOnly.place(sidecar(path), provenance);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { house: await importCommits(repository, [{ ...commit, files: tracked() }]), revisions };
|
|
89
165
|
}
|
|
90
166
|
async function ruled(path, rules) {
|
|
91
167
|
if ((await readFile(path, 'utf8').catch(() => null)) !== rules)
|
|
92
168
|
await writeFile(path, rules);
|
|
93
169
|
}
|
|
94
170
|
async function ignoreRules(repository, writable, copy) {
|
|
95
|
-
const readOnly =
|
|
171
|
+
const readOnly = copy.read_only.filter((path) => !path.split('/').includes(PROVENANCE));
|
|
96
172
|
const protectedPath = (path) => copy.protected.some((prefix) => prefix !== '' && covers(path, prefix));
|
|
97
173
|
const whole = copy.protected.filter((prefix) => prefix !== '' && !writable.some((path) => covers(path, prefix)));
|
|
98
174
|
const house = [
|
|
@@ -101,7 +177,7 @@ async function ignoreRules(repository, writable, copy) {
|
|
|
101
177
|
].map(pattern);
|
|
102
178
|
const granted = readOnly.filter((path) => !protectedPath(path)).map(pattern);
|
|
103
179
|
await ruled(join(repository, '.gitignore'), [
|
|
104
|
-
'#
|
|
180
|
+
'# Kit writes this file and .ignore. The paths below are read-only House',
|
|
105
181
|
'# content: Git does not track them, and House refuses a change to them even',
|
|
106
182
|
'# when this file is edited or a path is force-added.',
|
|
107
183
|
'/.gitignore',
|
|
@@ -116,13 +192,19 @@ async function ignoreRules(repository, writable, copy) {
|
|
|
116
192
|
'',
|
|
117
193
|
].join('\n'));
|
|
118
194
|
await ruled(join(repository, '.ignore'), [
|
|
119
|
-
'#
|
|
195
|
+
'# Kit writes this file so native search still reads the read-only House',
|
|
120
196
|
'# content that .gitignore keeps out of Git.',
|
|
121
197
|
`!${PROVENANCE}`,
|
|
122
198
|
...[...house, ...granted].map((rule) => `!${rule}`),
|
|
123
199
|
'',
|
|
124
200
|
].join('\n'));
|
|
125
201
|
}
|
|
202
|
+
async function modelOf(copy, files) {
|
|
203
|
+
const entry = files.get(SCHEMA);
|
|
204
|
+
if (entry !== undefined)
|
|
205
|
+
return readTypes(await blobText(copy.repository, entry), HOUSE_ROOM_TYPES);
|
|
206
|
+
return readTypes(copy.read_only.includes(SCHEMA) ? await readFile(join(copy.repository, SCHEMA), 'utf8') : '', HOUSE_ROOM_TYPES);
|
|
207
|
+
}
|
|
126
208
|
function revisionAt(copy, commit, path) {
|
|
127
209
|
let manifest = copy.manifests[commit];
|
|
128
210
|
while (manifest !== undefined) {
|
|
@@ -152,15 +234,15 @@ export class LocalCopies {
|
|
|
152
234
|
house;
|
|
153
235
|
copies = new Map();
|
|
154
236
|
queues = new Map();
|
|
155
|
-
|
|
156
|
-
|
|
237
|
+
waiting = new Set();
|
|
238
|
+
answering = Promise.resolve();
|
|
157
239
|
constructor(house) {
|
|
158
240
|
this.house = house;
|
|
159
241
|
this.owner = {
|
|
160
242
|
key: 'owner',
|
|
161
243
|
submit: async (operation, changes) => {
|
|
162
244
|
try {
|
|
163
|
-
const outcome = await retrying(() => house.
|
|
245
|
+
const outcome = await retrying(() => house.door('files/batch', { operation_id: operation, changes }));
|
|
164
246
|
return { accepted: outcome.contents };
|
|
165
247
|
}
|
|
166
248
|
catch (error) {
|
|
@@ -184,43 +266,115 @@ export class LocalCopies {
|
|
|
184
266
|
this.copies.set(copy.key, copy);
|
|
185
267
|
}
|
|
186
268
|
}
|
|
187
|
-
async
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
269
|
+
async swept() {
|
|
270
|
+
const rooms = join(localCopies(), 'rooms');
|
|
271
|
+
for (const name of await readdir(rooms).catch(() => [])) {
|
|
272
|
+
if (name.startsWith(stagingPrefix()))
|
|
273
|
+
await rm(join(rooms, name), { recursive: true, force: true });
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
connected() {
|
|
277
|
+
return this.selected();
|
|
278
|
+
}
|
|
279
|
+
fetch() {
|
|
280
|
+
return this.answered(() => this.fetched(true));
|
|
281
|
+
}
|
|
282
|
+
async selected() {
|
|
283
|
+
const copied = await this.answered(() => this.fetched(false));
|
|
284
|
+
if (copied.refused)
|
|
285
|
+
logged(copied.text);
|
|
286
|
+
}
|
|
287
|
+
answered(work) {
|
|
288
|
+
const answered = this.answering.then(work);
|
|
289
|
+
this.answering = answered.catch(() => undefined);
|
|
290
|
+
return answered;
|
|
291
|
+
}
|
|
292
|
+
async fetched(refreshing) {
|
|
293
|
+
const { local_copy: answer } = await this.house.act('local-copies/selection/read', {});
|
|
294
|
+
const synced = new Map(answer.rooms.map((room) => [`${ROOMS}${room.room_ref}`, room.room_handle]));
|
|
295
|
+
return this.holding([...new Set([...this.copies.keys(), ...synced.keys()])].sort(), async () => {
|
|
296
|
+
const said = [];
|
|
297
|
+
let refused = false;
|
|
298
|
+
const mark = refreshing ? 'said' : 'unsaid';
|
|
299
|
+
for (const copy of [...this.copies.values()]) {
|
|
300
|
+
if (synced.has(copy.key) || copy.unfollowed === 'said' || copy.unfollowed === mark)
|
|
301
|
+
continue;
|
|
302
|
+
await this.save({ ...copy, unfollowed: mark });
|
|
303
|
+
if (refreshing)
|
|
304
|
+
said.push(`${rootOf(copy.room_handle)}: no longer followed; kept as it is`);
|
|
305
|
+
}
|
|
306
|
+
const current = [];
|
|
307
|
+
const wanted = new Map();
|
|
308
|
+
for (const [key, handle] of synced) {
|
|
309
|
+
try {
|
|
310
|
+
const held = this.copies.get(key);
|
|
311
|
+
if (held === undefined || !(await exists(held.repository))) {
|
|
312
|
+
wanted.set(key, handle);
|
|
313
|
+
continue;
|
|
314
|
+
}
|
|
315
|
+
const { unfollowed, ...followed } = held;
|
|
316
|
+
current.push(unfollowed === undefined && held.room_handle === handle ? held : await this.save({ ...followed, room_handle: handle }));
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
refused = true;
|
|
320
|
+
said.push(`${rootOf(handle)}: ${causeOf(error)}`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const unready = [];
|
|
324
|
+
const unsettled = [];
|
|
325
|
+
if (wanted.size > 0) {
|
|
326
|
+
const { authorities } = await this.discovered([...wanted.values()]);
|
|
327
|
+
for (const [key, handle] of wanted) {
|
|
328
|
+
const authority = authorities.find((entry) => `${ROOMS}${entry.room_ref}` === key);
|
|
329
|
+
try {
|
|
330
|
+
if (authority === undefined)
|
|
331
|
+
throw new Error('House serves nothing of it to copy');
|
|
332
|
+
said.push(await this.copied({ key, handle, authority }));
|
|
333
|
+
}
|
|
334
|
+
catch (error) {
|
|
335
|
+
if (error instanceof NotReady) {
|
|
336
|
+
unready.push(...error.rooms);
|
|
337
|
+
said.push(`${rootOf(handle)}: ${NOT_READY}`);
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
refused = true;
|
|
341
|
+
unsettled.push(key.slice(ROOMS.length));
|
|
342
|
+
said.push(`${rootOf(handle)}: ${causeOf(error)}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const reading = refreshing ? current : current.filter((copy) => this.waiting.has(copy.room_ref));
|
|
348
|
+
if (reading.length > 0) {
|
|
349
|
+
const failed = await this.refreshed(reading, unready).then(() => null, houseCause);
|
|
350
|
+
for (const copy of reading) {
|
|
351
|
+
said.push(...(unready.includes(copy.room_ref) ? [`${rootOf(copy.room_handle)}: ${NOT_READY}`] : moved(copy, this.copies.get(copy.key))));
|
|
352
|
+
}
|
|
353
|
+
if (failed !== null) {
|
|
354
|
+
refused = true;
|
|
355
|
+
unsettled.push(...reading.map((copy) => copy.room_ref));
|
|
356
|
+
said.push(failed);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
for (const room of [...this.waiting]) {
|
|
360
|
+
if (!unready.includes(room) && !unsettled.includes(room))
|
|
361
|
+
this.waiting.delete(room);
|
|
362
|
+
}
|
|
363
|
+
const due = unready.filter((room) => !this.waiting.has(room));
|
|
364
|
+
for (const room of due)
|
|
365
|
+
this.waiting.add(room);
|
|
366
|
+
if (due.length > 0)
|
|
367
|
+
void this.askedAgain(due);
|
|
368
|
+
return { refused, text: said.length === 0 ? 'Nothing new from House.' : said.join('\n') };
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
async askedAgain(rooms) {
|
|
372
|
+
let asking = rooms;
|
|
373
|
+
for (let step = 0; asking.length > 0; step++) {
|
|
374
|
+
await paused(ASKED_AGAIN_MS[Math.min(step, ASKED_AGAIN_MS.length - 1)]);
|
|
375
|
+
await this.selected().catch(logged);
|
|
376
|
+
asking = asking.filter((room) => this.waiting.has(room));
|
|
377
|
+
}
|
|
224
378
|
}
|
|
225
379
|
async observed(report) {
|
|
226
380
|
const key = await this.keyAt(dirname(report.common));
|
|
@@ -250,11 +404,11 @@ export class LocalCopies {
|
|
|
250
404
|
async push(cwd, selector, caller) {
|
|
251
405
|
const located = await run(cwd, ['rev-parse', '--path-format=absolute', '--git-common-dir', '--show-toplevel']);
|
|
252
406
|
if (located.status !== 0)
|
|
253
|
-
return
|
|
407
|
+
return outside(cwd);
|
|
254
408
|
const [common, worktree] = located.stdout.toString('utf8').split('\n');
|
|
255
409
|
const key = await this.keyAt(dirname(common));
|
|
256
410
|
if (key === undefined)
|
|
257
|
-
return
|
|
411
|
+
return outside(worktree);
|
|
258
412
|
return this.exclusive(key, () => this.pushed(key, worktree, selector, caller));
|
|
259
413
|
}
|
|
260
414
|
async keyAt(repository) {
|
|
@@ -270,19 +424,12 @@ export class LocalCopies {
|
|
|
270
424
|
this.queues.set(key, queued.catch(() => undefined));
|
|
271
425
|
return queued;
|
|
272
426
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
this.delivering.add(key);
|
|
277
|
-
void this.exclusive(key, async () => {
|
|
278
|
-
this.delivering.delete(key);
|
|
279
|
-
const copy = this.copies.get(key);
|
|
280
|
-
if (copy.active)
|
|
281
|
-
await this.save(await this.caughtUp(copy));
|
|
282
|
-
}).catch(logged);
|
|
427
|
+
holding(keys, work) {
|
|
428
|
+
const [key, ...rest] = keys;
|
|
429
|
+
return key === undefined ? work() : this.exclusive(key, () => this.holding(rest, work));
|
|
283
430
|
}
|
|
284
431
|
async save(copy) {
|
|
285
|
-
const path =
|
|
432
|
+
const path = recordOf(copy.key);
|
|
286
433
|
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
287
434
|
const temporary = `${path}.${process.pid}`;
|
|
288
435
|
await writeFile(temporary, JSON.stringify(copy), { mode: 0o600 });
|
|
@@ -290,161 +437,210 @@ export class LocalCopies {
|
|
|
290
437
|
this.copies.set(copy.key, copy);
|
|
291
438
|
return copy;
|
|
292
439
|
}
|
|
293
|
-
async
|
|
294
|
-
const
|
|
295
|
-
const
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (view === undefined)
|
|
301
|
-
return null;
|
|
302
|
-
const authority = discovery.authorities.find((entry) => entry.room_ref === view.manifest.anchor);
|
|
303
|
-
const contents = new Map(view.contents.map((entry) => [entry.path, entry.content]));
|
|
304
|
-
const read = {
|
|
305
|
-
anchor: view.manifest.anchor,
|
|
306
|
-
position: view.manifest.position,
|
|
307
|
-
log_epoch: view.manifest.log_epoch,
|
|
308
|
-
write: authority.operations.write,
|
|
309
|
-
protected: authority.protected_paths,
|
|
310
|
-
writable: new Map(),
|
|
311
|
-
revisions: {},
|
|
312
|
-
readOnly: new Map(),
|
|
313
|
-
};
|
|
314
|
-
for (const file of view.manifest.files) {
|
|
315
|
-
const content = contents.get(file.path);
|
|
316
|
-
if (file.writable) {
|
|
317
|
-
read.writable.set(file.path, content);
|
|
318
|
-
read.revisions[file.path] = file.revision;
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
read.readOnly.set(file.path, content);
|
|
322
|
-
}
|
|
323
|
-
if (file.provenance !== undefined)
|
|
324
|
-
read.readOnly.set(sidecar(file.path), file.provenance);
|
|
325
|
-
}
|
|
326
|
-
return read;
|
|
440
|
+
async discovered(handles) {
|
|
441
|
+
const discover = (group) => this.house.door('rooms/discover', { prefixes: group.map(rootOf) });
|
|
442
|
+
const [first, ...rest] = handles;
|
|
443
|
+
const { bounds, authorities } = await discover([first]);
|
|
444
|
+
for (const group of grouped(rest, bounds.max_prefixes))
|
|
445
|
+
authorities.push(...(await discover(group)).authorities);
|
|
446
|
+
return { bounds, authorities };
|
|
327
447
|
}
|
|
328
|
-
async
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
await this.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
if (authority === undefined)
|
|
345
|
-
return;
|
|
346
|
-
if (authority.managed_replication !== 'admitted') {
|
|
347
|
-
logged(`operation_denied: ${rootOf(copy.room_handle)} is not synchronized to this Environment`);
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
if (JSON.stringify([authority.operations.write, authority.protected_paths]) !==
|
|
351
|
-
JSON.stringify([copy.write, copy.protected])) {
|
|
352
|
-
await this.save(await this.received(copy));
|
|
353
|
-
return;
|
|
448
|
+
async chunked(root, room, directory) {
|
|
449
|
+
await mkdir(directory, { recursive: true });
|
|
450
|
+
for (let renewed = false;; renewed = true) {
|
|
451
|
+
const { rooms } = await this.house.door('room-chunks/list', { prefixes: [root] });
|
|
452
|
+
const list = rooms.find((entry) => entry.room_ref === room);
|
|
453
|
+
if (list === undefined)
|
|
454
|
+
throw new Error('House serves nothing of it to copy');
|
|
455
|
+
if (!list.ready)
|
|
456
|
+
throw new NotReady([room]);
|
|
457
|
+
const held = new Set(await readdir(directory));
|
|
458
|
+
const failure = await stagedChunks(directory, list.chunks.filter(({ hash }) => !held.has(hash)));
|
|
459
|
+
if (failure === undefined) {
|
|
460
|
+
return { position: list.position, log_epoch: list.log_epoch, texts: chunkTexts(directory, list.chunks, list.models) };
|
|
461
|
+
}
|
|
462
|
+
if (renewed && (await readdir(directory)).length === held.size)
|
|
463
|
+
throw failure;
|
|
354
464
|
}
|
|
355
|
-
await this.save(await this.caughtUp(copy));
|
|
356
465
|
}
|
|
357
|
-
async
|
|
358
|
-
const
|
|
359
|
-
if (
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
const repository = join(localCopies(), 'rooms', read.anchor);
|
|
364
|
-
if (await exists(repository)) {
|
|
365
|
-
logged(`${repository} already exists and House Kit leaves it as it is`);
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
const staging = join(dirname(repository), `.${randomUUID()}`);
|
|
466
|
+
async materialized({ key, handle, authority }, whole) {
|
|
467
|
+
const repository = join(localCopies(), 'rooms', authority.room_ref);
|
|
468
|
+
if (await exists(repository))
|
|
469
|
+
throw new Error(`${repository} already exists and Kit leaves it as it is`);
|
|
470
|
+
const staging = join(dirname(repository), `${stagingPrefix()}${randomUUID()}`);
|
|
471
|
+
const scope = { write: authority.operations.write, protected: authority.protected_paths };
|
|
369
472
|
await mkdir(staging, { recursive: true });
|
|
370
|
-
let
|
|
371
|
-
let readOnly;
|
|
473
|
+
let copy;
|
|
372
474
|
try {
|
|
373
475
|
await git(staging, ['init', '-q', '-b', BRANCH]);
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
476
|
+
const read = await whole(join(staging, '.git', STAGED_CHUNKS));
|
|
477
|
+
const readOnly = await readOnlyFiles(staging, []);
|
|
478
|
+
const { house, revisions } = await importedWhole(staging, scope, read.texts, { message: `House ${rootOf(handle)}`, from: null }, readOnly);
|
|
377
479
|
await git(staging, ['update-ref', `refs/heads/${BRANCH}`, house]);
|
|
378
480
|
await git(staging, ['reset', '-q', '--hard']);
|
|
379
|
-
|
|
380
|
-
|
|
481
|
+
copy = {
|
|
482
|
+
key,
|
|
483
|
+
room_ref: authority.room_ref,
|
|
484
|
+
room_handle: handle,
|
|
485
|
+
repository,
|
|
486
|
+
house,
|
|
487
|
+
position: read.position,
|
|
488
|
+
log_epoch: read.log_epoch,
|
|
489
|
+
...scope,
|
|
490
|
+
read_only: readOnly.held(),
|
|
491
|
+
manifests: { [house]: { parent: null, files: revisions } },
|
|
492
|
+
moves: [],
|
|
493
|
+
};
|
|
494
|
+
await ignoreRules(staging, Object.keys(revisions), copy);
|
|
495
|
+
await rm(join(staging, '.git', STAGED_CHUNKS), { recursive: true, force: true });
|
|
381
496
|
await rename(staging, repository);
|
|
382
497
|
}
|
|
383
498
|
catch (error) {
|
|
384
499
|
await rm(staging, { recursive: true, force: true });
|
|
385
500
|
throw error;
|
|
386
501
|
}
|
|
387
|
-
|
|
388
|
-
key: scope.key,
|
|
389
|
-
room_ref: read.anchor,
|
|
390
|
-
room_handle: scope.handle,
|
|
391
|
-
repository,
|
|
392
|
-
active: true,
|
|
393
|
-
house,
|
|
394
|
-
position: read.position,
|
|
395
|
-
log_epoch: read.log_epoch,
|
|
396
|
-
write: read.write,
|
|
397
|
-
protected: read.protected,
|
|
398
|
-
read_only: readOnly,
|
|
399
|
-
manifests: { [house]: { parent: null, files: read.revisions } },
|
|
400
|
-
moves: [],
|
|
401
|
-
});
|
|
502
|
+
return this.save(copy);
|
|
402
503
|
}
|
|
403
|
-
async
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
504
|
+
async copied(wanted) {
|
|
505
|
+
const { handle, authority } = wanted;
|
|
506
|
+
const root = rootOf(handle);
|
|
507
|
+
let answer = null;
|
|
508
|
+
try {
|
|
509
|
+
if (!this.waiting.has(authority.room_ref)) {
|
|
510
|
+
answer = await this.house.door('changes/enumerate', {
|
|
511
|
+
prefixes: [root],
|
|
512
|
+
positions: [
|
|
513
|
+
{ authority: authority.room_ref, position: '0', log_epoch: authority.log_epoch, page: { through: authority.position, read: 0 } },
|
|
514
|
+
],
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
catch (error) {
|
|
519
|
+
if (expiredAuthority(error) !== authority.room_ref)
|
|
520
|
+
throw error;
|
|
521
|
+
}
|
|
522
|
+
const view = answer?.authorities.find((entry) => entry.authority === authority.room_ref);
|
|
523
|
+
if (answer !== null && view === undefined)
|
|
524
|
+
throw new Error('House serves nothing of it to copy');
|
|
525
|
+
if (view !== undefined && view.next === undefined) {
|
|
526
|
+
const texts = view.changes.filter((change) => !('removed' in change));
|
|
527
|
+
const copy = await this.materialized(wanted, async () => ({ position: view.position, log_epoch: view.log_epoch, texts }));
|
|
528
|
+
return `${root}: copied to ${copy.repository}`;
|
|
529
|
+
}
|
|
530
|
+
const copy = await this.materialized(wanted, (directory) => this.chunked(root, authority.room_ref, directory));
|
|
531
|
+
const [caught] = await this.caughtUp([copy], true);
|
|
532
|
+
await succeeded(copy.repository, ['merge', '--ff-only', '-q', caught.house]);
|
|
533
|
+
return `${root}: copied to ${copy.repository}`;
|
|
424
534
|
}
|
|
425
|
-
async
|
|
426
|
-
|
|
427
|
-
|
|
535
|
+
async received(copy, authority) {
|
|
536
|
+
const root = rootOf(copy.room_handle);
|
|
537
|
+
const directory = join(copy.repository, '.git', STAGED_CHUNKS);
|
|
538
|
+
const scope = { write: authority.operations.write, protected: authority.protected_paths };
|
|
539
|
+
try {
|
|
540
|
+
const read = await this.chunked(root, copy.room_ref, directory);
|
|
541
|
+
const readOnly = await readOnlyFiles(copy.repository, copy.read_only);
|
|
542
|
+
for (const path of copy.read_only)
|
|
543
|
+
await readOnly.remove(path);
|
|
544
|
+
const commit = { message: `House ${root} at position ${read.position}`, from: copy.house, replaces: true };
|
|
545
|
+
const { house, revisions } = await importedWhole(copy.repository, scope, read.texts, commit, readOnly);
|
|
546
|
+
const next = {
|
|
547
|
+
...copy,
|
|
548
|
+
...scope,
|
|
549
|
+
house,
|
|
550
|
+
position: read.position,
|
|
551
|
+
log_epoch: read.log_epoch,
|
|
552
|
+
read_only: readOnly.held(),
|
|
553
|
+
manifests: { ...copy.manifests, [house]: { parent: null, files: revisions } },
|
|
554
|
+
};
|
|
555
|
+
await ignoreRules(copy.repository, Object.keys(revisions), next);
|
|
556
|
+
return next;
|
|
557
|
+
}
|
|
558
|
+
finally {
|
|
559
|
+
await rm(directory, { recursive: true, force: true });
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
async reread(copy) {
|
|
563
|
+
const { authorities } = await this.discovered([copy.room_handle]);
|
|
564
|
+
const authority = authorities.find((entry) => entry.room_ref === copy.room_ref);
|
|
565
|
+
if (authority === undefined)
|
|
566
|
+
throw new NotReady([copy.room_ref]);
|
|
567
|
+
return this.received(copy, authority);
|
|
568
|
+
}
|
|
569
|
+
async refreshed(copies, unready) {
|
|
570
|
+
const { bounds, authorities } = await this.discovered(copies.map((copy) => copy.room_handle));
|
|
571
|
+
const read = [];
|
|
572
|
+
const unchanged = [];
|
|
573
|
+
for (const copy of copies) {
|
|
574
|
+
const authority = authorities.find((entry) => entry.room_ref === copy.room_ref);
|
|
575
|
+
if (authority !== undefined &&
|
|
576
|
+
JSON.stringify([authority.operations.write, authority.protected_paths]) !== JSON.stringify([copy.write, copy.protected])) {
|
|
577
|
+
try {
|
|
578
|
+
read.push(await this.save(await this.received(copy, authority)));
|
|
579
|
+
}
|
|
580
|
+
catch (error) {
|
|
581
|
+
if (!(error instanceof NotReady))
|
|
582
|
+
throw error;
|
|
583
|
+
unready.push(...error.rooms);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
unchanged.push(copy);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
for (const group of grouped(unchanged, bounds.max_prefixes))
|
|
591
|
+
await this.caughtUp(group, false, unready);
|
|
592
|
+
for (const group of grouped(read, bounds.max_prefixes))
|
|
593
|
+
await this.caughtUp(group, true, unready);
|
|
594
|
+
}
|
|
595
|
+
async caughtUp(copies, whole, unready) {
|
|
596
|
+
const caught = new Map(copies.map((copy) => [copy.key, copy]));
|
|
597
|
+
const read = new Set();
|
|
598
|
+
const waiting = unready ?? [];
|
|
599
|
+
let asking = [...copies];
|
|
600
|
+
while (asking.length > 0) {
|
|
428
601
|
let answer;
|
|
429
602
|
try {
|
|
430
|
-
answer = await this.house.
|
|
431
|
-
prefixes:
|
|
432
|
-
positions:
|
|
603
|
+
answer = await this.house.door('changes/enumerate', {
|
|
604
|
+
prefixes: asking.map((copy) => rootOf(copy.room_handle)),
|
|
605
|
+
positions: asking.map((copy) => ({ authority: copy.room_ref, position: copy.position, log_epoch: copy.log_epoch })),
|
|
433
606
|
});
|
|
434
607
|
}
|
|
435
608
|
catch (error) {
|
|
436
|
-
const
|
|
437
|
-
if (
|
|
438
|
-
return this.received(copy);
|
|
439
|
-
if (code !== 'replica_behind')
|
|
609
|
+
const expired = asking.find((copy) => copy.room_ref === expiredAuthority(error));
|
|
610
|
+
if (expired === undefined)
|
|
440
611
|
throw error;
|
|
441
|
-
|
|
612
|
+
asking = asking.filter((copy) => copy !== expired);
|
|
613
|
+
if (read.has(expired.key)) {
|
|
614
|
+
waiting.push(expired.room_ref);
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
read.add(expired.key);
|
|
618
|
+
try {
|
|
619
|
+
const next = await this.save(await this.reread(expired));
|
|
620
|
+
caught.set(expired.key, next);
|
|
621
|
+
asking.push(next);
|
|
622
|
+
}
|
|
623
|
+
catch (refused) {
|
|
624
|
+
if (!(refused instanceof NotReady))
|
|
625
|
+
throw refused;
|
|
626
|
+
waiting.push(expired.room_ref);
|
|
627
|
+
}
|
|
628
|
+
continue;
|
|
442
629
|
}
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
630
|
+
const advanced = [];
|
|
631
|
+
for (const copy of asking) {
|
|
632
|
+
const view = answer.authorities.find((entry) => entry.authority === copy.room_ref);
|
|
633
|
+
if (view === undefined || (view.position === copy.position && view.log_epoch === copy.log_epoch))
|
|
634
|
+
continue;
|
|
635
|
+
const next = await this.save(await this.incorporated(copy, view.changes, view.position, view.log_epoch));
|
|
636
|
+
caught.set(copy.key, next);
|
|
637
|
+
advanced.push(next);
|
|
638
|
+
}
|
|
639
|
+
asking = advanced.filter((copy) => whole || read.has(copy.key));
|
|
447
640
|
}
|
|
641
|
+
if (unready === undefined && waiting.length > 0)
|
|
642
|
+
throw new NotReady(waiting);
|
|
643
|
+
return copies.map((copy) => caught.get(copy.key));
|
|
448
644
|
}
|
|
449
645
|
async incorporated(copy, changes, position, logEpoch) {
|
|
450
646
|
const houseTree = await tree(copy.repository, copy.house);
|
|
@@ -507,9 +703,6 @@ export class LocalCopies {
|
|
|
507
703
|
}
|
|
508
704
|
copy = await this.save(without(copy));
|
|
509
705
|
}
|
|
510
|
-
if (!copy.active) {
|
|
511
|
-
return { refused: true, text: `${rootOf(copy.room_handle)} is no longer synced to this Environment, so House takes no push from it` };
|
|
512
|
-
}
|
|
513
706
|
const listed = (await git(copy.repository, ['rev-list', '--topo-order', commit])).split('\n');
|
|
514
707
|
const base = listed.find((ancestor) => ancestor in copy.manifests);
|
|
515
708
|
if (base === undefined) {
|
|
@@ -520,7 +713,7 @@ export class LocalCopies {
|
|
|
520
713
|
changes = await this.derived(copy, base, commit);
|
|
521
714
|
}
|
|
522
715
|
catch (error) {
|
|
523
|
-
return { refused: true, text:
|
|
716
|
+
return { refused: true, text: houseCause(error) };
|
|
524
717
|
}
|
|
525
718
|
if (changes.length === 0)
|
|
526
719
|
return { refused: false, text: `Nothing to submit: ${short(commit)} matches House.` };
|
|
@@ -547,7 +740,19 @@ export class LocalCopies {
|
|
|
547
740
|
const after = await tree(copy.repository, commit);
|
|
548
741
|
const moved = movedPaths(copy.moves, before, after);
|
|
549
742
|
const arrived = new Set(moved.values());
|
|
550
|
-
const
|
|
743
|
+
const arriving = [...after].filter(([path, entry]) => before.get(path) !== entry);
|
|
744
|
+
if (arriving.length > 0) {
|
|
745
|
+
const { bounds } = await this.house.door('rooms/discover', { prefixes: [root] });
|
|
746
|
+
const binary = [];
|
|
747
|
+
for (const [path, entry] of arriving) {
|
|
748
|
+
if (!(await isText(copy.repository, entry, bounds.max_authored_file_bytes)))
|
|
749
|
+
binary.push(path);
|
|
750
|
+
}
|
|
751
|
+
if (binary.length > 0)
|
|
752
|
+
throw new Error(textOnly(binary));
|
|
753
|
+
}
|
|
754
|
+
const text = (entry) => blobText(copy.repository, entry);
|
|
755
|
+
const model = await modelOf(copy, after);
|
|
551
756
|
const changes = [];
|
|
552
757
|
for (const path of [...new Set([...before.keys(), ...after.keys()])].sort()) {
|
|
553
758
|
if (arrived.has(path))
|
|
@@ -560,7 +765,7 @@ export class LocalCopies {
|
|
|
560
765
|
changes.push({ op: 'rename', path: `${root}/${path}`, to: `${root}/${to}`, base: known });
|
|
561
766
|
const moving = after.get(to);
|
|
562
767
|
if (moving !== prior) {
|
|
563
|
-
changes.push({ op: 'replace', path: `${root}/${to}`, base: known, content: await text(moving
|
|
768
|
+
changes.push({ op: 'replace', path: `${root}/${to}`, base: known, content: await text(moving) });
|
|
564
769
|
}
|
|
565
770
|
continue;
|
|
566
771
|
}
|
|
@@ -569,9 +774,9 @@ export class LocalCopies {
|
|
|
569
774
|
if (next === undefined)
|
|
570
775
|
changes.push({ op: 'remove', path: `${root}/${path}`, base: known });
|
|
571
776
|
else if (prior === undefined)
|
|
572
|
-
changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next
|
|
777
|
+
changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next) });
|
|
573
778
|
else
|
|
574
|
-
changes.push(...changed(`${root}/${path}`, path, known, await text(prior
|
|
779
|
+
changes.push(...changed(`${root}/${path}`, path, known, await text(prior), await text(next), model));
|
|
575
780
|
}
|
|
576
781
|
return changes;
|
|
577
782
|
}
|
|
@@ -598,12 +803,14 @@ export class LocalCopies {
|
|
|
598
803
|
const { upload, ...unstaged } = copy.push;
|
|
599
804
|
return this.settle(await this.save({ ...copy, push: unstaged }), caller, true);
|
|
600
805
|
}
|
|
601
|
-
if (outcome.refused.code === '
|
|
806
|
+
if (outcome.refused.code === 'expired')
|
|
602
807
|
return this.recovered(copy);
|
|
603
|
-
const rebased = rebaseFixes(outcome.refused);
|
|
604
808
|
let settled = await this.save(without(copy));
|
|
809
|
+
if (settled.unfollowed !== undefined)
|
|
810
|
+
return { refused: true, text: outcome.refused.text };
|
|
811
|
+
const rebased = rebaseFixes(outcome.refused);
|
|
605
812
|
try {
|
|
606
|
-
settled =
|
|
813
|
+
settled = (await this.caughtUp([settled], true))[0];
|
|
607
814
|
}
|
|
608
815
|
catch {
|
|
609
816
|
return {
|
|
@@ -622,10 +829,11 @@ export class LocalCopies {
|
|
|
622
829
|
}
|
|
623
830
|
async recovered(copy) {
|
|
624
831
|
const push = copy.push;
|
|
625
|
-
const current =
|
|
832
|
+
const current = (await this.caughtUp([copy], true))[0];
|
|
626
833
|
const house = await tree(copy.repository, current.house);
|
|
627
834
|
const root = rootOf(current.room_handle);
|
|
628
|
-
|
|
835
|
+
const model = await modelOf(current, house);
|
|
836
|
+
if (!(await this.landed(copy.repository, push.changes, house, await tree(copy.repository, push.commit), model))) {
|
|
629
837
|
await this.save(without(current));
|
|
630
838
|
return {
|
|
631
839
|
refused: true,
|
|
@@ -638,7 +846,7 @@ export class LocalCopies {
|
|
|
638
846
|
written.push({
|
|
639
847
|
path: `${root}/${path}`,
|
|
640
848
|
revision: entry === undefined ? null : (revisionAt(current, current.house, path) ?? null),
|
|
641
|
-
content: entry === undefined ? null : await blobText(copy.repository, entry
|
|
849
|
+
content: entry === undefined ? null : await blobText(copy.repository, entry),
|
|
642
850
|
});
|
|
643
851
|
}
|
|
644
852
|
return this.finished(await this.save({ ...current, push: { ...push, state: 'accepted', written } }));
|
|
@@ -666,7 +874,7 @@ export class LocalCopies {
|
|
|
666
874
|
const push = copy.push;
|
|
667
875
|
let written = push.written;
|
|
668
876
|
if (push.changes.some((change) => change.op === 'rename')) {
|
|
669
|
-
copy =
|
|
877
|
+
copy = (await this.caughtUp([copy], true))[0];
|
|
670
878
|
const house = await tree(copy.repository, copy.house);
|
|
671
879
|
const sent = await tree(copy.repository, push.house);
|
|
672
880
|
if (push.changes.some((change) => change.op === 'rename' && !house.has(relative(change.to)))) {
|
|
@@ -682,7 +890,7 @@ export class LocalCopies {
|
|
|
682
890
|
{
|
|
683
891
|
path: `${rootOf(copy.room_handle)}/${path}`,
|
|
684
892
|
revision: entry === undefined ? null : (revisionAt(copy, copy.house, path) ?? null),
|
|
685
|
-
content: entry === undefined ? null : await blobText(copy.repository, entry
|
|
893
|
+
content: entry === undefined ? null : await blobText(copy.repository, entry),
|
|
686
894
|
},
|
|
687
895
|
];
|
|
688
896
|
}
|
|
@@ -724,10 +932,10 @@ export class LocalCopies {
|
|
|
724
932
|
push: { ...push, acknowledged },
|
|
725
933
|
};
|
|
726
934
|
}
|
|
727
|
-
async landed(repository, changes, house, selected) {
|
|
935
|
+
async landed(repository, changes, house, selected, model) {
|
|
728
936
|
const text = async (path) => {
|
|
729
937
|
const entry = house.get(relative(path));
|
|
730
|
-
return entry === undefined ? undefined : blobText(repository, entry
|
|
938
|
+
return entry === undefined ? undefined : blobText(repository, entry);
|
|
731
939
|
};
|
|
732
940
|
for (const change of changes) {
|
|
733
941
|
const current = await text(change.path);
|
|
@@ -738,9 +946,8 @@ export class LocalCopies {
|
|
|
738
946
|
}
|
|
739
947
|
if ((change.op === 'create' || change.op === 'replace') && current === change.content)
|
|
740
948
|
continue;
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
if (document === null)
|
|
949
|
+
const document = current === undefined ? undefined : readDocument(current, relative(change.path), model)?.document;
|
|
950
|
+
if (document === undefined)
|
|
744
951
|
return false;
|
|
745
952
|
if (change.op === 'set_field' && JSON.stringify(document.fields[change.field]) === JSON.stringify(change.value))
|
|
746
953
|
continue;
|
|
@@ -753,7 +960,7 @@ export class LocalCopies {
|
|
|
753
960
|
return true;
|
|
754
961
|
}
|
|
755
962
|
async revisionText(path, wanted) {
|
|
756
|
-
const page = await this.house.
|
|
963
|
+
const page = await this.house.door('files/revisions/list', {
|
|
757
964
|
path,
|
|
758
965
|
revision: wanted,
|
|
759
966
|
});
|