tryharness 0.7.45 → 0.7.54
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 +239 -14
- package/assets/dsh-plugin.mjs +72 -0
- package/assets/opencode-plugin.js +4 -3
- package/cli.mjs +497 -196
- package/lib/actorRoster.mjs +28 -5
- package/lib/adapters.mjs +165 -222
- package/lib/agentRuntimeConfig.mjs +36 -0
- package/lib/agentRuntimes.mjs +570 -0
- package/lib/agentSignIn.mjs +226 -0
- package/lib/atlas.mjs +7 -2
- package/lib/audit.mjs +643 -0
- package/lib/backupSetup.mjs +141 -0
- package/lib/boardAccess.mjs +8 -1
- package/lib/boardBackup.mjs +283 -0
- package/lib/boardCommands.mjs +5 -10
- package/lib/boardFileCommands.mjs +2 -1
- package/lib/boardMirror.mjs +523 -0
- package/lib/boardProtocol.json +263 -6
- package/lib/boardTools.mjs +2 -6
- package/lib/boardWaits.mjs +102 -0
- package/lib/book.mjs +659 -0
- package/lib/bridge.mjs +26 -4
- package/lib/browserWake.mjs +60 -0
- package/lib/cards.mjs +159 -16
- package/lib/cloudBoot.mjs +124 -0
- package/lib/commands.mjs +25 -5
- package/lib/connectionTools.d.ts +13 -0
- package/lib/connectionTools.js +45 -0
- package/lib/connectorAuth.mjs +309 -0
- package/lib/connectorCatalog.json +41 -0
- package/lib/connectorCommands.mjs +121 -0
- package/lib/connectorGoogle.mjs +513 -0
- package/lib/connectors.mjs +805 -0
- package/lib/context.mjs +18 -4
- package/lib/contractGate.mjs +377 -0
- package/lib/coordinator.mjs +152 -39
- package/lib/coreModels.mjs +78 -0
- package/lib/daemon.mjs +973 -54
- package/lib/desk.mjs +239 -0
- package/lib/desktop.mjs +113 -8
- package/lib/digest.mjs +32 -0
- package/lib/directLink.mjs +283 -0
- package/lib/environments.mjs +825 -0
- package/lib/folders.mjs +4 -4
- package/lib/gitHost.mjs +174 -0
- package/lib/goalCommands.mjs +58 -14
- package/lib/hookDialects.mjs +298 -0
- package/lib/inference.mjs +263 -152
- package/lib/landed.mjs +887 -0
- package/lib/lessons.mjs +6 -0
- package/lib/lineup.mjs +324 -0
- package/lib/live.mjs +284 -13
- package/lib/localmodels.mjs +10 -0
- package/lib/machineIdentity.mjs +3 -0
- package/lib/machineRoutes.mjs +40 -2
- package/lib/machineRuns.mjs +30 -3
- package/lib/machineSeal.mjs +69 -10
- package/lib/mcp-stdio.mjs +189 -120
- package/lib/mcpRelay.mjs +119 -0
- package/lib/members.json +26 -0
- package/lib/members.mjs +33 -0
- package/lib/modelMemory.mjs +100 -0
- package/lib/models.mjs +48 -15
- package/lib/museSession.mjs +122 -0
- package/lib/nativeHost.mjs +203 -0
- package/lib/neovim.mjs +126 -0
- package/lib/network.mjs +7 -2
- package/lib/nudge.mjs +57 -18
- package/lib/onboard.mjs +430 -1
- package/lib/oneclawLocal.mjs +150 -0
- package/lib/ownMachines.mjs +828 -39
- package/lib/pairing.mjs +182 -0
- package/lib/paths.mjs +8 -0
- package/lib/personModel.mjs +89 -0
- package/lib/phones.mjs +119 -3
- package/lib/placeCommands.mjs +27 -0
- package/lib/places.mjs +337 -9
- package/lib/plans.mjs +151 -27
- package/lib/profile.mjs +152 -0
- package/lib/projects.mjs +624 -137
- package/lib/readiness.mjs +400 -0
- package/lib/record.mjs +115 -0
- package/lib/repoLinks.mjs +354 -0
- package/lib/roomChannels.mjs +641 -0
- package/lib/runBrief.mjs +32 -2
- package/lib/runRequests.mjs +157 -0
- package/lib/runWorker.mjs +37 -9
- package/lib/runner.mjs +74 -11
- package/lib/secretPatterns.json +55 -0
- package/lib/secrets.mjs +10 -27
- package/lib/seen.mjs +102 -0
- package/lib/service.mjs +11 -6
- package/lib/sessionControl.mjs +386 -96
- package/lib/sessionIndex.mjs +5 -3
- package/lib/specialties.json +74 -0
- package/lib/specialties.mjs +477 -0
- package/lib/specialtyKeys.d.ts +3 -0
- package/lib/specialtyKeys.js +58 -0
- package/lib/specialtyNotice.mjs +147 -0
- package/lib/specialtySnapshot.mjs +138 -0
- package/lib/store.mjs +829 -29
- package/lib/subagents.mjs +8 -4
- package/lib/swarm.mjs +483 -37
- package/lib/swarmMemory.mjs +947 -0
- package/lib/t3.mjs +56 -17
- package/lib/taskCommands.mjs +91 -13
- package/lib/taskRuns.mjs +68 -11
- package/lib/team.json +253 -144
- package/lib/team.mjs +538 -147
- package/lib/threadLine.mjs +116 -0
- package/lib/threadRuns.mjs +78 -12
- package/lib/threadView.mjs +66 -16
- package/lib/tokenizer.mjs +405 -0
- package/lib/ui.mjs +16 -2
- package/lib/usageTotals.mjs +148 -0
- package/lib/vault.mjs +1144 -0
- package/lib/vaultCloud.mjs +117 -0
- package/lib/vaultCommands.mjs +201 -0
- package/lib/vaultTools.d.ts +12 -0
- package/lib/vaultTools.js +42 -0
- package/lib/windowAsks.mjs +42 -0
- package/lib/workFocus.mjs +59 -0
- package/lib/workLinks.mjs +90 -0
- package/lib/worktrees.mjs +51 -13
- package/package.json +10 -5
package/lib/context.mjs
CHANGED
|
@@ -35,6 +35,8 @@ const PACK_FILES = 8;
|
|
|
35
35
|
const POOL = 60;
|
|
36
36
|
const HISTORY_DAYS = 60;
|
|
37
37
|
const REFRESH_MS = 15 * 60_000;
|
|
38
|
+
// How long the background pass trusts which repository a folder is in; a new repository joins on the next asking.
|
|
39
|
+
const PLACE_KEPT_MS = 60 * 60_000;
|
|
38
40
|
const LEARN_EVERY_MS = 20 * 3_600_000;
|
|
39
41
|
// Vectors of the pieces packs search stay in memory while packs are being made, and go after this long without one.
|
|
40
42
|
const VECTORS_IDLE_MS = 5 * 60_000;
|
|
@@ -212,11 +214,22 @@ export function createContextEngine({
|
|
|
212
214
|
: repo.root;
|
|
213
215
|
return { root, top: repo.root };
|
|
214
216
|
};
|
|
217
|
+
// The background pass keeps each folder's place for a while: asking git blocks the daemon, and the pass asked three
|
|
218
|
+
// times for each of 683 sessions every 15 minutes, holding everything else (T3, the buddy, hooks) for up to 11 s
|
|
219
|
+
// (October 23, .harness-runs/measure/t3-probe). A brief's pack still asks fresh.
|
|
220
|
+
const keptPlaces = new Map();
|
|
221
|
+
const keptPlaceOf = (folder) => {
|
|
222
|
+
const kept = keptPlaces.get(folder);
|
|
223
|
+
if (kept && Date.now() - kept.at < PLACE_KEPT_MS) return kept.place;
|
|
224
|
+
const place = placeOf(folder);
|
|
225
|
+
keptPlaces.set(folder, { place, at: Date.now() });
|
|
226
|
+
return place;
|
|
227
|
+
};
|
|
215
228
|
|
|
216
229
|
const roots = () => [
|
|
217
230
|
...new Set(
|
|
218
231
|
known()
|
|
219
|
-
.map((place) =>
|
|
232
|
+
.map((place) => keptPlaceOf(place.path)?.root)
|
|
220
233
|
.filter(Boolean)
|
|
221
234
|
),
|
|
222
235
|
];
|
|
@@ -237,14 +250,15 @@ export function createContextEngine({
|
|
|
237
250
|
const trees = new Map();
|
|
238
251
|
let added = 0;
|
|
239
252
|
for (const session of store.sessionSources({ since })) {
|
|
240
|
-
const place = placeOf(session.cwd);
|
|
241
|
-
if (!place || !rootList.includes(place.root)) continue;
|
|
242
253
|
// A session whose source file the agent has since deleted is read from the relay's own copy, once.
|
|
243
254
|
let mtime = 0;
|
|
244
255
|
try {
|
|
245
256
|
mtime = fs.statSync(session.source).mtimeMs;
|
|
246
257
|
} catch {}
|
|
258
|
+
// Seen as it is now: nothing to read, and no need to ask git where it ran.
|
|
247
259
|
if (atlas.runSeen(session.agent, session.session_id) === mtime) continue;
|
|
260
|
+
const place = keptPlaceOf(session.cwd);
|
|
261
|
+
if (!place || !rootList.includes(place.root)) continue;
|
|
248
262
|
const trail = mtime
|
|
249
263
|
? await readTrail(session.agent, session.source)
|
|
250
264
|
: trailFromTranscript(
|
|
@@ -267,7 +281,7 @@ export function createContextEngine({
|
|
|
267
281
|
{
|
|
268
282
|
...trail,
|
|
269
283
|
cwd:
|
|
270
|
-
trail.cwd &&
|
|
284
|
+
trail.cwd && keptPlaceOf(trail.cwd)?.top === place.top
|
|
271
285
|
? path.join(place.root, path.relative(place.top, trail.cwd))
|
|
272
286
|
: trail.cwd,
|
|
273
287
|
},
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { MACHINE_RUNNERS, nameOf } from "./members.mjs";
|
|
3
|
+
import { onchainExecutors, treasurerOf } from "./book.mjs";
|
|
4
|
+
|
|
5
|
+
// The gate between building a contract and deploying it (docs/swarm-organization.md, "Contracts", Decision 34). Bankr
|
|
6
|
+
// builds and deploys as two asks, so its maker is not its only check:
|
|
7
|
+
//
|
|
8
|
+
// 1. Build: Bankr returns the source and the compiled code; the treasurer (or the person) files them in the book and
|
|
9
|
+
// code hashes the runtime code. Every verdict below is bound to that hash, so code filed again after a review is
|
|
10
|
+
// reviewed again.
|
|
11
|
+
// 2. Check: a coding agent tests it on a fork with no real funds.
|
|
12
|
+
// 3. Judge: a reviewer on a model other than the checker's; then the grant or the person approves.
|
|
13
|
+
// 4. Deploy: Bankr is asked to deploy exactly that code, and code reads what the chain holds at the address it reports
|
|
14
|
+
// and compares it with the code reviewed.
|
|
15
|
+
//
|
|
16
|
+
// Deploying needs the grant's code_deployment and financial_onchain classes, both off by default, as the person
|
|
17
|
+
// recorded them in the book. The gate before the action itself stays the mandate's reservation on Harness's server:
|
|
18
|
+
// nothing here moves money or widens what Harness's server allows. If Bankr can only build and deploy in one go, the
|
|
19
|
+
// first deploy goes to a testnet (`oneGo`), and the testnet's code is what is reviewed.
|
|
20
|
+
|
|
21
|
+
export const DEPLOY_CLASSES = ["code_deployment", "financial_onchain"];
|
|
22
|
+
// Test networks a one-go build may deploy to. Harness's server reads code on the ones it knows (chainReceipts.ts).
|
|
23
|
+
export const TESTNETS = ["base-sepolia", "sepolia"];
|
|
24
|
+
|
|
25
|
+
const now = () => new Date().toISOString();
|
|
26
|
+
const short = (value, limit) =>
|
|
27
|
+
typeof value === "string" ? value.trim().slice(0, limit) : "";
|
|
28
|
+
|
|
29
|
+
/** Runtime code as hex (with or without 0x), normalized, or null when it is not hex. */
|
|
30
|
+
function hexOf(code) {
|
|
31
|
+
const hex = short(code, 200_000).toLowerCase().replace(/^0x/, "");
|
|
32
|
+
return hex && hex.length % 2 === 0 && /^[0-9a-f]+$/.test(hex) ? hex : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The SHA-256 of runtime code's bytes, as Harness's server hashes the code it reads at an address. */
|
|
36
|
+
export const codeSha256 = (hex) =>
|
|
37
|
+
createHash("sha256").update(Buffer.from(hex, "hex")).digest("hex");
|
|
38
|
+
|
|
39
|
+
const contractRow = (store, id) =>
|
|
40
|
+
store.db.get("select * from book_contracts where id = ?", [String(id || "")]);
|
|
41
|
+
|
|
42
|
+
const strategyOf = (store, id) =>
|
|
43
|
+
store.db.get("select * from book_strategies where id = ?", [
|
|
44
|
+
String(id || ""),
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
// The classes the person recorded for the strategy's grant; an agent's record of a grant counts for nothing here.
|
|
48
|
+
const grantClasses = (strategy) =>
|
|
49
|
+
strategy?.grant_set_by === "user"
|
|
50
|
+
? JSON.parse(strategy.grant_classes || "[]")
|
|
51
|
+
: [];
|
|
52
|
+
|
|
53
|
+
const keeps = (store, agent) =>
|
|
54
|
+
agent === "user" || treasurerOf(store).agent === agent;
|
|
55
|
+
|
|
56
|
+
const update = (store, id, fields) => {
|
|
57
|
+
const names = Object.keys(fields);
|
|
58
|
+
store.db.run(
|
|
59
|
+
`update book_contracts set ${names.map((name) => `${name} = ?`).join(", ")}, version = version + 1, updated_at = ?
|
|
60
|
+
where id = ?`,
|
|
61
|
+
[...names.map((name) => fields[name]), now(), id]
|
|
62
|
+
);
|
|
63
|
+
return view(contractRow(store, id));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** A contract as agents and the person read it, without its source and code. */
|
|
67
|
+
export const view = (row) =>
|
|
68
|
+
row && {
|
|
69
|
+
id: row.id,
|
|
70
|
+
strategy: row.strategy_id,
|
|
71
|
+
name: row.name,
|
|
72
|
+
chain: row.chain,
|
|
73
|
+
oneGo: Boolean(row.one_go),
|
|
74
|
+
buildChain: row.build_chain,
|
|
75
|
+
status: row.status,
|
|
76
|
+
codeSha256: row.code_sha256,
|
|
77
|
+
codeBytes: row.code_bytes == null ? null : Number(row.code_bytes),
|
|
78
|
+
check: row.check_by
|
|
79
|
+
? {
|
|
80
|
+
by: row.check_by,
|
|
81
|
+
model: row.check_model,
|
|
82
|
+
sha256: row.check_sha256,
|
|
83
|
+
passed: Boolean(row.check_passed),
|
|
84
|
+
}
|
|
85
|
+
: null,
|
|
86
|
+
judge: row.judge_by
|
|
87
|
+
? {
|
|
88
|
+
by: row.judge_by,
|
|
89
|
+
model: row.judge_model,
|
|
90
|
+
sha256: row.judge_sha256,
|
|
91
|
+
accepted: Boolean(row.judge_accepted),
|
|
92
|
+
}
|
|
93
|
+
: null,
|
|
94
|
+
approvedBy: row.approved_by,
|
|
95
|
+
deployTask: row.deploy_task,
|
|
96
|
+
address: row.address,
|
|
97
|
+
deployedSha256: row.deployed_sha256,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/** A contract the desk will build: under a strategy in the book, for one chain. The treasurer or the person. */
|
|
101
|
+
export function startContract(
|
|
102
|
+
store,
|
|
103
|
+
agent,
|
|
104
|
+
{ strategy, name, chain, oneGo = false, buildChain = null }
|
|
105
|
+
) {
|
|
106
|
+
if (!keeps(store, agent))
|
|
107
|
+
return {
|
|
108
|
+
ok: false,
|
|
109
|
+
error: "the treasurer or the person starts a contract",
|
|
110
|
+
};
|
|
111
|
+
if (!strategyOf(store, strategy))
|
|
112
|
+
return { ok: false, error: "name the strategy in the book it is for" };
|
|
113
|
+
const title = short(name, 120);
|
|
114
|
+
const target = short(chain, 40).toLowerCase();
|
|
115
|
+
if (!title || !target)
|
|
116
|
+
return {
|
|
117
|
+
ok: false,
|
|
118
|
+
error: "a contract has a name and the chain it is for",
|
|
119
|
+
};
|
|
120
|
+
const testnet = short(buildChain, 40).toLowerCase() || null;
|
|
121
|
+
if (oneGo && !TESTNETS.includes(testnet))
|
|
122
|
+
return {
|
|
123
|
+
ok: false,
|
|
124
|
+
error: `Bankr builds and deploys in one go here, so its first deploy goes to a testnet: one of ${TESTNETS.join(", ")}`,
|
|
125
|
+
};
|
|
126
|
+
const id = randomUUID();
|
|
127
|
+
const at = now();
|
|
128
|
+
store.db.run(
|
|
129
|
+
`insert into book_contracts(id, strategy_id, name, chain, one_go, build_chain, status, written_by, version, created_at, updated_at)
|
|
130
|
+
values(?, ?, ?, ?, ?, ?, 'drafting', ?, 1, ?, ?)`,
|
|
131
|
+
[
|
|
132
|
+
id,
|
|
133
|
+
String(strategy),
|
|
134
|
+
title,
|
|
135
|
+
target,
|
|
136
|
+
oneGo ? 1 : 0,
|
|
137
|
+
oneGo ? testnet : null,
|
|
138
|
+
agent,
|
|
139
|
+
at,
|
|
140
|
+
at,
|
|
141
|
+
]
|
|
142
|
+
);
|
|
143
|
+
return { ok: true, contract: view(contractRow(store, id)) };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** The words of Bankr's build ask: source and compiled code back, and no deploy except to a testnet in one go. */
|
|
147
|
+
export function buildAsk(store, id) {
|
|
148
|
+
const row = contractRow(store, id);
|
|
149
|
+
if (!row) return null;
|
|
150
|
+
return row.one_go
|
|
151
|
+
? `Build the contract "${row.name}" and deploy it to ${row.build_chain} only, never to a main network. Return the full source, the compiled runtime bytecode as hex, the testnet address and the deploy transaction hash.`
|
|
152
|
+
: `Build the contract "${row.name}" for ${row.chain}. Do not deploy it. Return the full source and the compiled runtime bytecode as hex.`;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Bankr's build, filed by the treasurer or the person: the source and runtime code it returned. Code hashes the code;
|
|
157
|
+
* code filed again under a different hash clears every verdict given for the old one.
|
|
158
|
+
*/
|
|
159
|
+
export function fileBuild(
|
|
160
|
+
store,
|
|
161
|
+
agent,
|
|
162
|
+
{ contract, source, runtimeCode, buildTask = null, address = null }
|
|
163
|
+
) {
|
|
164
|
+
const row = contractRow(store, contract);
|
|
165
|
+
if (!row) return { ok: false, error: "no contract in the book has that id" };
|
|
166
|
+
if (!keeps(store, agent))
|
|
167
|
+
return {
|
|
168
|
+
ok: false,
|
|
169
|
+
error: "the treasurer or the person files Bankr's build",
|
|
170
|
+
};
|
|
171
|
+
if (row.deploy_task)
|
|
172
|
+
return {
|
|
173
|
+
ok: false,
|
|
174
|
+
error: "this contract was already asked to deploy; start a new one",
|
|
175
|
+
};
|
|
176
|
+
const hex = hexOf(runtimeCode);
|
|
177
|
+
if (!hex)
|
|
178
|
+
return {
|
|
179
|
+
ok: false,
|
|
180
|
+
error: "the runtime code is hex, as the compiler gives it",
|
|
181
|
+
};
|
|
182
|
+
const sha256 = codeSha256(hex);
|
|
183
|
+
const same = sha256 === row.code_sha256;
|
|
184
|
+
return {
|
|
185
|
+
ok: true,
|
|
186
|
+
contract: update(store, row.id, {
|
|
187
|
+
source: short(source, 200_000),
|
|
188
|
+
runtime_code: hex,
|
|
189
|
+
code_sha256: sha256,
|
|
190
|
+
code_bytes: hex.length / 2,
|
|
191
|
+
build_task: short(buildTask, 120) || row.build_task,
|
|
192
|
+
...(row.one_go && address
|
|
193
|
+
? { address: short(address, 64).toLowerCase() }
|
|
194
|
+
: {}),
|
|
195
|
+
...(same
|
|
196
|
+
? {}
|
|
197
|
+
: {
|
|
198
|
+
check_by: null,
|
|
199
|
+
check_model: null,
|
|
200
|
+
check_sha256: null,
|
|
201
|
+
check_passed: null,
|
|
202
|
+
judge_by: null,
|
|
203
|
+
judge_model: null,
|
|
204
|
+
judge_sha256: null,
|
|
205
|
+
judge_accepted: null,
|
|
206
|
+
approved_by: null,
|
|
207
|
+
approved_sha256: null,
|
|
208
|
+
}),
|
|
209
|
+
status: "built",
|
|
210
|
+
}),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Who may give a verdict on a contract: never the agent that executes onchain, and a verdict names the code it is for.
|
|
215
|
+
function verdictRefusal(row, agent, sha256) {
|
|
216
|
+
if (!row) return "no contract in the book has that id";
|
|
217
|
+
if (!row.code_sha256)
|
|
218
|
+
return "nothing is built yet; Bankr's build is filed first";
|
|
219
|
+
if (onchainExecutors().includes(agent))
|
|
220
|
+
return `${nameOf(agent)} built it, so it does not check or judge it`;
|
|
221
|
+
if (short(sha256, 64).toLowerCase() !== row.code_sha256)
|
|
222
|
+
return `that verdict is for other code: the code filed now has SHA-256 ${row.code_sha256}`;
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** The Check: a coding agent tested exactly this code on a fork with no real funds. */
|
|
227
|
+
export function fileCheck(store, agent, { contract, model, sha256, passed }) {
|
|
228
|
+
const row = contractRow(store, contract);
|
|
229
|
+
const refusal = verdictRefusal(row, agent, sha256);
|
|
230
|
+
if (refusal) return { ok: false, error: refusal };
|
|
231
|
+
if (!MACHINE_RUNNERS.includes(agent))
|
|
232
|
+
return {
|
|
233
|
+
ok: false,
|
|
234
|
+
error: "a coding agent on the person's computers checks a contract",
|
|
235
|
+
};
|
|
236
|
+
if (!short(model, 100))
|
|
237
|
+
return { ok: false, error: "a check names the model it ran on" };
|
|
238
|
+
return {
|
|
239
|
+
ok: true,
|
|
240
|
+
contract: update(store, row.id, {
|
|
241
|
+
check_by: agent,
|
|
242
|
+
check_model: short(model, 100),
|
|
243
|
+
check_sha256: row.code_sha256,
|
|
244
|
+
check_passed: passed === true ? 1 : 0,
|
|
245
|
+
judge_by: null,
|
|
246
|
+
judge_model: null,
|
|
247
|
+
judge_sha256: null,
|
|
248
|
+
judge_accepted: null,
|
|
249
|
+
status: passed === true ? "checked" : "sent_back",
|
|
250
|
+
}),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** The Judge: a reviewer on a model other than the checker's accepted exactly this code, or sent it back. */
|
|
255
|
+
export function fileJudge(store, agent, { contract, model, sha256, accepted }) {
|
|
256
|
+
const row = contractRow(store, contract);
|
|
257
|
+
const refusal = verdictRefusal(row, agent, sha256);
|
|
258
|
+
if (refusal) return { ok: false, error: refusal };
|
|
259
|
+
if (!row.check_passed || row.check_sha256 !== row.code_sha256)
|
|
260
|
+
return {
|
|
261
|
+
ok: false,
|
|
262
|
+
error: "it is judged after a check passes on this code",
|
|
263
|
+
};
|
|
264
|
+
const judgeModel = short(model, 100);
|
|
265
|
+
if (agent === row.check_by)
|
|
266
|
+
return { ok: false, error: "the checker does not judge its own check" };
|
|
267
|
+
if (
|
|
268
|
+
!judgeModel ||
|
|
269
|
+
judgeModel.toLowerCase() === String(row.check_model).toLowerCase()
|
|
270
|
+
)
|
|
271
|
+
return {
|
|
272
|
+
ok: false,
|
|
273
|
+
error: `the judge runs on a model other than the checker's (${row.check_model})`,
|
|
274
|
+
};
|
|
275
|
+
return {
|
|
276
|
+
ok: true,
|
|
277
|
+
contract: update(store, row.id, {
|
|
278
|
+
judge_by: agent,
|
|
279
|
+
judge_model: judgeModel,
|
|
280
|
+
judge_sha256: row.code_sha256,
|
|
281
|
+
judge_accepted: accepted === true ? 1 : 0,
|
|
282
|
+
status: accepted === true ? "judged" : "sent_back",
|
|
283
|
+
}),
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** The person's own approval of deploying exactly this code, kept with the contract as who approved it. */
|
|
288
|
+
export function approveDeploy(store, agent, { contract, sha256 }) {
|
|
289
|
+
const row = contractRow(store, contract);
|
|
290
|
+
if (!row) return { ok: false, error: "no contract in the book has that id" };
|
|
291
|
+
if (agent !== "user")
|
|
292
|
+
return { ok: false, error: "only the person approves a deploy" };
|
|
293
|
+
if (short(sha256, 64).toLowerCase() !== row.code_sha256)
|
|
294
|
+
return {
|
|
295
|
+
ok: false,
|
|
296
|
+
error: `that approval is for other code: the code filed now has SHA-256 ${row.code_sha256}`,
|
|
297
|
+
};
|
|
298
|
+
return {
|
|
299
|
+
ok: true,
|
|
300
|
+
contract: update(store, row.id, {
|
|
301
|
+
approved_by: "user",
|
|
302
|
+
approved_sha256: row.code_sha256,
|
|
303
|
+
}),
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Whether the reviewed code may be deployed now, and Bankr's deploy ask when it may: every step passed on the code
|
|
309
|
+
* filed now, approved by the grant or the person, under a grant the person recorded with both deploy classes.
|
|
310
|
+
*/
|
|
311
|
+
export function deployRequest(store, { contract }) {
|
|
312
|
+
const row = contractRow(store, contract);
|
|
313
|
+
if (!row)
|
|
314
|
+
return { ok: false, refusals: ["no contract in the book has that id"] };
|
|
315
|
+
const strategy = strategyOf(store, row.strategy_id);
|
|
316
|
+
const classes = grantClasses(strategy);
|
|
317
|
+
const hash = row.code_sha256;
|
|
318
|
+
const refusals = [
|
|
319
|
+
!hash && "nothing is built yet",
|
|
320
|
+
hash &&
|
|
321
|
+
!(row.check_passed && row.check_sha256 === hash) &&
|
|
322
|
+
"no check passed on the code filed now",
|
|
323
|
+
hash &&
|
|
324
|
+
!(row.judge_accepted && row.judge_sha256 === hash) &&
|
|
325
|
+
"no judge accepted the code filed now",
|
|
326
|
+
// The grant approves within its classes; Harness's server still asks the person when the grant says to.
|
|
327
|
+
!DEPLOY_CLASSES.every((name) => classes.includes(name)) &&
|
|
328
|
+
`the person's grant for this strategy does not allow ${DEPLOY_CLASSES.join(" and ")}`,
|
|
329
|
+
row.deploy_task && "it was already asked to deploy",
|
|
330
|
+
].filter(Boolean);
|
|
331
|
+
if (refusals.length) return { ok: false, refusals };
|
|
332
|
+
const from = row.build_task
|
|
333
|
+
? ` from your build in task ${row.build_task}`
|
|
334
|
+
: "";
|
|
335
|
+
return {
|
|
336
|
+
ok: true,
|
|
337
|
+
chain: row.chain,
|
|
338
|
+
sha256: hash,
|
|
339
|
+
ask: `Deploy the contract "${row.name}" on ${row.chain}: exactly the compiled runtime code${from}, ${row.code_bytes} bytes with SHA-256 ${hash}, as reviewed. Do not rebuild or change it. Report the deployed address and the transaction hash.`,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** The deploy ask went to Bankr as this task. */
|
|
344
|
+
export const markDeployAsked = (store, contract, taskId) =>
|
|
345
|
+
update(store, contract, { deploy_task: String(taskId), status: "deploying" });
|
|
346
|
+
|
|
347
|
+
/** The contract Bankr's deploy task was for, or null. */
|
|
348
|
+
export const contractOfDeploy = (store, taskId) =>
|
|
349
|
+
view(
|
|
350
|
+
store.db.get("select * from book_contracts where deploy_task = ?", [
|
|
351
|
+
String(taskId || ""),
|
|
352
|
+
])
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* What the chain holds at the deployed address against the code reviewed: `deployed` when its SHA-256 is the reviewed
|
|
357
|
+
* code's, `mismatch` otherwise, and `unread` while the chain cannot be read.
|
|
358
|
+
*/
|
|
359
|
+
export function verifyDeployment(store, { contract, address, deployedSha256 }) {
|
|
360
|
+
const row = contractRow(store, contract);
|
|
361
|
+
if (!row) return { ok: false, error: "no contract in the book has that id" };
|
|
362
|
+
const read = short(deployedSha256, 64).toLowerCase() || null;
|
|
363
|
+
const status = !read
|
|
364
|
+
? "unread"
|
|
365
|
+
: read === row.code_sha256
|
|
366
|
+
? "deployed"
|
|
367
|
+
: "mismatch";
|
|
368
|
+
return {
|
|
369
|
+
ok: status === "deployed",
|
|
370
|
+
status,
|
|
371
|
+
contract: update(store, row.id, {
|
|
372
|
+
address: short(address, 64).toLowerCase() || row.address,
|
|
373
|
+
deployed_sha256: read,
|
|
374
|
+
status: status === "unread" ? row.status : status,
|
|
375
|
+
}),
|
|
376
|
+
};
|
|
377
|
+
}
|