@north-light/cli 0.3.606 → 0.3.608
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/dist/clients/attach/viewer.js +504 -504
- package/dist/core/import/bundle/layout.d.ts +4 -5
- package/dist/core/import/bundle/layout.js +3 -4
- package/dist/core/import/export/dump.d.ts +1 -1
- package/dist/core/import/export/dump.js +4 -4
- package/dist/core/import/load/rewrite.js +9 -9
- package/package.json +2 -2
- package/packages/crouter-identity/package.json +1 -1
- package/runtime.lock.json +13 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** `bodies` (revision text, design-fleet D106) is copied like any table but dumped apart: its 667 MB do not fit one row file (
|
|
1
|
+
/** `bodies` (revision text, design-fleet D106) is copied like any table but dumped apart: its 667 MB do not fit one row file (a whole table as one string exceeds V8's string limit), so its rows
|
|
2
2
|
* travel as the part files named in `source.bodyParts` (see `rowKeys`), each written and read a line at a time (`RowFileWriter`, `rowLines`).
|
|
3
3
|
* Every row is canonical: `hash` is the sha256 of `text`, which holds no NUL. The exporter dumps only such rows and the lane refuses a bundle with any other (`stage`). */
|
|
4
4
|
export declare const BODIES_TABLE = "bodies";
|
|
@@ -66,13 +66,12 @@ export type PathMap = readonly PathMapEntry[];
|
|
|
66
66
|
/** Rewrite one path through the map: the longest matching prefix wins; a path under no prefix is returned unchanged. */
|
|
67
67
|
export declare function mapPath(map: PathMap, path: string): string;
|
|
68
68
|
export type RowObject = Record<string, unknown>;
|
|
69
|
-
/** Row-file codec: one JSON object per line, newline-terminated, zstd-compressed
|
|
70
|
-
export declare function encodeRows(rows: Iterable<RowObject>): Buffer;
|
|
69
|
+
/** Row-file codec: one JSON object per line, newline-terminated, zstd-compressed; written by `RowFileWriter`. */
|
|
71
70
|
export declare function decodeRows(data: Buffer | Uint8Array): RowObject[];
|
|
72
71
|
/** One JSON object per line, newline-terminated: the line `RowFileWriter.write` takes. */
|
|
73
72
|
export declare function rowLine(row: RowObject): string;
|
|
74
|
-
/** Writes a row file as a zstd stream, a line at a time, so no string larger than one line exists (
|
|
75
|
-
* ~512 MiB string limit for a large
|
|
73
|
+
/** Writes a row file as a zstd stream, a line at a time, so no string larger than one line exists (a whole file as one string is past V8's
|
|
74
|
+
* ~512 MiB string limit for a large table). `bytes` is the size of the JSON written so far, before compression. */
|
|
76
75
|
export declare class RowFileWriter {
|
|
77
76
|
private readonly zst;
|
|
78
77
|
private readonly finished;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var a=Object.defineProperty;var
|
|
2
|
-
`;return l(Buffer.from(e,"utf8"))}r(j,"encodeRows");function A(s){const e=_(s).toString("utf8");if(e==="")return[];if(!e.endsWith(`
|
|
1
|
+
var a=Object.defineProperty;var o=(s,e)=>a(s,"name",{value:e,configurable:!0});import{once as d}from"node:events";import{createWriteStream as u}from"node:fs";import{pipeline as f}from"node:stream/promises";import{createZstdCompress as m,createZstdDecompress as p,zstdDecompressSync as l}from"node:zlib";const _="bodies",h=["objects","documents","revisions","revision_parents","identities","jobs","custom_objects","context_sessions","environments","object_kinds","edges","watches","watch_subscriptions","exposures","rules","unresolved_links","nodes","sessions","worktrees","node_faults","waits","structured_requests","memory_reads","deleted_isolated_nodes","node_outcome_deliveries","run_events","messages","message_causes","deliveries","crons","cron_runs","daemon_actions","human_requests","human_action_deliveries","review_comments","review_comment_events","audit_rows","app_users","idempotency_keys","uploads","upload_uses","shares","provider_approvals","relations","charges","limits","conversation_parts","conversation_entries","profiles","bodies"],w=["grants"],E=[...h,...w],S={audit_rows:"id",review_comment_events:"seq",app_users:"uid"},z=["objects","revisions","watches","watch_subscriptions","sessions","waits","structured_requests","deliveries","run_events"],c={prefix:o(s=>`imports/${s}/`,"prefix"),rows:o((s,e)=>`imports/${s}/rows/${e}.jsonl.zst`,"rows"),source:o(s=>`imports/${s}/source.json`,"source"),manifest:o(s=>`imports/${s}/manifest.jsonl.zst`,"manifest"),nodeFiles:o((s,e)=>`imports/${s}/node-files/${e}.tar.zst`,"nodeFiles"),bodyRows:o((s,e)=>`imports/${s}/rows/bodies/${e}.jsonl.zst`,"bodyRows"),request:o((s,e)=>`requests/${s}/${e}`,"request")};function $(s,e,t){return e===_?(t.bodyParts??[]).map(r=>c.bodyRows(s,r)):[c.rows(s,e)]}o($,"rowKeys");function L(s,e){let t;for(const r of s)(e===r.from||e.startsWith(r.from.endsWith("/")?r.from:`${r.from}/`))&&(t===void 0||r.from.length>t.from.length)&&(t=r);return t===void 0?e:t.to+e.slice(t.from.length)}o(L,"mapPath");function j(s){const e=l(s).toString("utf8");if(e==="")return[];if(!e.endsWith(`
|
|
3
2
|
`))throw new Error("row file is truncated: the last line is not newline-terminated");return e.slice(0,-1).split(`
|
|
4
|
-
`).map(t=>JSON.parse(t))}
|
|
5
|
-
`}
|
|
3
|
+
`).map(t=>JSON.parse(t))}o(j,"decodeRows");function B(s){return`${JSON.stringify(s)}
|
|
4
|
+
`}o(B,"rowLine");class A{static{o(this,"RowFileWriter")}zst=m();finished;written=0;constructor(e){this.finished=f(this.zst,u(e)),this.finished.catch(()=>{})}get bytes(){return this.written}async write(e,t=Buffer.byteLength(e,"utf8")){this.written+=t,this.zst.write(e,"utf8")||await Promise.race([d(this.zst,"drain"),this.finished])}async close(){this.zst.end(),await this.finished}destroy(){this.zst.destroy()}}async function*D(s){const e=p({chunkSize:1048576});e.end(s);let t=[];for await(const r of e){let n=0;for(let i=r.indexOf(10,n);i!==-1;i=r.indexOf(10,n))t.push(r.subarray(n,i)),yield(t.length===1?t[0]:Buffer.concat(t)).toString("utf8"),t=[],n=i+1;n<r.length&&t.push(r.subarray(n))}if(t.length>0)throw new Error("row file is truncated: the last line is not newline-terminated")}o(D,"rowLines");export{_ as BODIES_TABLE,h as COPIED_TABLES,E as DUMPED_TABLES,S as KEY_MAPPED_TABLES,A as RowFileWriter,z as SEQ_TABLES,w as STAGED_ONLY_TABLES,c as bundleKeys,j as decodeRows,L as mapPath,$ as rowKeys,B as rowLine,D as rowLines};
|
|
@@ -31,4 +31,4 @@ export declare function dumpBodiesPre(out: string): Promise<{
|
|
|
31
31
|
parts: string[];
|
|
32
32
|
count: number;
|
|
33
33
|
}>;
|
|
34
|
-
export declare function dumpRows(out: string, kind: SourceJson['kind']): Promise<DumpResult>;
|
|
34
|
+
export declare function dumpRows(out: string, kind: SourceJson['kind'], maxPageRows?: number): Promise<DumpResult>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
2
|
-
JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = k.attnum) AS cols FROM pg_constraint c WHERE c.contype = 'p' AND c.connamespace = current_schema()::regnamespace`).all(),
|
|
3
|
-
WHERE d.source_path IS NOT NULL AND NOT EXISTS (SELECT 1 FROM revision_parents p WHERE p.parent = r.rev_id) ORDER BY d.object, r.number DESC, r.rev_id`).all(),
|
|
4
|
-
WHERE n.status IN ('active', 'idle') ORDER BY n.node_id`).all();return
|
|
1
|
+
var K=Object.defineProperty;var o=(e,r)=>K(e,"name",{value:r,configurable:!0});import{mkdirSync as M,readFileSync as $,writeFileSync as Q}from"node:fs";import{join as m}from"node:path";import{openDb as Z,withCanvasWrite as ee}from"../../canvas/db.js";import{hashOf as te}from"../../graph/bodies.js";import{personIdAsync as re}from"../../canvas/person.js";import{CANVAS_SCHEMA_VERSION as ne}from"../../canvas/schema-version.js";import{crtrVersion as ae}from"../../../shared/crtr-version.js";import{BODIES_TABLE as T,DUMPED_TABLES as k,RowFileWriter as v,SEQ_TABLES as oe,bundleKeys as se,rowLine as Y}from"../bundle/layout.js";import{inlineMessageBody as ie}from"./inline.js";const ce=16*1024*1024,le=8*1024*1024,j=32*1024*1024,he=500,W=5e3,N="bodies-pre.json",L=o(e=>`"${e.replace(/"/g,'""')}"`,"q");function de(e){try{const r=$(e,"utf8");return r.trim()===""?null:r}catch(r){if(r.code==="ENOENT")return null;throw r}}o(de,"readText");function pe(e,r){return new Error(`revision text ${e} is ${r} bytes; the import carries at most ${j} bytes of text per body`)}o(pe,"tooLarge");function ue(e){const r=te(e.text);if(r!==e.hash)throw new Error(`body ${e.hash} does not hash to its key (its text hashes to ${r}); upgrade and restart the daemon so its boot repair rekeys the row, then export again`)}o(ue,"assertCanonical");async function H(e,r,s,h){const n=m(r,"rows",T);M(n,{recursive:!0});const f=[];let i=null;const y=o(async()=>{const a=i;i=null,a!==null&&await a.close()},"close"),g=o(async a=>{ue(a);const E=Y(a),c=Buffer.byteLength(E,"utf8");if(i!==null&&i.bytes>0&&i.bytes+c>ce&&await y(),i===null){const d=`${s}-${f.length}`;i=new v(m(n,`${d}.jsonl.zst`)),f.push(d)}await i.write(E,c)},"add");try{for(let a=0;a<h.length;){const E=await e.prepare("SELECT hash, octet_length(text) AS n FROM bodies WHERE hash = ANY(?::text[]) ORDER BY hash").all(h.slice(a,a+W));let c=[],d=0;const R=o(async()=>{if(c.length===0)return;const u=await e.prepare("SELECT hash, text FROM bodies WHERE hash = ANY(?::text[]) ORDER BY hash").all(c);for(const w of u)await g(w);c=[],d=0},"fetchPage");for(const{hash:u,n:w}of E){const p=Number(w);if(p>j)throw pe(u,p);c.length>0&&d+p>le&&await R(),c.push(u),d+=p}await R(),a+=W}await y()}catch(a){throw i?.destroy(),a}return f}o(H,"writeBodyParts");const P=o(async e=>(await e.prepare("SELECT hash FROM bodies ORDER BY hash").all()).map(r=>r.hash),"allHashes");async function Ne(e){const r=await Z(),s=await P(r),h=await H(r,e,"pre",s),n={hashes:s,parts:h,count:s.length,canonical:!0};return Q(m(e,N),JSON.stringify(n)),{parts:h,count:s.length}}o(Ne,"dumpBodiesPre");function Ee(e){try{return JSON.parse($(m(e,N),"utf8"))}catch(r){if(r.code==="ENOENT")return{hashes:[],parts:[],count:0};throw r}}o(Ee,"readPre");function we(e,r){if(e.count===0&&e.parts.length===0)return;if(e.canonical!==!0)throw new Error(`${N} was written before bodies were checked against their keys; discard the export directory and run the pre-pause dump again`);const s=e.hashes.filter(h=>!r.has(h));if(s.length>0)throw new Error(`the pre-pause dump holds ${s.length} body row(s) the database no longer has (first: ${s[0]}); the boot repair ran after it. Discard the export directory and run the pre-pause dump again`)}o(we,"assertPreCurrent");async function Le(e,r,s=he){const h=await re();return M(m(e,"rows"),{recursive:!0}),ee(async n=>{await n.exec("SET TRANSACTION ISOLATION LEVEL REPEATABLE READ");const f=new Set((await n.prepareUncached("SELECT table_name FROM information_schema.tables WHERE table_schema = current_schema()").all()).map(t=>t.table_name)),i=k.filter(t=>!f.has(t));if(i.length>0)throw new Error(`the canvas database lacks tables the bundle needs: ${i.join(", ")}`);const y=await n.prepareUncached(`SELECT c.conrelid::regclass::text AS tbl, (SELECT array_agg(a.attname::text ORDER BY k.ord) FROM unnest(c.conkey) WITH ORDINALITY k(attnum, ord)
|
|
2
|
+
JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = k.attnum) AS cols FROM pg_constraint c WHERE c.contype = 'p' AND c.connamespace = current_schema()::regnamespace`).all(),g=new Map(y.map(t=>[t.tbl.replace(/"/g,"").replace(/^.*\./,""),t.cols])),a=await n.prepareUncached("SELECT table_name, column_name FROM information_schema.columns WHERE table_schema = current_schema() ORDER BY table_name, ordinal_position").all(),E=new Set(oe),c={};let d=0,R=0;for(const t of k.filter(_=>_!==T)){const _=E.has(t)?["seq"]:g.get(t),D=_!==void 0&&_.length>0?_.map(l=>`t.${L(l)}`):a.filter(l=>l.table_name===t).map(l=>`t.${L(l.column_name)}::text`);if(D.length===0)throw new Error(`table ${t} has no columns to order its dump by`);const b=new v(m(e,se.rows("",t).replace(/^imports\/\//,"")));let x=0;try{for(await n.exec(`DECLARE dump_cursor NO SCROLL CURSOR FOR SELECT row_to_json(t)::text AS j FROM ${L(t)} t ORDER BY ${D.join(", ")}`);;){const l=await n.prepareUncached(`FETCH FORWARD ${s} FROM dump_cursor`).all();for(const G of l){let O=JSON.parse(G.j);if(t==="messages"){const F=O.body_ref,I=ie(O,de);typeof F=="string"&&F.startsWith("/")&&(I===O?R+=1:d+=1),O=I}await b.write(Y(O))}if(x+=l.length,l.length<s)break}await n.exec("CLOSE dump_cursor"),await b.close()}catch(l){throw b.destroy(),l}c[t]=x}const u=(await n.prepare("SELECT value FROM canvas_meta WHERE key = 'install_id'").get())?.value;if(u===void 0)throw new Error("this canvas database has no install id");const w=await n.prepare("SELECT object FROM environments WHERE kind = 'machine' ORDER BY object LIMIT 1").get(),p={installId:u,kind:r,person:h,release:ae(),schemaVersion:ne,counts:c,...w===void 0?{}:{environmentObject:w.object}},q=await n.prepare("SELECT request_id, request_dir, file FROM human_requests ORDER BY request_id").all(),J=await n.prepare(`SELECT d.object, r.body_hash FROM documents d JOIN revisions r ON r.document = d.object
|
|
3
|
+
WHERE d.source_path IS NOT NULL AND NOT EXISTS (SELECT 1 FROM revision_parents p WHERE p.parent = r.rev_id) ORDER BY d.object, r.number DESC, r.rev_id`).all(),A={};for(const t of J)A[t.object]??=t.body_hash;const S=Ee(e),U=new Set(S.hashes),C=await P(n);we(S,new Set(C));const B=C.filter(t=>!U.has(t)),V=await H(n,e,"pause",B),z=S.count+B.length;c[T]=z,p.bodyParts=[...S.parts,...V];const X=await n.prepare(`SELECT n.node_id, r.grantee, n.cwd, w.path AS worktree FROM nodes n JOIN node_rows r ON r.node_id = n.node_id LEFT JOIN worktrees w ON w.node_id = n.node_id AND w.state = 'open'
|
|
4
|
+
WHERE n.status IN ('active', 'idle') ORDER BY n.node_id`).all();return p.shippedBodies=A,{source:p,requests:q.map(t=>({id:t.request_id,dir:t.request_dir,file:t.file})),runningNodes:X.map(t=>({node:t.node_id,app:t.grantee,cwd:t.cwd,worktree:t.worktree})),bodiesInlined:d,bodiesMissing:R}})}o(Le,"dumpRows");export{j as BODY_MAX_BYTES,ce as PART_JSON_BYTES,Ne as dumpBodiesPre,Le as dumpRows};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var h=Object.defineProperty;var l=(n,a)=>h(n,"name",{value:a,configurable:!0});import{createHash as g}from"node:crypto";import{ROOT_PROFILE_ID as j}from"../../profiles/manifest.js";import{substitutePerson as D}from"../../canvas/person.js";import{withCanvasWrite as A}from"../../canvas/db.js";import{ImportLaneError as _}from"./stage.js";import{q as T}from"./catalog.js";const I=[["rules","owner"],["messages","object_id"],["messages","actor_id"],["custom_objects","registered_by"],["nodes","app"],["nodes","profile_id"],["revisions","acting_app"],["relations","resource_id"],["relations","subject_id"],["crons","profile"],["profiles","environment_id"]],M=[["nodes","grant_id"],["crons","grant_id"]],
|
|
1
|
+
var h=Object.defineProperty;var l=(n,a)=>h(n,"name",{value:a,configurable:!0});import{createHash as g}from"node:crypto";import{ROOT_PROFILE_ID as j}from"../../profiles/manifest.js";import{substitutePerson as D}from"../../canvas/person.js";import{withCanvasWrite as A}from"../../canvas/db.js";import{ImportLaneError as _}from"./stage.js";import{q as T}from"./catalog.js";const I=[["rules","owner"],["messages","object_id"],["messages","actor_id"],["custom_objects","registered_by"],["nodes","app"],["nodes","profile_id"],["revisions","acting_app"],["relations","resource_id"],["relations","subject_id"],["crons","profile"],["profiles","environment_id"]],M=[["nodes","grant_id"],["crons","grant_id"]],S={identities:"object",documents:"object",jobs:"object",custom_objects:"object",context_sessions:"node",rules:"object"},H=["app","person","profile","repo"];function C(n){const a=new Map,o=l((c,d)=>{a.has(c)||a.set(c,new Set),a.get(c).add(d)},"add");for(const c of n.foreignKeys)c.parent==="objects"&&c.columns.length===1&&o(c.table,c.columns[0]);for(const[c,d]of I)o(c,d);return a}l(C,"objectIdColumns");const N=l((n,a)=>`${T(n)}.${T(a)}`,"sq"),E=l(async(n,a,...o)=>Number((await n.prepareUncached(a).run(...o)).changes),"run"),O=l(async(n,a,...o)=>await n.prepareUncached(a).all(...o),"rows");async function K(n){n.sourcePerson!==n.targetPerson&&await A(async a=>{await a.exec(`SET LOCAL search_path TO ${T(n.schema)}`),await D(a,n.sourcePerson,n.targetPerson)})}l(K,"rewritePerson");async function W(n,a,o,c,d){return o===null?void 0:(await n.prepareUncached(`SELECT id FROM ${N(a,"grants")} WHERE runtime = ? AND sub = ? AND grantee = ?`).get(o,c,d))?.id}l(W,"findFleetGrant");function F(n){return new _("id_map","grant_missing",`no grant in the target for: ${n.slice(0,10).join(", ")}; approve the app, then rerun`,{grantees:[...n]})}l(F,"grantMissing");async function Y(n,a){const{db:o,schema:c,target:d}=n,t=l(e=>N(c,e),"S"),m=l(e=>N(d,e),"T"),f={object:new Map,grant:new Map,kind:new Map};for(const[e,p]of a)f.object.set(e,p);const i=n.targetPerson.replace(/^user:/,"");for(const e of H){const p=e==="person"?"t.external_id = ?":e==="app"?"?::text IS NOT NULL":`EXISTS (SELECT 1 FROM ${m("relations")} r WHERE r.resource_type = 'crtr/object' AND r.resource_id = tobj.id AND r.relation = 'acts_for' AND r.subject_type = 'user' AND r.subject_id = ?)`,R=await O(o,`SELECT i.object AS src, t.object AS dst FROM ${t("identities")} i
|
|
2
2
|
JOIN ${t("objects")} so ON so.id = i.object AND so.type = ?
|
|
3
3
|
JOIN ${m("identities")} t ON t.scheme = i.scheme AND t.external_id = i.external_id
|
|
4
4
|
JOIN ${m("objects")} tobj ON tobj.id = t.object AND tobj.type = so.type
|
|
5
|
-
WHERE ${p}`,e,e==="person"?n.targetPerson:
|
|
6
|
-
WHERE o.owner = ? AND o.name = ? AND o.type = 'document' AND o.deleted_at IS NULL AND d.source_path IS NOT NULL`).get(
|
|
5
|
+
WHERE ${p}`,e,e==="person"?n.targetPerson:i);for(const{src:$,dst:L}of R)$!==L&&f.object.set($,L)}const r=await O(o,`SELECT o.id, o.owner, o.name, o.created_at FROM ${t("objects")} o JOIN ${t("documents")} d ON d.object = o.id WHERE d.source_path IS NOT NULL`);for(const e of r){const p=await o.prepareUncached(`SELECT o.id FROM ${m("objects")} o JOIN ${m("documents")} d ON d.object = o.id
|
|
6
|
+
WHERE o.owner = ? AND o.name = ? AND o.type = 'document' AND o.deleted_at IS NULL AND d.source_path IS NOT NULL`).get(f.object.get(e.owner)??e.owner,e.name);if(p!==void 0){f.object.set(e.id,p.id);continue}const R=n.shippedBodies[e.id];if(R===void 0)throw new _("id_map","bundle_invalid",`shipped document ${e.name} (${e.id}) has no counterpart in the target and source.json has no body for it`);const $=await o.prepareUncached(`SELECT o.id FROM ${m("objects")} o JOIN ${m("identities")} i ON i.object = o.id
|
|
7
7
|
WHERE o.type = 'person' AND i.scheme = 'user' AND i.external_id = ?
|
|
8
8
|
UNION ALL SELECT o.id FROM ${t("objects")} o JOIN ${t("identities")} i ON i.object = o.id
|
|
9
|
-
WHERE o.type = 'person' AND i.scheme = 'user' AND i.external_id = ? LIMIT 1`).get(n.targetPerson,n.targetPerson);if(
|
|
10
|
-
VALUES ('crtr/object', ?, 'acts_for', 'user', ?, '', 'crtr', ?) ON CONFLICT DO NOTHING`,e.id,
|
|
11
|
-
FROM ${t("_idmap")} m WHERE m.kind = 'grant' AND d.adapter_json::jsonb ->> 'adapter' = 'cron_spawn' AND d.adapter_json::jsonb #>> '{principal,grant_id}' = m.source`),await E(o,`DELETE FROM ${t("objects")} WHERE id IN ${b}`);for(const{name:e}of await
|
|
12
|
-
AND o.name <> ? AND (o.name = ? OR EXISTS (SELECT 1 FROM ${
|
|
13
|
-
WHERE c.${s} IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${t(r.parent)} p WHERE p.${
|
|
14
|
-
AND NOT EXISTS (SELECT 1 FROM ${
|
|
9
|
+
WHERE o.type = 'person' AND i.scheme = 'user' AND i.external_id = ? LIMIT 1`).get(n.targetPerson,n.targetPerson);if($===void 0)throw new _("id_map","bundle_invalid",`no person object for ${n.targetPerson}; cannot import shipped document ${e.name}`);await E(o,`UPDATE ${t("objects")} SET owner = ? WHERE id = ?`,$.id,e.id),await E(o,`DELETE FROM ${t("relations")} WHERE resource_type = 'crtr/object' AND resource_id = ? AND relation = 'reader' AND subject_type = 'user' AND subject_id = '*' AND subject_relation = ''`,e.id),await E(o,`INSERT INTO ${t("relations")} (resource_type, resource_id, relation, subject_type, subject_id, subject_relation, written_by, created_at)
|
|
10
|
+
VALUES ('crtr/object', ?, 'acts_for', 'user', ?, '', 'crtr', ?) ON CONFLICT DO NOTHING`,e.id,i,e.created_at),await E(o,`UPDATE ${t("documents")} SET source_path = NULL WHERE object = ?`,e.id),await E(o,`UPDATE ${t("revisions")} r SET body_hash = ? WHERE r.document = ? AND NOT EXISTS (SELECT 1 FROM ${t("revision_parents")} p WHERE p.parent = r.rev_id)`,R,e.id)}const s=await O(o,`SELECT id, sub, grantee FROM ${t("grants")} ORDER BY id`),u=[];for(const e of s){const p=await W(o,d,n.fleetRuntime,e.sub,e.grantee);p===void 0?u.push(e.grantee):f.grant.set(e.id,p)}if(u.length>0)throw F(u);await o.exec(`CREATE TABLE ${t("_idmap")} (kind text NOT NULL, source text NOT NULL, target text NOT NULL, PRIMARY KEY (kind, source))`);for(const[e,p]of[["object",f.object],["grant",f.grant]])for(const[R,$]of p)await E(o,`INSERT INTO ${t("_idmap")} (kind, source, target) VALUES (?, ?, ?)`,e,R,$);const b=`(SELECT source FROM ${t("_idmap")} WHERE kind = 'object')`;for(const[e,p]of Object.entries(S))await E(o,`DELETE FROM ${t(e)} WHERE ${p} IN ${b}`);await E(o,`DELETE FROM ${t("revision_parents")} WHERE child IN (SELECT rev_id FROM ${t("revisions")} WHERE document IN ${b})`),await E(o,`DELETE FROM ${t("revisions")} WHERE document IN ${b}`);for(const[e,p]of C(n.catalog))if(n.catalog.tables.has(e))for(const R of p)await w(o,t(e),R,"object",t("_idmap"));for(const[e,p]of M)await w(o,t(e),p,"grant",t("_idmap"));await E(o,`UPDATE ${t("daemon_actions")} d SET adapter_json = jsonb_set(d.adapter_json::jsonb, '{principal,grant_id}', to_jsonb(m.target))::text
|
|
11
|
+
FROM ${t("_idmap")} m WHERE m.kind = 'grant' AND d.adapter_json::jsonb ->> 'adapter' = 'cron_spawn' AND d.adapter_json::jsonb #>> '{principal,grant_id}' = m.source`),await E(o,`DELETE FROM ${t("objects")} WHERE id IN ${b}`),await E(o,`UPDATE ${t("objects")} SET name = ? WHERE type = 'person' AND name <> ? AND id IN (SELECT object FROM ${t("identities")} WHERE scheme = 'user' AND external_id = ?)`,i,i,n.targetPerson);for(const{name:e}of await O(o,`SELECT k.name FROM ${t("object_kinds")} k WHERE EXISTS (SELECT 1 FROM ${m("object_kinds")} t WHERE t.name = k.name)`))f.kind.set(e,e);return await E(o,`DELETE FROM ${t("object_kinds")} k WHERE EXISTS (SELECT 1 FROM ${m("object_kinds")} t WHERE t.name = k.name)`),f}l(Y,"rewriteIds");async function B(n){const{db:a,schema:o,target:c,targetPerson:d}=n,t=new Map,m=l(async(i,...r)=>await a.prepareUncached(i).get(...r),"row"),f=l(i=>E(a,`DELETE FROM ${N(o,"profiles")} WHERE id = ?`,i),"dropStaged");for(const{id:i}of await O(a,`SELECT id FROM ${N(o,"profiles")} ORDER BY id`)){let r=i===j?await m(`SELECT id, person FROM ${N(c,"profiles")} WHERE person = ? AND name = 'root'`,d):await m(`SELECT id, person FROM ${N(c,"profiles")} WHERE id = ? AND person = ?`,i,d);if(r===void 0){if(await m(`SELECT id, person FROM ${N(c,"profiles")} WHERE id = ?`,i)===void 0&&i!==j)continue;const b=`${i.replace(/-[0-9a-f]{8}$/,"")}-${g("sha256").update(`${d}\0${i}`).digest("hex").slice(0,8)}`,e=await m(`SELECT id, person FROM ${N(c,"profiles")} WHERE id = ?`,b);if(e!==void 0&&e.person!==d)throw new _("id_map","unique_conflict",`profiles ${b} is held by another person in the target`,{table:"profiles",values:[b]});r=e??{id:b,person:d},e===void 0?await E(a,`UPDATE ${N(o,"profiles")} SET id = ? WHERE id = ?`,b,i):await f(i)}else await f(i);const s=r.id;await E(a,`UPDATE ${N(o,"objects")} o SET name = ? WHERE o.type = 'profile' AND o.id IN (SELECT object FROM ${N(o,"identities")} WHERE scheme = 'profile' AND external_id = ?)
|
|
12
|
+
AND o.name <> ? AND (o.name = ? OR EXISTS (SELECT 1 FROM ${N(c,"objects")} t WHERE t.type = 'profile' AND t.name = o.name AND t.home_machine IS NULL AND t.id <> o.id))`,s,i,s,i),await E(a,`UPDATE ${N(o,"identities")} SET external_id = ? WHERE scheme = 'profile' AND external_id = ? AND object IN (SELECT id FROM ${N(o,"objects")} WHERE type = 'profile')`,s,i),s!==i&&t.set(i,s)}return t}l(B,"mapProfileIds");async function w(n,a,o,c,d){await E(n,`UPDATE ${a} t SET ${T(o)} = m.target FROM ${d} m WHERE m.kind = ? AND t.${T(o)} = m.source`,c)}l(w,"remap");async function X(n){const{db:a,schema:o,target:c,catalog:d}=n,t=l(r=>N(o,r),"S"),m={},f=l((r,s)=>{s>0&&(m[r]=(m[r]??0)+s)},"count");await a.exec(`CREATE TABLE ${t("_dropped")} (tbl text NOT NULL, key text NOT NULL, PRIMARY KEY (tbl, key))`);const i=`(SELECT id FROM ${t("objects")} WHERE home_machine IS NOT NULL)`;await E(a,`INSERT INTO ${t("_dropped")} SELECT 'objects', id FROM ${t("objects")} WHERE home_machine IS NOT NULL`);for(const[r,s]of Object.entries(S))f(r,await E(a,`DELETE FROM ${t(r)} WHERE ${s} IN ${i}`));for(f("objects",await E(a,`DELETE FROM ${t("objects")} WHERE home_machine IS NOT NULL`));;){let r=0;for(const s of d.foreignKeys){if(s.columns.length!==1||s.parentColumns.length!==1||!n.catalog.tables.has(s.table))continue;const u=d.tables.get(s.table),b=T(s.columns[0]),e=u.primaryKey.length===1?T(u.primaryKey[0]):null;e!==null&&await E(a,`INSERT INTO ${t("_dropped")} SELECT ?, ${e}::text FROM ${t(s.table)} WHERE ${b} IN (SELECT key FROM ${t("_dropped")} WHERE tbl = ?) ON CONFLICT DO NOTHING`,s.table,s.parent);const p=await E(a,`DELETE FROM ${t(s.table)} WHERE ${b} IN (SELECT key FROM ${t("_dropped")} WHERE tbl = ?)`,s.parent);f(s.table,p),r+=p}if(r===0)break}for(const r of d.foreignKeys){if(r.columns.length!==1||!d.tables.has(r.table))continue;const s=T(r.columns[0]),u=T(r.parentColumns[0]),b=await O(a,`SELECT DISTINCT c.${s}::text AS value FROM ${t(r.table)} c
|
|
13
|
+
WHERE c.${s} IS NOT NULL AND NOT EXISTS (SELECT 1 FROM ${t(r.parent)} p WHERE p.${u} = c.${s})
|
|
14
|
+
AND NOT EXISTS (SELECT 1 FROM ${N(c,r.parent)} p WHERE p.${u} = c.${s}) LIMIT 10`);if(b.length>0)throw new _("drop","bundle_invalid",`${r.table}.${r.columns[0]} names rows that exist nowhere: ${b.map(e=>e.value).join(", ")}`,{table:r.table,column:r.columns[0],values:b.map(e=>e.value)})}return m}l(X,"dropStubRows");export{I as OBJECT_ID_COLUMNS,X as dropStubRows,W as findFleetGrant,F as grantMissing,B as mapProfileIds,C as objectIdColumns,Y as rewriteIds,K as rewritePerson};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.608",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
},
|
|
146
146
|
"license": "UNLICENSED",
|
|
147
147
|
"dependencies": {
|
|
148
|
-
"@north-light/identity": "0.3.
|
|
148
|
+
"@north-light/identity": "0.3.608",
|
|
149
149
|
"@earendil-works/chord": "1.1.0",
|
|
150
150
|
"@earendil-works/pi-agent-core": "1.1.0",
|
|
151
151
|
"@earendil-works/pi-ai": "1.1.0",
|
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.608",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.608",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"@milkdown/preset-gfm": "^7.22.3",
|
|
29
29
|
"@milkdown/prose": "^7.22.3",
|
|
30
30
|
"@milkdown/utils": "^7.22.3",
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.608",
|
|
32
32
|
"cron-parser": "^5.6.0",
|
|
33
33
|
"esbuild": "^0.27.7",
|
|
34
34
|
"jose": "^6.2.12",
|
|
@@ -11956,17 +11956,17 @@
|
|
|
11956
11956
|
},
|
|
11957
11957
|
"packages/crouter-api": {
|
|
11958
11958
|
"name": "@north-light/api",
|
|
11959
|
-
"version": "0.3.
|
|
11959
|
+
"version": "0.3.608",
|
|
11960
11960
|
"license": "UNLICENSED"
|
|
11961
11961
|
},
|
|
11962
11962
|
"packages/crouter-env-docker": {
|
|
11963
11963
|
"name": "@north-light/env-docker",
|
|
11964
|
-
"version": "0.3.
|
|
11964
|
+
"version": "0.3.608",
|
|
11965
11965
|
"license": "UNLICENSED"
|
|
11966
11966
|
},
|
|
11967
11967
|
"packages/crouter-identity": {
|
|
11968
11968
|
"name": "@north-light/identity",
|
|
11969
|
-
"version": "0.3.
|
|
11969
|
+
"version": "0.3.608",
|
|
11970
11970
|
"license": "UNLICENSED",
|
|
11971
11971
|
"dependencies": {
|
|
11972
11972
|
"jose": "^6.2.1"
|
|
@@ -11974,21 +11974,21 @@
|
|
|
11974
11974
|
},
|
|
11975
11975
|
"packages/crouter-plugin": {
|
|
11976
11976
|
"name": "@north-light/plugin",
|
|
11977
|
-
"version": "0.3.
|
|
11977
|
+
"version": "0.3.608",
|
|
11978
11978
|
"license": "UNLICENSED",
|
|
11979
11979
|
"dependencies": {
|
|
11980
|
-
"@north-light/api": "0.3.
|
|
11981
|
-
"@north-light/identity": "0.3.
|
|
11980
|
+
"@north-light/api": "0.3.608",
|
|
11981
|
+
"@north-light/identity": "0.3.608"
|
|
11982
11982
|
}
|
|
11983
11983
|
},
|
|
11984
11984
|
"packages/crouter-sdk": {
|
|
11985
11985
|
"name": "@north-light/sdk",
|
|
11986
|
-
"version": "0.3.
|
|
11986
|
+
"version": "0.3.608",
|
|
11987
11987
|
"license": "UNLICENSED",
|
|
11988
11988
|
"dependencies": {
|
|
11989
|
-
"@north-light/api": "0.3.
|
|
11990
|
-
"@north-light/identity": "0.3.
|
|
11991
|
-
"@north-light/plugin": "0.3.
|
|
11989
|
+
"@north-light/api": "0.3.608",
|
|
11990
|
+
"@north-light/identity": "0.3.608",
|
|
11991
|
+
"@north-light/plugin": "0.3.608",
|
|
11992
11992
|
"jose": "^6.2.1"
|
|
11993
11993
|
},
|
|
11994
11994
|
"bin": {
|