@agentshouse/kit 0.2.1-cd9cbd8b6428c → 0.2.1-cdc3937dea52e
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 +46 -49
- package/dist/acp.js +101 -108
- package/dist/afk.js +17 -0
- package/dist/agents.js +271 -73
- package/dist/api.js +43 -6
- package/dist/app-git.js +48 -0
- package/dist/bridge.js +42 -62
- package/dist/building.js +50 -0
- package/dist/calls.js +88 -0
- package/dist/chunks.js +49 -0
- package/dist/clis.js +179 -95
- 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 +817 -333
- package/dist/copies.js +451 -251
- package/dist/earlier.js +263 -0
- package/dist/end.js +26 -0
- package/dist/events.js +793 -0
- package/dist/files.js +139 -17
- package/dist/git-main.js +24 -29
- package/dist/git.js +57 -21
- package/dist/grok.js +39 -0
- package/dist/home.js +134 -9
- package/dist/house-cli.js +362 -0
- package/dist/house-main.js +7 -159
- package/dist/instructions.js +7 -11
- package/dist/keys.js +238 -0
- package/dist/kit-cli.js +78 -0
- package/dist/kit-main.js +8 -19
- package/dist/login.js +133 -104
- package/dist/logout.js +15 -14
- package/dist/mcp.js +6 -2
- package/dist/owner.js +46 -0
- package/dist/placement.js +25 -0
- package/dist/refusals.js +12 -0
- package/dist/relay.js +33 -2
- package/dist/resident.js +161 -61
- package/dist/scope.js +214 -0
- package/dist/scripts.js +303 -0
- package/dist/secret-input.js +5 -2
- package/dist/settings.js +188 -0
- package/dist/shell.js +3 -0
- package/dist/sign-in.js +85 -32
- package/dist/silence.js +28 -0
- package/dist/skills.js +49 -35
- package/dist/supervisor.js +163 -0
- package/dist/transcription.js +131 -40
- package/dist/translate.js +19 -16
- package/dist/update.js +119 -100
- package/dist/wire.js +32 -0
- package/dist/work.js +353 -0
- package/dist/workspace.js +103 -0
- package/package.json +26 -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 -47
- 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,21 +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
|
-
import { HouseRefusal } from './api.js';
|
|
6
|
-
import {
|
|
5
|
+
import { finalRefusal, HouseRefusal, retrying } from './api.js';
|
|
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
|
|
15
|
-
const
|
|
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
|
+
}
|
|
16
29
|
function causeOf(error) {
|
|
17
30
|
return error instanceof Error ? error.message : String(error);
|
|
18
31
|
}
|
|
32
|
+
function houseCause(error) {
|
|
33
|
+
return error instanceof HouseRefusal ? (refusalOf(error.text)?.text ?? causeOf(error)) : causeOf(error);
|
|
34
|
+
}
|
|
19
35
|
function logged(error) {
|
|
20
36
|
process.stderr.write(`kit: ${causeOf(error)}\n`);
|
|
21
37
|
}
|
|
@@ -30,9 +46,35 @@ const REBASED = new Set([
|
|
|
30
46
|
function rebaseFixes(refusal) {
|
|
31
47
|
return refusal.code === 'edit_conflict' && refusal.conflicts.some((code) => REBASED.has(code));
|
|
32
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
|
+
}
|
|
33
56
|
function short(commit) {
|
|
34
57
|
return commit.slice(0, 12);
|
|
35
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
|
+
}
|
|
36
78
|
function covers(path, prefix) {
|
|
37
79
|
return prefix === '' || path === prefix || path.startsWith(`${prefix}/`);
|
|
38
80
|
}
|
|
@@ -41,11 +83,17 @@ function sidecar(path) {
|
|
|
41
83
|
segments.splice(-1, 0, PROVENANCE);
|
|
42
84
|
return segments.join('/');
|
|
43
85
|
}
|
|
44
|
-
function
|
|
45
|
-
return
|
|
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
|
+
}
|
|
92
|
+
function rootOf(handle) {
|
|
93
|
+
return `/rooms/${handle}`;
|
|
46
94
|
}
|
|
47
95
|
function relative(path) {
|
|
48
|
-
return path.replace(/^\/
|
|
96
|
+
return path.replace(/^\/rooms\/[^/]+\//, '');
|
|
49
97
|
}
|
|
50
98
|
function declaredWritable(path, copy) {
|
|
51
99
|
const deepest = (scopes) => Math.max(-1, ...scopes.filter((scope) => covers(path, scope)).map((scope) => scope.length));
|
|
@@ -68,32 +116,59 @@ async function removeFile(repository, path) {
|
|
|
68
116
|
return;
|
|
69
117
|
}
|
|
70
118
|
}
|
|
71
|
-
async function
|
|
119
|
+
async function readOnlyFiles(repository, held) {
|
|
72
120
|
const tracked = new Set((await git(repository, ['ls-files', '-z'])).split('\0'));
|
|
73
121
|
const holding = new Set(held);
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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 };
|
|
90
165
|
}
|
|
91
166
|
async function ruled(path, rules) {
|
|
92
167
|
if ((await readFile(path, 'utf8').catch(() => null)) !== rules)
|
|
93
168
|
await writeFile(path, rules);
|
|
94
169
|
}
|
|
95
170
|
async function ignoreRules(repository, writable, copy) {
|
|
96
|
-
const readOnly =
|
|
171
|
+
const readOnly = copy.read_only.filter((path) => !path.split('/').includes(PROVENANCE));
|
|
97
172
|
const protectedPath = (path) => copy.protected.some((prefix) => prefix !== '' && covers(path, prefix));
|
|
98
173
|
const whole = copy.protected.filter((prefix) => prefix !== '' && !writable.some((path) => covers(path, prefix)));
|
|
99
174
|
const house = [
|
|
@@ -102,7 +177,7 @@ async function ignoreRules(repository, writable, copy) {
|
|
|
102
177
|
].map(pattern);
|
|
103
178
|
const granted = readOnly.filter((path) => !protectedPath(path)).map(pattern);
|
|
104
179
|
await ruled(join(repository, '.gitignore'), [
|
|
105
|
-
'#
|
|
180
|
+
'# Kit writes this file and .ignore. The paths below are read-only House',
|
|
106
181
|
'# content: Git does not track them, and House refuses a change to them even',
|
|
107
182
|
'# when this file is edited or a path is force-added.',
|
|
108
183
|
'/.gitignore',
|
|
@@ -117,13 +192,19 @@ async function ignoreRules(repository, writable, copy) {
|
|
|
117
192
|
'',
|
|
118
193
|
].join('\n'));
|
|
119
194
|
await ruled(join(repository, '.ignore'), [
|
|
120
|
-
'#
|
|
195
|
+
'# Kit writes this file so native search still reads the read-only House',
|
|
121
196
|
'# content that .gitignore keeps out of Git.',
|
|
122
197
|
`!${PROVENANCE}`,
|
|
123
198
|
...[...house, ...granted].map((rule) => `!${rule}`),
|
|
124
199
|
'',
|
|
125
200
|
].join('\n'));
|
|
126
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
|
+
}
|
|
127
208
|
function revisionAt(copy, commit, path) {
|
|
128
209
|
let manifest = copy.manifests[commit];
|
|
129
210
|
while (manifest !== undefined) {
|
|
@@ -153,19 +234,19 @@ export class LocalCopies {
|
|
|
153
234
|
house;
|
|
154
235
|
copies = new Map();
|
|
155
236
|
queues = new Map();
|
|
156
|
-
|
|
157
|
-
|
|
237
|
+
waiting = new Set();
|
|
238
|
+
answering = Promise.resolve();
|
|
158
239
|
constructor(house) {
|
|
159
240
|
this.house = house;
|
|
160
241
|
this.owner = {
|
|
161
242
|
key: 'owner',
|
|
162
243
|
submit: async (operation, changes) => {
|
|
163
244
|
try {
|
|
164
|
-
const outcome = await house.
|
|
245
|
+
const outcome = await retrying(() => house.door('files/batch', { operation_id: operation, changes }));
|
|
165
246
|
return { accepted: outcome.contents };
|
|
166
247
|
}
|
|
167
248
|
catch (error) {
|
|
168
|
-
if (!(error
|
|
249
|
+
if (!finalRefusal(error))
|
|
169
250
|
throw error;
|
|
170
251
|
return {
|
|
171
252
|
refused: refusalOf(error.text) ?? { code: '', text: `House refused it with ${error.status}`, conflicts: [] },
|
|
@@ -177,7 +258,7 @@ export class LocalCopies {
|
|
|
177
258
|
async load() {
|
|
178
259
|
const home = join(kitHome(), 'local-copies');
|
|
179
260
|
const names = (await readdir(join(home, 'rooms')).catch(() => [])).filter((name) => name.endsWith('.json'));
|
|
180
|
-
for (const path of
|
|
261
|
+
for (const path of names.map((name) => join(home, 'rooms', name))) {
|
|
181
262
|
const text = await readFile(path, 'utf8').catch(() => null);
|
|
182
263
|
if (text === null)
|
|
183
264
|
continue;
|
|
@@ -185,48 +266,115 @@ export class LocalCopies {
|
|
|
185
266
|
this.copies.set(copy.key, copy);
|
|
186
267
|
}
|
|
187
268
|
}
|
|
188
|
-
async
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
.
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
+
}
|
|
230
378
|
}
|
|
231
379
|
async observed(report) {
|
|
232
380
|
const key = await this.keyAt(dirname(report.common));
|
|
@@ -256,11 +404,11 @@ export class LocalCopies {
|
|
|
256
404
|
async push(cwd, selector, caller) {
|
|
257
405
|
const located = await run(cwd, ['rev-parse', '--path-format=absolute', '--git-common-dir', '--show-toplevel']);
|
|
258
406
|
if (located.status !== 0)
|
|
259
|
-
return
|
|
407
|
+
return outside(cwd);
|
|
260
408
|
const [common, worktree] = located.stdout.toString('utf8').split('\n');
|
|
261
409
|
const key = await this.keyAt(dirname(common));
|
|
262
410
|
if (key === undefined)
|
|
263
|
-
return
|
|
411
|
+
return outside(worktree);
|
|
264
412
|
return this.exclusive(key, () => this.pushed(key, worktree, selector, caller));
|
|
265
413
|
}
|
|
266
414
|
async keyAt(repository) {
|
|
@@ -276,19 +424,12 @@ export class LocalCopies {
|
|
|
276
424
|
this.queues.set(key, queued.catch(() => undefined));
|
|
277
425
|
return queued;
|
|
278
426
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
this.delivering.add(key);
|
|
283
|
-
void this.exclusive(key, async () => {
|
|
284
|
-
this.delivering.delete(key);
|
|
285
|
-
const copy = this.copies.get(key);
|
|
286
|
-
if (copy.active)
|
|
287
|
-
await this.save(await this.caughtUp(copy));
|
|
288
|
-
}).catch(logged);
|
|
427
|
+
holding(keys, work) {
|
|
428
|
+
const [key, ...rest] = keys;
|
|
429
|
+
return key === undefined ? work() : this.exclusive(key, () => this.holding(rest, work));
|
|
289
430
|
}
|
|
290
431
|
async save(copy) {
|
|
291
|
-
const path =
|
|
432
|
+
const path = recordOf(copy.key);
|
|
292
433
|
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
293
434
|
const temporary = `${path}.${process.pid}`;
|
|
294
435
|
await writeFile(temporary, JSON.stringify(copy), { mode: 0o600 });
|
|
@@ -296,163 +437,211 @@ export class LocalCopies {
|
|
|
296
437
|
this.copies.set(copy.key, copy);
|
|
297
438
|
return copy;
|
|
298
439
|
}
|
|
299
|
-
async
|
|
300
|
-
const
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (view === undefined)
|
|
307
|
-
return null;
|
|
308
|
-
const authority = discovery.authorities.find((entry) => entry.room_ref === view.manifest.anchor);
|
|
309
|
-
const contents = new Map(view.contents.map((entry) => [entry.path, entry.content]));
|
|
310
|
-
const read = {
|
|
311
|
-
anchor: view.manifest.anchor,
|
|
312
|
-
position: view.manifest.position,
|
|
313
|
-
log_epoch: view.manifest.log_epoch,
|
|
314
|
-
write: authority.operations.write,
|
|
315
|
-
protected: authority.protected_paths,
|
|
316
|
-
writable: new Map(),
|
|
317
|
-
revisions: {},
|
|
318
|
-
readOnly: new Map(),
|
|
319
|
-
};
|
|
320
|
-
for (const file of view.manifest.files) {
|
|
321
|
-
const content = contents.get(file.path);
|
|
322
|
-
if (file.writable) {
|
|
323
|
-
read.writable.set(file.path, content);
|
|
324
|
-
read.revisions[file.path] = file.revision;
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
read.readOnly.set(file.path, content);
|
|
328
|
-
}
|
|
329
|
-
if (file.provenance !== undefined)
|
|
330
|
-
read.readOnly.set(sidecar(file.path), file.provenance);
|
|
331
|
-
}
|
|
332
|
-
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 };
|
|
333
447
|
}
|
|
334
|
-
async
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
await this.
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
if (authority === undefined)
|
|
351
|
-
return;
|
|
352
|
-
if (authority.managed_replication !== 'admitted') {
|
|
353
|
-
logged(`operation_denied: ${rootOf(copy)} is not synchronized to this Environment`);
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
if (JSON.stringify([authority.operations.write, authority.protected_paths]) !==
|
|
357
|
-
JSON.stringify([copy.write, copy.protected])) {
|
|
358
|
-
await this.save(await this.received(copy));
|
|
359
|
-
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;
|
|
360
464
|
}
|
|
361
|
-
await this.save(await this.caughtUp(copy));
|
|
362
465
|
}
|
|
363
|
-
async
|
|
364
|
-
const
|
|
365
|
-
if (
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
const repository = scope.private ? join(localCopies(), 'private') : join(localCopies(), 'rooms', read.anchor);
|
|
370
|
-
if (await exists(repository)) {
|
|
371
|
-
logged(`${repository} already exists and House Kit leaves it as it is`);
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
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 };
|
|
375
472
|
await mkdir(staging, { recursive: true });
|
|
376
|
-
let
|
|
377
|
-
let readOnly;
|
|
473
|
+
let copy;
|
|
378
474
|
try {
|
|
379
475
|
await git(staging, ['init', '-q', '-b', BRANCH]);
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
]);
|
|
476
|
+
await git(staging, ['config', 'core.precomposeUnicode', 'true']);
|
|
477
|
+
const read = await whole(join(staging, '.git', STAGED_CHUNKS));
|
|
478
|
+
const readOnly = await readOnlyFiles(staging, []);
|
|
479
|
+
const { house, revisions } = await importedWhole(staging, scope, read.texts, { message: `House ${rootOf(handle)}`, from: null }, readOnly);
|
|
383
480
|
await git(staging, ['update-ref', `refs/heads/${BRANCH}`, house]);
|
|
384
481
|
await git(staging, ['reset', '-q', '--hard']);
|
|
385
|
-
|
|
386
|
-
|
|
482
|
+
copy = {
|
|
483
|
+
key,
|
|
484
|
+
room_ref: authority.room_ref,
|
|
485
|
+
room_handle: handle,
|
|
486
|
+
repository,
|
|
487
|
+
house,
|
|
488
|
+
position: read.position,
|
|
489
|
+
log_epoch: read.log_epoch,
|
|
490
|
+
...scope,
|
|
491
|
+
read_only: readOnly.held(),
|
|
492
|
+
manifests: { [house]: { parent: null, files: revisions } },
|
|
493
|
+
moves: [],
|
|
494
|
+
};
|
|
495
|
+
await ignoreRules(staging, Object.keys(revisions), copy);
|
|
496
|
+
await rm(join(staging, '.git', STAGED_CHUNKS), { recursive: true, force: true });
|
|
387
497
|
await rename(staging, repository);
|
|
388
498
|
}
|
|
389
499
|
catch (error) {
|
|
390
500
|
await rm(staging, { recursive: true, force: true });
|
|
391
501
|
throw error;
|
|
392
502
|
}
|
|
393
|
-
|
|
394
|
-
key: scope.key,
|
|
395
|
-
private: scope.private,
|
|
396
|
-
room_ref: read.anchor,
|
|
397
|
-
room_handle: scope.handle,
|
|
398
|
-
repository,
|
|
399
|
-
active: true,
|
|
400
|
-
house,
|
|
401
|
-
position: read.position,
|
|
402
|
-
log_epoch: read.log_epoch,
|
|
403
|
-
write: read.write,
|
|
404
|
-
protected: read.protected,
|
|
405
|
-
read_only: readOnly,
|
|
406
|
-
manifests: { [house]: { parent: null, files: read.revisions } },
|
|
407
|
-
moves: [],
|
|
408
|
-
});
|
|
503
|
+
return this.save(copy);
|
|
409
504
|
}
|
|
410
|
-
async
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
505
|
+
async copied(wanted) {
|
|
506
|
+
const { handle, authority } = wanted;
|
|
507
|
+
const root = rootOf(handle);
|
|
508
|
+
let answer = null;
|
|
509
|
+
try {
|
|
510
|
+
if (!this.waiting.has(authority.room_ref)) {
|
|
511
|
+
answer = await this.house.door('changes/enumerate', {
|
|
512
|
+
prefixes: [root],
|
|
513
|
+
positions: [
|
|
514
|
+
{ authority: authority.room_ref, position: '0', log_epoch: authority.log_epoch, page: { through: authority.position, read: 0 } },
|
|
515
|
+
],
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
catch (error) {
|
|
520
|
+
if (expiredAuthority(error) !== authority.room_ref)
|
|
521
|
+
throw error;
|
|
522
|
+
}
|
|
523
|
+
const view = answer?.authorities.find((entry) => entry.authority === authority.room_ref);
|
|
524
|
+
if (answer !== null && view === undefined)
|
|
525
|
+
throw new Error('House serves nothing of it to copy');
|
|
526
|
+
if (view !== undefined && view.next === undefined) {
|
|
527
|
+
const texts = view.changes.filter((change) => !('removed' in change));
|
|
528
|
+
const copy = await this.materialized(wanted, async () => ({ position: view.position, log_epoch: view.log_epoch, texts }));
|
|
529
|
+
return `${root}: copied to ${copy.repository}`;
|
|
530
|
+
}
|
|
531
|
+
const copy = await this.materialized(wanted, (directory) => this.chunked(root, authority.room_ref, directory));
|
|
532
|
+
const [caught] = await this.caughtUp([copy], true);
|
|
533
|
+
await succeeded(copy.repository, ['merge', '--ff-only', '-q', caught.house]);
|
|
534
|
+
return `${root}: copied to ${copy.repository}`;
|
|
431
535
|
}
|
|
432
|
-
async
|
|
433
|
-
|
|
434
|
-
|
|
536
|
+
async received(copy, authority) {
|
|
537
|
+
const root = rootOf(copy.room_handle);
|
|
538
|
+
const directory = join(copy.repository, '.git', STAGED_CHUNKS);
|
|
539
|
+
const scope = { write: authority.operations.write, protected: authority.protected_paths };
|
|
540
|
+
try {
|
|
541
|
+
const read = await this.chunked(root, copy.room_ref, directory);
|
|
542
|
+
const readOnly = await readOnlyFiles(copy.repository, copy.read_only);
|
|
543
|
+
for (const path of copy.read_only)
|
|
544
|
+
await readOnly.remove(path);
|
|
545
|
+
const commit = { message: `House ${root} at position ${read.position}`, from: copy.house, replaces: true };
|
|
546
|
+
const { house, revisions } = await importedWhole(copy.repository, scope, read.texts, commit, readOnly);
|
|
547
|
+
const next = {
|
|
548
|
+
...copy,
|
|
549
|
+
...scope,
|
|
550
|
+
house,
|
|
551
|
+
position: read.position,
|
|
552
|
+
log_epoch: read.log_epoch,
|
|
553
|
+
read_only: readOnly.held(),
|
|
554
|
+
manifests: { ...copy.manifests, [house]: { parent: null, files: revisions } },
|
|
555
|
+
};
|
|
556
|
+
await ignoreRules(copy.repository, Object.keys(revisions), next);
|
|
557
|
+
return next;
|
|
558
|
+
}
|
|
559
|
+
finally {
|
|
560
|
+
await rm(directory, { recursive: true, force: true });
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
async reread(copy) {
|
|
564
|
+
const { authorities } = await this.discovered([copy.room_handle]);
|
|
565
|
+
const authority = authorities.find((entry) => entry.room_ref === copy.room_ref);
|
|
566
|
+
if (authority === undefined)
|
|
567
|
+
throw new NotReady([copy.room_ref]);
|
|
568
|
+
return this.received(copy, authority);
|
|
569
|
+
}
|
|
570
|
+
async refreshed(copies, unready) {
|
|
571
|
+
const { bounds, authorities } = await this.discovered(copies.map((copy) => copy.room_handle));
|
|
572
|
+
const read = [];
|
|
573
|
+
const unchanged = [];
|
|
574
|
+
for (const copy of copies) {
|
|
575
|
+
const authority = authorities.find((entry) => entry.room_ref === copy.room_ref);
|
|
576
|
+
if (authority !== undefined &&
|
|
577
|
+
JSON.stringify([authority.operations.write, authority.protected_paths]) !== JSON.stringify([copy.write, copy.protected])) {
|
|
578
|
+
try {
|
|
579
|
+
read.push(await this.save(await this.received(copy, authority)));
|
|
580
|
+
}
|
|
581
|
+
catch (error) {
|
|
582
|
+
if (!(error instanceof NotReady))
|
|
583
|
+
throw error;
|
|
584
|
+
unready.push(...error.rooms);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
else {
|
|
588
|
+
unchanged.push(copy);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
for (const group of grouped(unchanged, bounds.max_prefixes))
|
|
592
|
+
await this.caughtUp(group, false, unready);
|
|
593
|
+
for (const group of grouped(read, bounds.max_prefixes))
|
|
594
|
+
await this.caughtUp(group, true, unready);
|
|
595
|
+
}
|
|
596
|
+
async caughtUp(copies, whole, unready) {
|
|
597
|
+
const caught = new Map(copies.map((copy) => [copy.key, copy]));
|
|
598
|
+
const read = new Set();
|
|
599
|
+
const waiting = unready ?? [];
|
|
600
|
+
let asking = [...copies];
|
|
601
|
+
while (asking.length > 0) {
|
|
435
602
|
let answer;
|
|
436
603
|
try {
|
|
437
|
-
answer = await this.house.
|
|
438
|
-
prefixes:
|
|
439
|
-
positions:
|
|
604
|
+
answer = await this.house.door('changes/enumerate', {
|
|
605
|
+
prefixes: asking.map((copy) => rootOf(copy.room_handle)),
|
|
606
|
+
positions: asking.map((copy) => ({ authority: copy.room_ref, position: copy.position, log_epoch: copy.log_epoch })),
|
|
440
607
|
});
|
|
441
608
|
}
|
|
442
609
|
catch (error) {
|
|
443
|
-
const
|
|
444
|
-
if (
|
|
445
|
-
return this.received(copy);
|
|
446
|
-
if (code !== 'replica_behind')
|
|
610
|
+
const expired = asking.find((copy) => copy.room_ref === expiredAuthority(error));
|
|
611
|
+
if (expired === undefined)
|
|
447
612
|
throw error;
|
|
448
|
-
|
|
449
|
-
|
|
613
|
+
asking = asking.filter((copy) => copy !== expired);
|
|
614
|
+
if (read.has(expired.key)) {
|
|
615
|
+
waiting.push(expired.room_ref);
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
read.add(expired.key);
|
|
619
|
+
try {
|
|
620
|
+
const next = await this.save(await this.reread(expired));
|
|
621
|
+
caught.set(expired.key, next);
|
|
622
|
+
asking.push(next);
|
|
623
|
+
}
|
|
624
|
+
catch (refused) {
|
|
625
|
+
if (!(refused instanceof NotReady))
|
|
626
|
+
throw refused;
|
|
627
|
+
waiting.push(expired.room_ref);
|
|
628
|
+
}
|
|
629
|
+
continue;
|
|
450
630
|
}
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
631
|
+
const advanced = [];
|
|
632
|
+
for (const copy of asking) {
|
|
633
|
+
const view = answer.authorities.find((entry) => entry.authority === copy.room_ref);
|
|
634
|
+
if (view === undefined || (view.position === copy.position && view.log_epoch === copy.log_epoch))
|
|
635
|
+
continue;
|
|
636
|
+
const next = await this.save(await this.incorporated(copy, view.changes, view.position, view.log_epoch));
|
|
637
|
+
caught.set(copy.key, next);
|
|
638
|
+
advanced.push(next);
|
|
639
|
+
}
|
|
640
|
+
asking = advanced.filter((copy) => whole || read.has(copy.key));
|
|
455
641
|
}
|
|
642
|
+
if (unready === undefined && waiting.length > 0)
|
|
643
|
+
throw new NotReady(waiting);
|
|
644
|
+
return copies.map((copy) => caught.get(copy.key));
|
|
456
645
|
}
|
|
457
646
|
async incorporated(copy, changes, position, logEpoch) {
|
|
458
647
|
const houseTree = await tree(copy.repository, copy.house);
|
|
@@ -485,7 +674,7 @@ export class LocalCopies {
|
|
|
485
674
|
let { house, manifests } = copy;
|
|
486
675
|
if (files.size > 0) {
|
|
487
676
|
house = await importCommits(copy.repository, [
|
|
488
|
-
{ message: `House ${rootOf(copy)} at position ${position}`, from: copy.house, files },
|
|
677
|
+
{ message: `House ${rootOf(copy.room_handle)} at position ${position}`, from: copy.house, files },
|
|
489
678
|
]);
|
|
490
679
|
manifests = { ...manifests, [house]: { parent: copy.house, files: revisions } };
|
|
491
680
|
}
|
|
@@ -515,9 +704,6 @@ export class LocalCopies {
|
|
|
515
704
|
}
|
|
516
705
|
copy = await this.save(without(copy));
|
|
517
706
|
}
|
|
518
|
-
if (!copy.active) {
|
|
519
|
-
return { refused: true, text: `${rootOf(copy)} is no longer synced to this Environment, so House takes no push from it` };
|
|
520
|
-
}
|
|
521
707
|
const listed = (await git(copy.repository, ['rev-list', '--topo-order', commit])).split('\n');
|
|
522
708
|
const base = listed.find((ancestor) => ancestor in copy.manifests);
|
|
523
709
|
if (base === undefined) {
|
|
@@ -528,7 +714,7 @@ export class LocalCopies {
|
|
|
528
714
|
changes = await this.derived(copy, base, commit);
|
|
529
715
|
}
|
|
530
716
|
catch (error) {
|
|
531
|
-
return { refused: true, text:
|
|
717
|
+
return { refused: true, text: houseCause(error) };
|
|
532
718
|
}
|
|
533
719
|
if (changes.length === 0)
|
|
534
720
|
return { refused: false, text: `Nothing to submit: ${short(commit)} matches House.` };
|
|
@@ -550,12 +736,24 @@ export class LocalCopies {
|
|
|
550
736
|
return this.settle(submitted, caller);
|
|
551
737
|
}
|
|
552
738
|
async derived(copy, base, commit) {
|
|
553
|
-
const root = rootOf(copy);
|
|
739
|
+
const root = rootOf(copy.room_handle);
|
|
554
740
|
const before = await tree(copy.repository, base);
|
|
555
741
|
const after = await tree(copy.repository, commit);
|
|
556
742
|
const moved = movedPaths(copy.moves, before, after);
|
|
557
743
|
const arrived = new Set(moved.values());
|
|
558
|
-
const
|
|
744
|
+
const arriving = [...after].filter(([path, entry]) => before.get(path) !== entry);
|
|
745
|
+
if (arriving.length > 0) {
|
|
746
|
+
const { bounds } = await this.house.door('rooms/discover', { prefixes: [root] });
|
|
747
|
+
const binary = [];
|
|
748
|
+
for (const [path, entry] of arriving) {
|
|
749
|
+
if (!(await isText(copy.repository, entry, bounds.max_authored_file_bytes)))
|
|
750
|
+
binary.push(path);
|
|
751
|
+
}
|
|
752
|
+
if (binary.length > 0)
|
|
753
|
+
throw new Error(textOnly(binary));
|
|
754
|
+
}
|
|
755
|
+
const text = (entry) => blobText(copy.repository, entry);
|
|
756
|
+
const model = await modelOf(copy, after);
|
|
559
757
|
const changes = [];
|
|
560
758
|
for (const path of [...new Set([...before.keys(), ...after.keys()])].sort()) {
|
|
561
759
|
if (arrived.has(path))
|
|
@@ -568,7 +766,7 @@ export class LocalCopies {
|
|
|
568
766
|
changes.push({ op: 'rename', path: `${root}/${path}`, to: `${root}/${to}`, base: known });
|
|
569
767
|
const moving = after.get(to);
|
|
570
768
|
if (moving !== prior) {
|
|
571
|
-
changes.push({ op: 'replace', path: `${root}/${to}`, base: known, content: await text(moving
|
|
769
|
+
changes.push({ op: 'replace', path: `${root}/${to}`, base: known, content: await text(moving) });
|
|
572
770
|
}
|
|
573
771
|
continue;
|
|
574
772
|
}
|
|
@@ -577,9 +775,9 @@ export class LocalCopies {
|
|
|
577
775
|
if (next === undefined)
|
|
578
776
|
changes.push({ op: 'remove', path: `${root}/${path}`, base: known });
|
|
579
777
|
else if (prior === undefined)
|
|
580
|
-
changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next
|
|
778
|
+
changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next) });
|
|
581
779
|
else
|
|
582
|
-
changes.push(...changed(`${root}/${path}`, path, known, await text(prior
|
|
780
|
+
changes.push(...changed(`${root}/${path}`, path, known, await text(prior), await text(next), model));
|
|
583
781
|
}
|
|
584
782
|
return changes;
|
|
585
783
|
}
|
|
@@ -606,12 +804,14 @@ export class LocalCopies {
|
|
|
606
804
|
const { upload, ...unstaged } = copy.push;
|
|
607
805
|
return this.settle(await this.save({ ...copy, push: unstaged }), caller, true);
|
|
608
806
|
}
|
|
609
|
-
if (outcome.refused.code === '
|
|
807
|
+
if (outcome.refused.code === 'expired')
|
|
610
808
|
return this.recovered(copy);
|
|
611
|
-
const rebased = rebaseFixes(outcome.refused);
|
|
612
809
|
let settled = await this.save(without(copy));
|
|
810
|
+
if (settled.unfollowed !== undefined)
|
|
811
|
+
return { refused: true, text: outcome.refused.text };
|
|
812
|
+
const rebased = rebaseFixes(outcome.refused);
|
|
613
813
|
try {
|
|
614
|
-
settled =
|
|
814
|
+
settled = (await this.caughtUp([settled], true))[0];
|
|
615
815
|
}
|
|
616
816
|
catch {
|
|
617
817
|
return {
|
|
@@ -630,10 +830,11 @@ export class LocalCopies {
|
|
|
630
830
|
}
|
|
631
831
|
async recovered(copy) {
|
|
632
832
|
const push = copy.push;
|
|
633
|
-
const current =
|
|
833
|
+
const current = (await this.caughtUp([copy], true))[0];
|
|
634
834
|
const house = await tree(copy.repository, current.house);
|
|
635
|
-
const root = rootOf(current);
|
|
636
|
-
|
|
835
|
+
const root = rootOf(current.room_handle);
|
|
836
|
+
const model = await modelOf(current, house);
|
|
837
|
+
if (!(await this.landed(copy.repository, push.changes, house, await tree(copy.repository, push.commit), model))) {
|
|
637
838
|
await this.save(without(current));
|
|
638
839
|
return {
|
|
639
840
|
refused: true,
|
|
@@ -646,7 +847,7 @@ export class LocalCopies {
|
|
|
646
847
|
written.push({
|
|
647
848
|
path: `${root}/${path}`,
|
|
648
849
|
revision: entry === undefined ? null : (revisionAt(current, current.house, path) ?? null),
|
|
649
|
-
content: entry === undefined ? null : await blobText(copy.repository, entry
|
|
850
|
+
content: entry === undefined ? null : await blobText(copy.repository, entry),
|
|
650
851
|
});
|
|
651
852
|
}
|
|
652
853
|
return this.finished(await this.save({ ...current, push: { ...push, state: 'accepted', written } }));
|
|
@@ -674,7 +875,7 @@ export class LocalCopies {
|
|
|
674
875
|
const push = copy.push;
|
|
675
876
|
let written = push.written;
|
|
676
877
|
if (push.changes.some((change) => change.op === 'rename')) {
|
|
677
|
-
copy =
|
|
878
|
+
copy = (await this.caughtUp([copy], true))[0];
|
|
678
879
|
const house = await tree(copy.repository, copy.house);
|
|
679
880
|
const sent = await tree(copy.repository, push.house);
|
|
680
881
|
if (push.changes.some((change) => change.op === 'rename' && !house.has(relative(change.to)))) {
|
|
@@ -688,9 +889,9 @@ export class LocalCopies {
|
|
|
688
889
|
written = [
|
|
689
890
|
...written,
|
|
690
891
|
{
|
|
691
|
-
path: `${rootOf(copy)}/${path}`,
|
|
892
|
+
path: `${rootOf(copy.room_handle)}/${path}`,
|
|
692
893
|
revision: entry === undefined ? null : (revisionAt(copy, copy.house, path) ?? null),
|
|
693
|
-
content: entry === undefined ? null : await blobText(copy.repository, entry
|
|
894
|
+
content: entry === undefined ? null : await blobText(copy.repository, entry),
|
|
694
895
|
},
|
|
695
896
|
];
|
|
696
897
|
}
|
|
@@ -708,7 +909,7 @@ export class LocalCopies {
|
|
|
708
909
|
}
|
|
709
910
|
const edits = new Map([...files].filter(([path, content]) => (content === null ? selected.has(path) : selected.get(path) !== blobId(content))));
|
|
710
911
|
const received = [...files.keys()].filter((path) => revisionAt(copy, copy.house, path) === revisionAt(copy, push.house, path));
|
|
711
|
-
const accepted = `House ${rootOf(copy)} with ${push.commit} accepted`;
|
|
912
|
+
const accepted = `House ${rootOf(copy.room_handle)} with ${push.commit} accepted`;
|
|
712
913
|
const house = await importCommits(copy.repository, [
|
|
713
914
|
...(edits.size === 0 ? [] : [{ message: accepted, from: push.commit, files: edits }]),
|
|
714
915
|
{
|
|
@@ -732,10 +933,10 @@ export class LocalCopies {
|
|
|
732
933
|
push: { ...push, acknowledged },
|
|
733
934
|
};
|
|
734
935
|
}
|
|
735
|
-
async landed(repository, changes, house, selected) {
|
|
936
|
+
async landed(repository, changes, house, selected, model) {
|
|
736
937
|
const text = async (path) => {
|
|
737
938
|
const entry = house.get(relative(path));
|
|
738
|
-
return entry === undefined ? undefined : blobText(repository, entry
|
|
939
|
+
return entry === undefined ? undefined : blobText(repository, entry);
|
|
739
940
|
};
|
|
740
941
|
for (const change of changes) {
|
|
741
942
|
const current = await text(change.path);
|
|
@@ -746,9 +947,8 @@ export class LocalCopies {
|
|
|
746
947
|
}
|
|
747
948
|
if ((change.op === 'create' || change.op === 'replace') && current === change.content)
|
|
748
949
|
continue;
|
|
749
|
-
const
|
|
750
|
-
|
|
751
|
-
if (document === null)
|
|
950
|
+
const document = current === undefined ? undefined : readDocument(current, relative(change.path), model)?.document;
|
|
951
|
+
if (document === undefined)
|
|
752
952
|
return false;
|
|
753
953
|
if (change.op === 'set_field' && JSON.stringify(document.fields[change.field]) === JSON.stringify(change.value))
|
|
754
954
|
continue;
|
|
@@ -761,7 +961,7 @@ export class LocalCopies {
|
|
|
761
961
|
return true;
|
|
762
962
|
}
|
|
763
963
|
async revisionText(path, wanted) {
|
|
764
|
-
const page = await this.house.
|
|
964
|
+
const page = await this.house.door('files/revisions/list', {
|
|
765
965
|
path,
|
|
766
966
|
revision: wanted,
|
|
767
967
|
});
|