@agentshouse/kit 0.2.1-cd9cbd8b6428c → 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 -49
- package/dist/acp.js +102 -108
- package/dist/afk.js +17 -0
- package/dist/agents.js +256 -69
- 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 +169 -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 +450 -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.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 -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 +40 -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 +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 -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,210 @@ 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
|
+
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);
|
|
383
479
|
await git(staging, ['update-ref', `refs/heads/${BRANCH}`, house]);
|
|
384
480
|
await git(staging, ['reset', '-q', '--hard']);
|
|
385
|
-
|
|
386
|
-
|
|
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 });
|
|
387
496
|
await rename(staging, repository);
|
|
388
497
|
}
|
|
389
498
|
catch (error) {
|
|
390
499
|
await rm(staging, { recursive: true, force: true });
|
|
391
500
|
throw error;
|
|
392
501
|
}
|
|
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
|
-
});
|
|
502
|
+
return this.save(copy);
|
|
409
503
|
}
|
|
410
|
-
async
|
|
411
|
-
const
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
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}`;
|
|
431
534
|
}
|
|
432
|
-
async
|
|
433
|
-
|
|
434
|
-
|
|
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) {
|
|
435
601
|
let answer;
|
|
436
602
|
try {
|
|
437
|
-
answer = await this.house.
|
|
438
|
-
prefixes:
|
|
439
|
-
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 })),
|
|
440
606
|
});
|
|
441
607
|
}
|
|
442
608
|
catch (error) {
|
|
443
|
-
const
|
|
444
|
-
if (
|
|
445
|
-
return this.received(copy);
|
|
446
|
-
if (code !== 'replica_behind')
|
|
609
|
+
const expired = asking.find((copy) => copy.room_ref === expiredAuthority(error));
|
|
610
|
+
if (expired === undefined)
|
|
447
611
|
throw error;
|
|
448
|
-
|
|
449
|
-
|
|
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;
|
|
450
629
|
}
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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));
|
|
455
640
|
}
|
|
641
|
+
if (unready === undefined && waiting.length > 0)
|
|
642
|
+
throw new NotReady(waiting);
|
|
643
|
+
return copies.map((copy) => caught.get(copy.key));
|
|
456
644
|
}
|
|
457
645
|
async incorporated(copy, changes, position, logEpoch) {
|
|
458
646
|
const houseTree = await tree(copy.repository, copy.house);
|
|
@@ -485,7 +673,7 @@ export class LocalCopies {
|
|
|
485
673
|
let { house, manifests } = copy;
|
|
486
674
|
if (files.size > 0) {
|
|
487
675
|
house = await importCommits(copy.repository, [
|
|
488
|
-
{ message: `House ${rootOf(copy)} at position ${position}`, from: copy.house, files },
|
|
676
|
+
{ message: `House ${rootOf(copy.room_handle)} at position ${position}`, from: copy.house, files },
|
|
489
677
|
]);
|
|
490
678
|
manifests = { ...manifests, [house]: { parent: copy.house, files: revisions } };
|
|
491
679
|
}
|
|
@@ -515,9 +703,6 @@ export class LocalCopies {
|
|
|
515
703
|
}
|
|
516
704
|
copy = await this.save(without(copy));
|
|
517
705
|
}
|
|
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
706
|
const listed = (await git(copy.repository, ['rev-list', '--topo-order', commit])).split('\n');
|
|
522
707
|
const base = listed.find((ancestor) => ancestor in copy.manifests);
|
|
523
708
|
if (base === undefined) {
|
|
@@ -528,7 +713,7 @@ export class LocalCopies {
|
|
|
528
713
|
changes = await this.derived(copy, base, commit);
|
|
529
714
|
}
|
|
530
715
|
catch (error) {
|
|
531
|
-
return { refused: true, text:
|
|
716
|
+
return { refused: true, text: houseCause(error) };
|
|
532
717
|
}
|
|
533
718
|
if (changes.length === 0)
|
|
534
719
|
return { refused: false, text: `Nothing to submit: ${short(commit)} matches House.` };
|
|
@@ -550,12 +735,24 @@ export class LocalCopies {
|
|
|
550
735
|
return this.settle(submitted, caller);
|
|
551
736
|
}
|
|
552
737
|
async derived(copy, base, commit) {
|
|
553
|
-
const root = rootOf(copy);
|
|
738
|
+
const root = rootOf(copy.room_handle);
|
|
554
739
|
const before = await tree(copy.repository, base);
|
|
555
740
|
const after = await tree(copy.repository, commit);
|
|
556
741
|
const moved = movedPaths(copy.moves, before, after);
|
|
557
742
|
const arrived = new Set(moved.values());
|
|
558
|
-
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);
|
|
559
756
|
const changes = [];
|
|
560
757
|
for (const path of [...new Set([...before.keys(), ...after.keys()])].sort()) {
|
|
561
758
|
if (arrived.has(path))
|
|
@@ -568,7 +765,7 @@ export class LocalCopies {
|
|
|
568
765
|
changes.push({ op: 'rename', path: `${root}/${path}`, to: `${root}/${to}`, base: known });
|
|
569
766
|
const moving = after.get(to);
|
|
570
767
|
if (moving !== prior) {
|
|
571
|
-
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) });
|
|
572
769
|
}
|
|
573
770
|
continue;
|
|
574
771
|
}
|
|
@@ -577,9 +774,9 @@ export class LocalCopies {
|
|
|
577
774
|
if (next === undefined)
|
|
578
775
|
changes.push({ op: 'remove', path: `${root}/${path}`, base: known });
|
|
579
776
|
else if (prior === undefined)
|
|
580
|
-
changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next
|
|
777
|
+
changes.push({ op: 'create', path: `${root}/${path}`, content: await text(next) });
|
|
581
778
|
else
|
|
582
|
-
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));
|
|
583
780
|
}
|
|
584
781
|
return changes;
|
|
585
782
|
}
|
|
@@ -606,12 +803,14 @@ export class LocalCopies {
|
|
|
606
803
|
const { upload, ...unstaged } = copy.push;
|
|
607
804
|
return this.settle(await this.save({ ...copy, push: unstaged }), caller, true);
|
|
608
805
|
}
|
|
609
|
-
if (outcome.refused.code === '
|
|
806
|
+
if (outcome.refused.code === 'expired')
|
|
610
807
|
return this.recovered(copy);
|
|
611
|
-
const rebased = rebaseFixes(outcome.refused);
|
|
612
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);
|
|
613
812
|
try {
|
|
614
|
-
settled =
|
|
813
|
+
settled = (await this.caughtUp([settled], true))[0];
|
|
615
814
|
}
|
|
616
815
|
catch {
|
|
617
816
|
return {
|
|
@@ -630,10 +829,11 @@ export class LocalCopies {
|
|
|
630
829
|
}
|
|
631
830
|
async recovered(copy) {
|
|
632
831
|
const push = copy.push;
|
|
633
|
-
const current =
|
|
832
|
+
const current = (await this.caughtUp([copy], true))[0];
|
|
634
833
|
const house = await tree(copy.repository, current.house);
|
|
635
|
-
const root = rootOf(current);
|
|
636
|
-
|
|
834
|
+
const root = rootOf(current.room_handle);
|
|
835
|
+
const model = await modelOf(current, house);
|
|
836
|
+
if (!(await this.landed(copy.repository, push.changes, house, await tree(copy.repository, push.commit), model))) {
|
|
637
837
|
await this.save(without(current));
|
|
638
838
|
return {
|
|
639
839
|
refused: true,
|
|
@@ -646,7 +846,7 @@ export class LocalCopies {
|
|
|
646
846
|
written.push({
|
|
647
847
|
path: `${root}/${path}`,
|
|
648
848
|
revision: entry === undefined ? null : (revisionAt(current, current.house, path) ?? null),
|
|
649
|
-
content: entry === undefined ? null : await blobText(copy.repository, entry
|
|
849
|
+
content: entry === undefined ? null : await blobText(copy.repository, entry),
|
|
650
850
|
});
|
|
651
851
|
}
|
|
652
852
|
return this.finished(await this.save({ ...current, push: { ...push, state: 'accepted', written } }));
|
|
@@ -674,7 +874,7 @@ export class LocalCopies {
|
|
|
674
874
|
const push = copy.push;
|
|
675
875
|
let written = push.written;
|
|
676
876
|
if (push.changes.some((change) => change.op === 'rename')) {
|
|
677
|
-
copy =
|
|
877
|
+
copy = (await this.caughtUp([copy], true))[0];
|
|
678
878
|
const house = await tree(copy.repository, copy.house);
|
|
679
879
|
const sent = await tree(copy.repository, push.house);
|
|
680
880
|
if (push.changes.some((change) => change.op === 'rename' && !house.has(relative(change.to)))) {
|
|
@@ -688,9 +888,9 @@ export class LocalCopies {
|
|
|
688
888
|
written = [
|
|
689
889
|
...written,
|
|
690
890
|
{
|
|
691
|
-
path: `${rootOf(copy)}/${path}`,
|
|
891
|
+
path: `${rootOf(copy.room_handle)}/${path}`,
|
|
692
892
|
revision: entry === undefined ? null : (revisionAt(copy, copy.house, path) ?? null),
|
|
693
|
-
content: entry === undefined ? null : await blobText(copy.repository, entry
|
|
893
|
+
content: entry === undefined ? null : await blobText(copy.repository, entry),
|
|
694
894
|
},
|
|
695
895
|
];
|
|
696
896
|
}
|
|
@@ -708,7 +908,7 @@ export class LocalCopies {
|
|
|
708
908
|
}
|
|
709
909
|
const edits = new Map([...files].filter(([path, content]) => (content === null ? selected.has(path) : selected.get(path) !== blobId(content))));
|
|
710
910
|
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`;
|
|
911
|
+
const accepted = `House ${rootOf(copy.room_handle)} with ${push.commit} accepted`;
|
|
712
912
|
const house = await importCommits(copy.repository, [
|
|
713
913
|
...(edits.size === 0 ? [] : [{ message: accepted, from: push.commit, files: edits }]),
|
|
714
914
|
{
|
|
@@ -732,10 +932,10 @@ export class LocalCopies {
|
|
|
732
932
|
push: { ...push, acknowledged },
|
|
733
933
|
};
|
|
734
934
|
}
|
|
735
|
-
async landed(repository, changes, house, selected) {
|
|
935
|
+
async landed(repository, changes, house, selected, model) {
|
|
736
936
|
const text = async (path) => {
|
|
737
937
|
const entry = house.get(relative(path));
|
|
738
|
-
return entry === undefined ? undefined : blobText(repository, entry
|
|
938
|
+
return entry === undefined ? undefined : blobText(repository, entry);
|
|
739
939
|
};
|
|
740
940
|
for (const change of changes) {
|
|
741
941
|
const current = await text(change.path);
|
|
@@ -746,9 +946,8 @@ export class LocalCopies {
|
|
|
746
946
|
}
|
|
747
947
|
if ((change.op === 'create' || change.op === 'replace') && current === change.content)
|
|
748
948
|
continue;
|
|
749
|
-
const
|
|
750
|
-
|
|
751
|
-
if (document === null)
|
|
949
|
+
const document = current === undefined ? undefined : readDocument(current, relative(change.path), model)?.document;
|
|
950
|
+
if (document === undefined)
|
|
752
951
|
return false;
|
|
753
952
|
if (change.op === 'set_field' && JSON.stringify(document.fields[change.field]) === JSON.stringify(change.value))
|
|
754
953
|
continue;
|
|
@@ -761,7 +960,7 @@ export class LocalCopies {
|
|
|
761
960
|
return true;
|
|
762
961
|
}
|
|
763
962
|
async revisionText(path, wanted) {
|
|
764
|
-
const page = await this.house.
|
|
963
|
+
const page = await this.house.door('files/revisions/list', {
|
|
765
964
|
path,
|
|
766
965
|
revision: wanted,
|
|
767
966
|
});
|