@north-light/cli 0.3.748 → 0.3.749
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/chrome/canvas-panels.d.ts +2 -0
- package/dist/clients/attach/chrome/canvas-panels.js +1 -1
- package/dist/clients/attach/chrome/roster.d.ts +2 -0
- package/dist/clients/attach/chrome/roster.js +5 -5
- package/dist/clients/attach/chrome/run-facts.d.ts +12 -0
- package/dist/clients/attach/chrome/run-facts.js +1 -0
- package/dist/clients/attach/chrome/widgets.d.ts +3 -1
- package/dist/clients/attach/chrome/widgets.js +1 -1
- package/dist/clients/attach/viewer.js +487 -487
- package/dist/core/canvas/canvas.js +16 -16
- package/dist/core/canvas/schema-pg/036-ledger-holder-app-path.sql +13 -0
- package/dist/core/canvas/schema-version.d.ts +1 -1
- package/dist/core/canvas/schema-version.js +1 -1
- package/dist/core/command.d.ts +1 -1
- package/dist/core/command.js +6 -6
- package/dist/core/graph/reader.js +1 -1
- package/dist/core/peer/envelope.js +1 -1
- package/dist/core/peer/stubs.js +1 -1
- package/dist/core/permissions/ceiling.js +10 -10
- package/dist/core/permissions/evaluator.js +2 -2
- package/dist/core/runtime/recap.js +6 -6
- package/dist/daemon/api/handlers/providers.d.ts +2 -0
- package/dist/daemon/api/handlers/providers.js +1 -1
- package/dist/daemon/peer/authority.d.ts +1 -1
- package/dist/daemon/peer/authority.js +1 -1
- package/package.json +4 -4
- package/packages/crouter-api/dist/clients/attach/chrome/canvas-panels.js +19 -1
- package/packages/crouter-api/dist/clients/attach/chrome/roster.js +1 -0
- package/packages/crouter-api/dist/clients/attach/chrome/run-facts.js +76 -0
- package/packages/crouter-api/dist/clients/attach/chrome/widgets.js +14 -5
- package/packages/crouter-api/dist/clients/attach/viewer.js +7 -1
- package/packages/crouter-api/dist/core/canvas/canvas.js +2 -1
- package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
- package/packages/crouter-api/dist/core/command.js +4 -3
- package/packages/crouter-api/dist/core/graph/reader.js +1 -1
- package/packages/crouter-api/dist/core/peer/envelope.js +2 -1
- package/packages/crouter-api/dist/core/peer/stubs.js +5 -1
- package/packages/crouter-api/dist/core/permissions/ceiling.js +4 -0
- package/packages/crouter-api/dist/core/permissions/evaluator.js +13 -4
- package/packages/crouter-api/dist/daemon/api/handlers/providers.js +5 -1
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/dist/index.d.ts +8 -0
- package/packages/crouter-identity/dist/index.js +18 -0
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
- package/scripts/lib/install-source.mjs +5 -1
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
var j=Object.defineProperty;var s=(t,e)=>j(t,"name",{value:e,configurable:!0});import{covers as
|
|
2
|
-
WHERE g.resolved_scopes_json::jsonb @> '[{"scope":"crtr:memory:manage:user","mode":"always"}]'::jsonb`).all()).map(n=>n.id)}s(
|
|
1
|
+
var j=Object.defineProperty;var s=(t,e)=>j(t,"name",{value:e,configurable:!0});import{parsePrincipal as x}from"@north-light/identity";import{covers as R}from"@north-light/identity";import{isCloudRole as F}from"../canvas/person-state.js";import{eligiblePackageApps as M}from"../packages/eligibility.js";import{subjectSet as U}from"./evaluator.js";import{FALSE as g,TRUE as H,and as k,f as h,or as T,raw as c}from"./sql.js";const J=s(t=>({ownApp:t,roots:[],namespaces:[],place:null,predicates:{allNodes:!1,spaces:!1},authorApps:[],packageApps:null}),"empty");async function L(t,e){return(await t.prepare("SELECT external_id FROM identities WHERE object = ? ORDER BY scheme LIMIT 1").get(e))?.external_id??null}s(L,"externalId");async function D(t,e,n){return(await t.prepare("SELECT o.id FROM identities i JOIN objects o ON o.id = i.object WHERE i.scheme = ? AND i.external_id = ? AND o.deleted_at IS NULL").get(e,n))?.id??null}s(D,"objectOf");async function P(t){return(await t.prepare("SELECT id FROM objects WHERE type = 'person' AND home_machine IS NULL AND deleted_at IS NULL ORDER BY created_at").all()).map(n=>n.id)}s(P,"personObjectIds");async function X(t){return(await t.prepare(`SELECT DISTINCT i.object AS id FROM grants g JOIN identities i ON i.external_id = g.grantee AND i.scheme = 'app'
|
|
2
|
+
WHERE g.resolved_scopes_json::jsonb @> '[{"scope":"crtr:memory:manage:user","mode":"always"}]'::jsonb`).all()).map(n=>n.id)}s(X,"firstPartyApps");function I(t,e){return z(t).has(e.replace(/^app:/,""))}s(I,"holdsProviderGroup");const W=new WeakMap;function z(t){let e=W.get(t);if(e===void 0){e=new Set;for(const n of t){const o=n.indexOf(":");o>=0&&!n.includes(":",o+1)&&e.add(n.slice(0,o))}W.set(t,e)}return e}s(z,"providerGroupHolders");function Y(t){return t.class==="object"?t.repos.map(e=>e.id):t.class!=="node"?[]:[...new Set([...t.repos,...t.projectRepos].map(e=>e.id))]}s(Y,"repoRoots");async function Z(t,e){return e===null?[]:(await U(t,e)).groupIds.filter(n=>n.startsWith("group:")).map(n=>n.slice(6))}s(Z,"memberGroups");async function V(t,e,n){if(e.class==="person")return null;const o=e.scopes;return await M(t,{holdsProvider:s(f=>o!==null&&I(o,f),"holdsProvider"),cloud:F(),ownExt:await L(t,e.app.id),user:n})}s(V,"readablePackageApps");async function ie(t,e,n,o,f={}){if(e.class==="person")return null;const a=J(e.app.id),r=e.scopes,E=s(i=>r!==null&&r.some(p=>R(p,i)),"has"),l=await L(t,e.app.id),w=e.class==="node"?await _(t,e.node.id):e.place??null;a.place=w,a.authorApps=[e.app.id];const N=o==="write"?"rw":"read",m=e.launched,d=s((i,p,u=!0)=>{a.roots.push({id:i,private:u,match:p})},"own");if(o==="message"||m===void 0||m===null||l===null||m.some(i=>R(i,`crtr:memory:${N}:${l}`)))d(e.app.id,"any"),l!==null&&(a.namespaces=await G(t,l));else{d(e.app.id,"non-document"),o==="read"&&w!==null&&d(e.app.id,"run-report");for(const i of await t.prepare("SELECT o.id, i.external_id FROM objects o JOIN identities i ON i.object = o.id AND i.scheme = 'profile' WHERE o.owner = ? AND o.type = 'profile' AND o.deleted_at IS NULL").all(e.app.id))m.some(p=>R(p,`crtr:memory:${N}:${l}:profile:${i.external_id}`))&&d(i.id,"no-node")}if(o==="read"&&(a.packageApps=await V(t,e,n)??[]),o==="read"&&w===null&&d(e.app.id,"run-node",!1),r===null)return a;a.predicates.spaces=!0;const A=await P(t),y=E("crtr:memory:manage:user"),C=y||E("crtr:memory:read_private:user"),S=s((i,p)=>{for(const u of A)u!==e.app.id&&a.roots.push({id:u,private:p,match:i})},"addPerson");if(o==="write")if(y)S("any",!0);else{E("crtr:memory:rw:user")&&(S("self",!0),S("authored:*",!0));for(const i of r){const p=/^crtr:memory:rw:user:(.+)$/.exec(i);p!==null&&S(`authored:${p[1]}`,!0)}E("crtr:objects:write:user")&&S("any",!0),a.roots.some(i=>i.match.startsWith("authored:"))&&a.authorApps.push(...await X(t))}else o==="read"&&(y?S("any",!0):S("direct-doc",C),E(`crtr:objects:${f.verb??"read"}:user`)&&S("any",C));const v=o==="write"?"write":f.verb??"read",b=e.class==="object"&&e.object.type.includes("."),$=s(async(i,p)=>{const u=x(i);if(u?.kind!=="app"||u.path.length>0)return;const O=await D(t,"app",i);O===null||O===e.app.id||a.roots.push({id:O,private:I(r,i),match:p})},"appRoot");for(const i of r){if(!i.startsWith("crtr:"))continue;let p=/^crtr:memory:(read|rw):app:([A-Za-z0-9_-]{1,64})(?::profile:([A-Za-z0-9_-]{1,64}))?$/.exec(i);if(p!==null&&(o==="read"||o==="write"&&p[1]==="rw")){if(p[3]===void 0)await $(`app:${p[2]}`,"no-node");else{const u=await D(t,"profile",p[3]);u!==null&&a.roots.push({id:u,private:!1,match:"no-node"})}continue}if(p=/^crtr:objects:(read|watch|link|write):(user|node|profile:[A-Za-z0-9_-]+|app:[A-Za-z0-9_-]+)$/.exec(i),p!==null&&o!=="message"&&(p[1]===v||o==="read"&&b&&p[1]==="watch")){const u=p[2];if(u==="node")a.predicates.allNodes=!0;else if(u.startsWith("profile:")){const O=await D(t,"profile",u.slice(8));O!==null&&a.roots.push({id:O,private:!1,match:"below"})}else u.startsWith("app:")&&await $(u,"objects-app");continue}if(p=/^crtr:conversations:read:(app:[A-Za-z0-9_-]+)$/.exec(i),p!==null&&o==="read"){await $(p[1],"node-report"),await $(p[1],"run-node");continue}p=/^crtr:objects:message:(app:[A-Za-z0-9_-]+)$/.exec(i),p!==null&&o==="message"&&await $(p[1],"node-tree")}if(o==="read"){for(const i of a.packageApps??[])i!==e.app.id&&a.roots.push({id:i,private:!1,match:"shipped"});for(const i of await t.prepare("SELECT o.id, i.external_id FROM objects o JOIN identities i ON i.object = o.id AND i.scheme = 'app' WHERE o.type = 'app' AND o.deleted_at IS NULL").all())i.id!==e.app.id&&a.roots.push({id:i.id,private:I(r,i.external_id),match:"custom"})}if(o!=="message")for(const i of[...Y(e),...await Z(t,n)])a.roots.push({id:i,private:o==="read",match:"any"});return a}s(ie,"resolveCeiling");async function G(t,e){return(await t.prepare("SELECT namespace FROM schemas WHERE app = ?").all(e)).map(n=>n.namespace)}s(G,"ownNamespaces");async function _(t,e){const n=await t.prepare("SELECT run_id, isolated FROM nodes WHERE node_id = ?").get(e);if(n!==void 0)return{run:n.run_id??e,isolated:n.isolated===1};const o=await t.prepare("SELECT run_id FROM deleted_isolated_nodes WHERE node_id = ?").get(e);return o?{run:o.run_id,isolated:!0}:null}s(_,"nodePlace");async function ae(t,e){const n=await _(e,t);n?.isolated&&await e.prepare("INSERT INTO deleted_isolated_nodes (node_id, run_id) VALUES (?, ?) ON CONFLICT (node_id) DO UPDATE SET run_id = excluded.run_id").run(t,n.run)}s(ae,"rememberDeletedIsolated");function pe(t){return t.class==="person"?t:{...t,launched:null}}s(pe,"asRuntimeWriter");async function se(t,e,n,o,f=!1){if(e.class==="person"||e.launched===void 0||e.launched===null)return null;const a=await t.prepare(`WITH RECURSIVE c(id, owner, type, kind, depth) AS (
|
|
3
3
|
SELECT id, owner, type, kind, 0 FROM objects WHERE id = ? UNION ALL
|
|
4
4
|
SELECT p.id, p.owner, p.type, p.kind, c.depth + 1 FROM c JOIN objects p ON p.id = c.owner WHERE c.depth < 12)
|
|
5
|
-
SELECT c.id, c.type, c.kind FROM c ORDER BY c.depth`).all(n);if(a[a.length-1]?.id!==e.app.id)return null;const r=await
|
|
6
|
-
SELECT ${
|
|
5
|
+
SELECT c.id, c.type, c.kind FROM c ORDER BY c.depth`).all(n);if(a[a.length-1]?.id!==e.app.id)return null;const r=await L(t,e.app.id);if(r===null)return null;if(a.length===1)return f?e.launched.some(N=>R(N,`crtr:memory:${o}:${r}`))?null:`crtr:memory:${o}:${r}`:null;if(!f&&a[0].type!=="document")return null;const E=a.slice(0,-1).reverse();if(o==="read"&&!f&&a[0].kind==="report"&&E[0].type==="node"&&e.class!=="object"){const N=e.class==="node"?await _(t,e.node.id):e.place??null,m=await _(t,E[0].id);if(N!==null&&m!==null&&N.run===m.run)return null}const l=E[0],w=l.type==="profile"?`crtr:memory:${o}:${r}:profile:${await L(t,l.id)}`:`crtr:memory:${o}:${r}`;return e.launched.some(N=>R(N,w))?null:w}s(se,"missingMemoryScope");function ce(t,e){const n=[];t.roots.length>0&&n.push(K(t,e)),t.namespaces.length>0&&n.push(h`split_part(${c(e)}.schema_type, '/', 1) = ANY(${t.namespaces}::text[])`),t.predicates.allNodes&&n.push(c(`(${e}.type = 'node' AND ${e}.privacy = 'public')`)),t.predicates.spaces&&n.push(c(`(${e}.owner IS NULL AND ${e}.type IN ('app','person','repo','group'))`));const o=t.packageApps===null?H:h`(NOT EXISTS (SELECT 1 FROM documents sd WHERE sd.object = ${c(e)}.id AND sd.source_path IS NOT NULL) OR ${c(e)}.owner = ANY(${t.packageApps}::text[]))`;return k([T(n),B(t,e),o])}s(ce,"ceilingFrag");function B(t,e){if(t.place===null)return H;const n=t.place.isolated?1:0;return h`NOT EXISTS (WITH RECURSIVE ca(id, owner, depth, near_node) AS (
|
|
6
|
+
SELECT ${c(e)}.id, ${c(e)}.owner, 0, CASE WHEN ${c(e)}.type = 'node' THEN ${c(e)}.id END
|
|
7
7
|
UNION ALL
|
|
8
8
|
SELECT p.id, p.owner, ca.depth + 1, COALESCE(ca.near_node, CASE WHEN p.type = 'node' THEN p.id END)
|
|
9
9
|
FROM ca JOIN objects p ON p.id = ca.owner WHERE ca.depth < 12)
|
|
10
10
|
SELECT 1 FROM ca LEFT JOIN nodes cn ON cn.node_id = ca.near_node LEFT JOIN deleted_isolated_nodes cd ON cd.node_id = ca.near_node
|
|
11
11
|
WHERE ca.id = ${t.ownApp} AND ca.depth > 0 AND ca.near_node IS NOT NULL
|
|
12
12
|
AND NOT (CASE WHEN cn.node_id IS NOT NULL THEN COALESCE(cn.run_id, cn.node_id) = ${t.place.run} OR (cn.isolated = 0 AND ${n} = 0)
|
|
13
|
-
WHEN cd.node_id IS NOT NULL THEN cd.run_id = ${t.place.run} ELSE ${n} = 0 END))`}s(
|
|
14
|
-
WHERE rv.document = ${
|
|
15
|
-
AND (au.type = 'person' OR COALESCE((SELECT app FROM nodes WHERE node_id = au.id), au.owner) = ANY(${t.authorApps}::text[]))))`)}const w=
|
|
16
|
-
WHERE rn.node_id = ${
|
|
17
|
-
SELECT ${
|
|
13
|
+
WHEN cd.node_id IS NOT NULL THEN cd.run_id = ${t.place.run} ELSE ${n} = 0 END))`}s(B,"placeFrag");function K(t,e){const n=t.roots.map(d=>d.id),o=t.roots.map(d=>d.private?1:0),f=t.roots.map(d=>d.match),a=new Set(t.roots.map(d=>d.match)),r=s(d=>`${e}.${d}`,"O"),E=[],l=s((d,A)=>{a.has(d)&&E.push(h`(r.match = ${d} AND ${typeof A=="string"?c(A):A})`)},"t");l("any","TRUE"),l("below","ca.depth > 0"),l("direct-doc",`(ca.depth = 0 OR (ca.depth = 1 AND ${r("type")} = 'document'))`),l("no-node","NOT ca.node_below"),l("node-tree","ca.node_below"),l("objects-app",`(ca.node_below OR ${r("type")} LIKE '%.%')`),l("node-report",`(ca.node_below AND ${r("type")} = 'document' AND ${r("kind")} = 'report')`),l("custom",`${r("type")} LIKE '%.%'`),l("shipped",`(ca.depth > 0 AND EXISTS (SELECT 1 FROM documents sd WHERE sd.object = ${r("id")} AND sd.source_path IS NOT NULL))`),l("non-document",`(${r("type")} <> 'document')`),l("self","ca.depth = 0"),a.has("run-report")&&E.push(t.place===null?g:h`(r.match = 'run-report' AND ${c(r("type"))} = 'document' AND ${c(r("kind"))} = 'report' AND EXISTS (SELECT 1 FROM nodes rn WHERE rn.node_id = ca.near_node AND COALESCE(rn.run_id, rn.node_id) = ${t.place.run}))`);for(const d of a)if(d.startsWith("authored:")){const A=d.slice(9);E.push(h`(r.match = ${d} AND ca.depth = 1 AND ${c(r("type"))} = 'document' AND ${A==="*"?c("TRUE"):h`${c(r("name"))} = ${A}`} AND EXISTS (SELECT 1 FROM revisions rv JOIN objects au ON au.id = rv.author
|
|
14
|
+
WHERE rv.document = ${c(r("id"))} AND rv.number = (SELECT min(number) FROM revisions WHERE document = ${c(r("id"))})
|
|
15
|
+
AND (au.type = 'person' OR COALESCE((SELECT app FROM nodes WHERE node_id = au.id), au.owner) = ANY(${t.authorApps}::text[]))))`)}const w=T(E),N=a.has("run-node")?h`EXISTS (SELECT 1 FROM nodes rn JOIN unnest(${n}::text[], ${o}::int[], ${f}::text[]) AS r(id, priv, match) ON r.match = 'run-node' AND r.id = rn.app
|
|
16
|
+
WHERE rn.node_id = ${c(r("id"))} AND rn.run_id IS NOT NULL AND ${c(r("type"))} = 'node' AND (${c(r("privacy"))} = 'public' OR r.priv = 1))`:g,m=h`EXISTS (WITH RECURSIVE ca(id, owner, type, depth, node_below, near_node) AS (
|
|
17
|
+
SELECT ${c(r("id"))}, ${c(r("owner"))}, ${c(r("type"))}, 0, FALSE, CASE WHEN ${c(r("type"))} = 'node' THEN ${c(r("id"))} END
|
|
18
18
|
UNION ALL
|
|
19
19
|
SELECT p.id, p.owner, p.type, ca.depth + 1, ca.node_below OR ca.type = 'node', COALESCE(ca.near_node, CASE WHEN p.type = 'node' THEN p.id END)
|
|
20
20
|
FROM ca JOIN objects p ON p.id = ca.owner WHERE ca.depth < 12)
|
|
21
21
|
SELECT 1 FROM ca JOIN unnest(${n}::text[], ${o}::int[], ${f}::text[]) AS r(id, priv, match) ON r.id = ca.id
|
|
22
|
-
WHERE (CASE WHEN ca.id = r.id THEN (${
|
|
22
|
+
WHERE (CASE WHEN ca.id = r.id THEN (${c(r("privacy"))} = 'public' OR r.priv = 1) ELSE FALSE END) AND ${w})`;return T([m,N])}s(K,"rootsFrag");export{pe as asRuntimeWriter,ce as ceilingFrag,I as holdsProviderGroup,se as missingMemoryScope,_ as nodePlace,P as personObjectIds,V as readablePackageApps,ae as rememberDeletedIsolated,ie as resolveCeiling};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
1
|
+
var L=Object.defineProperty;var a=(s,e)=>L(s,"name",{value:e,configurable:!0});import{parsePrincipal as x}from"@north-light/identity";import{isCloudRole as _,personIdAsync as H}from"../canvas/person.js";import{requestPersonId as W}from"../canvas/person-state.js";import{OBJECT_TYPE as k,GROUP_TYPE as m}from"./builtin.js";import{ceilingFrag as M,resolveCeiling as U}from"./ceiling.js";import{compilePermission as w}from"./compile.js";import{PermissionError as j}from"./errors.js";import{loadDefinitions as y}from"./schemas.js";import{TRUE as D,and as F,f as d,or as P,raw as u}from"./sql.js";const q=["read","edit","message","use","share"],v={read:"read",use:"read",edit:"write",share:"write",message:"message"},f=a(s=>s.replace(/^user:/,""),"bareUser"),S=a(s=>{const e=x(s);return e?.kind==="user"?f(e.namespace):null},"personSub");async function J(s,e){const t=await A(s,e);if(t!==null)return t;const n=e.class==="app"&&e.sub===void 0;if(e.class==="app"&&!(n&&!_()))throw new j(403,"no_person","an app reader that names no person acts for no one");return f(await H())}a(J,"userOf");async function A(s,e){if(e.class==="person"){const r=await s.prepare("SELECT external_id FROM identities WHERE object = ? AND scheme = 'user'").get(e.person.id);return r===void 0?null:f(r.external_id)}if(e.class==="app")return e.sub===void 0?null:S(e.sub);if(e.class==="object"&&e.sub!==void 0)return S(e.sub);const t=e.class==="node"?e.node.id:e.object.id,n=await s.prepare("SELECT sub FROM nodes WHERE node_id = ?").get(t);return n?.sub==null?null:S(n.sub)}a(A,"namedUserOf");async function O(s,e){const t=[e,"*"],n=await s.prepareUncached(`WITH RECURSIVE g(id) AS (
|
|
2
2
|
SELECT resource_id FROM relations WHERE resource_type = ? AND relation = 'member' AND subject_type = 'user' AND subject_id = ANY(?::text[])
|
|
3
3
|
UNION
|
|
4
4
|
SELECT r.resource_id FROM relations r JOIN g ON r.subject_type = ? AND r.subject_id = g.id AND r.subject_relation = 'member'
|
|
5
5
|
WHERE r.resource_type = ? AND r.relation = 'member')
|
|
6
|
-
SELECT id FROM g`).all(m,
|
|
6
|
+
SELECT id FROM g`).all(m,t,m,m);return{userIds:t,groupIds:n.map(r=>r.id)}}a(O,"subjectSet");const p=new WeakMap,ce=a(s=>(p.has(s)||p.set(s,null),s),"shareReads");function Y(s,e){const t=p.get(e);if(t)return t;const n=(async()=>{const r=_()&&W()===void 0?await A(s,e):await J(s,e);return{reader:e,userId:r,subjects:r===null?{userIds:["*"],groupIds:[]}:await O(s,r),defs:await y(s)}})();return t===null&&(p.set(e,n),n.catch(()=>p.set(e,null))),n}a(Y,"resolveReader");const B=a(s=>"subjects"in s,"isEval");async function G(s,e,t,n="o",r={}){if(!q.includes(t))throw new j(400,"unknown_permission",`unknown permission ${t}`);const o=B(e)?e:await Y(s,e),{defs:c}=o,E=u(`${n}.id`),N=w(c,o.subjects,k,t,E),h=t==="read"?P([N,u(`${n}.type = 'app'`)]):N,g=o.reader.class==="person"?null:o.reader.app.id,T=o.reader.class==="app"&&o.reader.place===void 0&&g!==null?await z(s,g):new Set,l=[];for(const[i,I]of c){if(i.startsWith("crtr/")||i==="user"||i==="app"||!(t in I.permissions)&&!(t in I.relations))continue;const C=i.split("/")[0];l.push(d`WHEN ${u(n)}.schema_type = ${i} THEN ${T.has(C)?D:w(c,o.subjects,i,t,E)}`)}const b=l.length===0?d`(CASE WHEN ${u(n)}.schema_type IS NULL THEN ${h} ELSE FALSE END)`:d`(CASE WHEN ${u(n)}.schema_type IS NULL THEN ${h} ${{sql:l.map(i=>i.sql).join(" "),params:l.flatMap(i=>i.params)}} ELSE FALSE END)`,R=await V(s,o,v[t],r);return R===null?b:F([M(R,n),b])}a(G,"permits");const $=new WeakMap;function V(s,e,t,n={}){let r=$.get(e.reader);r===void 0&&$.set(e.reader,r=new Map);const o=`${t} ${n.verb??""} ${e.userId} ${e.subjects.groupIds.join(",")}`;let c=r.get(o);return c===void 0&&(c=U(s,e.reader,e.userId,t,n),r.set(o,c),c.catch(()=>r.delete(o))),c}a(V,"ceilingOf");async function z(s,e){const t=await s.prepare("SELECT s.namespace FROM schemas s JOIN identities i ON i.external_id = s.app AND i.scheme = 'app' WHERE i.object = ?").all(e);return new Set(t.map(n=>n.namespace))}a(z,"ownNamespaceTypes");async function ie(s,e,t,n,r={}){const o=await G(s,e,t,"o",r);return(await s.prepareUncached(`SELECT ${o.sql} AS ok FROM objects o WHERE o.id = ?`).get(...o.params,n))?.ok===!0}a(ie,"check");async function ue(s,e,t,n){const r=await O(s,f(e)),o=await y(s),c=w(o,r,n.type,t,d`${n.id}::text`);return(await s.prepareUncached(`SELECT ${c.sql} AS ok`).get(...c.params))?.ok===!0}a(ue,"checkUser");export{q as PERMISSIONS,V as ceilingOf,ie as check,ue as checkUser,G as permits,Y as resolveReader,ce as shareReads,O as subjectSet,J as userOf};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
var l=Object.defineProperty;var n=(t,e)=>l(t,"name",{value:e,configurable:!0});import{headlessText as
|
|
1
|
+
var l=Object.defineProperty;var n=(t,e)=>l(t,"name",{value:e,configurable:!0});import{headlessText as d}from"./headless-pi.js";import{envRecapModelOverride as c}from"../../shared/env.js";const m=25e3,u="anthropic/claude-haiku-5-5",p=`You brief a developer returning to a paused coding-agent conversation. They run many agent sessions in parallel and have lost this one's thread: they no longer know what this conversation is about or what they originally asked for. The brief exists to solve exactly that \u2014 pinned above their input box, it must tell them at a glance what this conversation is FOR and where it actually stands. You are given the first and most recent messages of the literal user/agent back-and-forth (tool output omitted), and the agent's roadmap file when one exists.
|
|
2
2
|
|
|
3
3
|
Output EXACTLY two plain-text lines, nothing else:
|
|
4
4
|
Goal: <what was requested \u2014 the original ask / what this conversation is for>
|
|
5
5
|
State: <catch-them-up: what is ACTUALLY going on right now>
|
|
6
6
|
|
|
7
|
-
Both lines are extremely short \u2014 telegraphic fragments, roughly 8-15 words, no filler. The State line must NOT restate the most recent message \u2014 the last message is often mid-progress, a question, or noise; instead synthesize the real position: what has landed, what is in flight, and the live blocker or needed answer.
|
|
7
|
+
Both lines are extremely short \u2014 telegraphic fragments, roughly 8-15 words, no filler. The State line must NOT restate the most recent message \u2014 the last message is often mid-progress, a question, or noise; instead synthesize the real position: what has landed, what is in flight, and the live blocker or needed answer. Do NOT say what the agent is waiting on or who it waits for \u2014 the viewer already shows that on its own line. Be concrete (real file names, branches, SHAs, error messages \u2014 one specific anchor beats abstractions). Never narrate turn by turn, hedge, or pad. If the conversation has barely started, still emit your best two lines.
|
|
8
8
|
|
|
9
9
|
Examples of the shape (from other conversations):
|
|
10
10
|
Goal: Validate + commit the Unit 3 attach-keybinding migration in this worktree.
|
|
11
11
|
State: Done \u2014 17/17 tests green, committed and rebased onto main.
|
|
12
12
|
|
|
13
13
|
Goal: Build the trimmed-v1 command-plugin seam (orchestrating phases).
|
|
14
|
-
State: Phase 1 landed;
|
|
14
|
+
State: Phase 1 landed; core-seam worker building phase 2.
|
|
15
15
|
|
|
16
16
|
Goal: Standing personal assistant \u2014 iMessage wakes, Reddit scans, small tasks.
|
|
17
|
-
State:
|
|
17
|
+
State: Reddit scan shipped; hook, map export and Omi timing still open.`;function g(t,e){return`${e!==void 0&&e.trim()!==""?`<roadmap>
|
|
18
18
|
${e.trim()}
|
|
19
19
|
</roadmap>
|
|
20
20
|
|
|
@@ -22,6 +22,6 @@ ${e.trim()}
|
|
|
22
22
|
${t}
|
|
23
23
|
</conversation>
|
|
24
24
|
|
|
25
|
-
Write the two-line Goal:/State: briefing for the conversation above. Output JUST the two lines.`}n(g,"recapUserPrompt");function f(t){const e=
|
|
25
|
+
Write the two-line Goal:/State: briefing for the conversation above. Output JUST the two lines.`}n(g,"recapUserPrompt");function f(t){const e=c();return e!==void 0?e:t!==void 0&&t.trim()!==""?t.trim():u}n(f,"recapModel");function w(t){return t.split(`
|
|
26
26
|
`).map(e=>e.replace(/\s+/g," ").trim()).filter(e=>e!=="").join(`
|
|
27
|
-
`)}n(w,"parseRecap");function
|
|
27
|
+
`)}n(w,"parseRecap");function T(t,e,a,r,o){const i=(t??"").trim();i!==""&&d({systemPrompt:p,userPrompt:g(i,r),modelSpec:f(a),timeoutMs:m,...o===void 0?{}:{causedBy:o}}).then(h=>{const s=w(h);if(s!=="")try{e(s)}catch{}}).catch(()=>{})}n(T,"generateRecap");export{T as generateRecap};
|
|
@@ -43,6 +43,8 @@ export interface ProviderCallInput {
|
|
|
43
43
|
approval?: string;
|
|
44
44
|
/** Which device machine takes the call (a `machine_id`, `runtime:` prefix optional); only a provider served by a machine accepts it. */
|
|
45
45
|
machine?: string;
|
|
46
|
+
/** The principal the call acts for (`--as`): carried through, not yet resolved. */
|
|
47
|
+
as?: string;
|
|
46
48
|
}
|
|
47
49
|
export declare function parseProvider(value: unknown): string;
|
|
48
50
|
export declare function parseCallInput(body: unknown): ProviderCallInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var q=Object.defineProperty;var s=(e,r)=>q(e,"name",{value:r,configurable:!0});import{
|
|
1
|
+
var q=Object.defineProperty;var s=(e,r)=>q(e,"name",{value:r,configurable:!0});import{parsePrincipal as G}from"@north-light/identity";import{randomUUID as N}from"node:crypto";import{cloudPersonScope as T}from"../../../core/runs/operations.js";import{directoryIssuer as F}from"../../../core/directory/issuer.js";import{activeGrantForApp as k,grantFor as x,grantsOfPerson as C,localGrants as j,providerIdsFromGrants as S}from"../../../core/grants/mirror.js";import{getNode as B}from"../../../core/canvas/canvas.js";import{scopeAllowed as D}from"../../../core/scopes.js";import{ProviderError as f,providerErrorBody as M,scopeMissing as U}from"../../../core/providers/errors.js";import{callProvider as z,providerTools as L}from"../../../core/providers/call.js";import{providerInstallState as V}from"../../../core/providers/bundles.js";import{installedProviderPlugins as Z,providerRootClaims as W,resolveProviderRef as J}from"../../../core/providers/roots.js";import{isCloudRole as h}from"../../../core/canvas/person-state.js";import{listAudit as X,writeProviderAudit as H}from"../../../core/providers/audit.js";import{emitEvent as P}from"../../../core/events/emit.js";import{resolvedScopes as _}from"../router.js";const Re=new Set(["provider.tools","provider.call","audit.list"]);async function K(e){if(e.class==="forwarded"){if(e.actor.kind==="person")return{class:"person",sub:null,grantee:null,client_id:null,resolved:null,nodeScopes:null,run_id:null,node_id:null,origin:{node:null,run:null,machine:e.via}};const r=await x(e.actor.app,e.sub);if(!r)throw new f("grant_revoked",`app ${e.actor.app} has no active grant`);return{class:"app",sub:e.sub,grantee:e.actor.app,client_id:null,resolved:r.resolved,nodeScopes:e.actor.node_scopes,run_id:null,node_id:null,origin:{node:e.actor.node,run:e.actor.place?.run??null,machine:e.via}}}if(e.class==="machine"||e.class==="import")throw new f("permission_error","this operation is not available to the caller");if(e.class==="person"&&e.sub!==void 0){if(!h())throw new f("permission_error","provider calls are made by the install's person, a node or an app");return{class:"person",sub:e.sub,grantee:null,client_id:null,resolved:await _(e),nodeScopes:null,run_id:null,node_id:null}}if(e.class==="person")return{class:"person",sub:null,grantee:null,client_id:null,resolved:null,nodeScopes:null,run_id:null,node_id:null};if(e.class==="app"){const r=await k(e.app);if(!r)throw new f("grant_revoked",`app ${e.app} has no active grant`);return{class:"app",sub:r.sub,grantee:e.app,client_id:null,resolved:r.resolved,nodeScopes:e.scopes,run_id:null,node_id:null}}return e.class==="cron"?{class:"app",sub:e.sub,grantee:e.app,client_id:null,resolved:await _(e),nodeScopes:e.scopes,run_id:e.origin_run,node_id:null}:{class:"broker",sub:e.sub,grantee:e.app,client_id:e.client_id,resolved:await _(e),nodeScopes:e.scopes,run_id:e.run??(await B(e.node))?.run_id??null,node_id:e.node}}s(K,"callerFromRequest");function Ie(e){return{class:"app",sub:e.sub,grantee:e.grantee,client_id:e.client_id,resolved:e.resolved,nodeScopes:null,run_id:null,node_id:null}}s(Ie,"callerFromApp");const Q=/^([A-Za-z0-9_-]{1,64}):([A-Za-z0-9_-]{1,64})$/;function Y(e){const r=Q.exec(e);return r!==null&&r[1]!=="crtr"}s(Y,"isProviderScope");const A=new WeakMap;function ee(e){let r=A.get(e);return r===void 0&&(r=new Set(e),A.set(e,r)),r}s(ee,"heldSet");function E(e,r){return e===null?!0:Y(r)?ee(e).has(r):D(e,r)}s(E,"holds");function R(e,r){return e.class==="person"&&e.resolved===null?!0:E(e.resolved??[],r)&&E(e.nodeScopes,r)}s(R,"callerAllows");function Oe(e,r,n){const o=`${r}:${n}`;if(!R(e,o))throw U(o)}s(Oe,"requireGroup");function re(){return!!F()}s(re,"providerOperationsEnabled");const oe=/^[A-Za-z0-9_-]{1,64}$/;function p(e,r){return new f("invalid_request",e,{param:r})}s(p,"invalid");function I(e){if(typeof e!="string"||!oe.test(e)||e==="crtr")throw p("provider must be a provider id","provider");return e}s(I,"parseProvider");function te(e){if(!e||typeof e!="object"||Array.isArray(e))throw new f("invalid_request","a JSON object is required");const r=e,n=I(r.provider),o=r.tool;if(typeof o!="string"||!o.trim())throw p("tool must be a non-empty string","tool");const d=r.arguments??{};if(!d||typeof d!="object"||Array.isArray(d))throw p("arguments must be an object","arguments");const a=r.version;if(a!==void 0&&(typeof a!="number"||!Number.isInteger(a)||a<1))throw p("version must be an integer >= 1","version");const u=r.approval;if(u!==void 0&&(typeof u!="string"||!u))throw p("approval must be a question id","approval");const l=r.machine;if(l!==void 0&&(typeof l!="string"||!l.trim()))throw p("machine must be a machine id","machine");const i=r.as;if(i!==void 0&&(typeof i!="string"||G(i)===null))throw p("as must be a principal like user:<id> or app:<id>/<path>","as");return{provider:n,tool:o.trim(),arguments:d,...a===void 0?{}:{version:a},...u===void 0?{}:{approval:u},...l===void 0?{}:{machine:l.trim()},...i===void 0?{}:{as:i}}}s(te,"parseCallInput");async function ne(e,r=new URLSearchParams){const n=s((i,v,b)=>{const m=r.get(i);if(m===null)return v;if(!/^\d+$/.test(m)||Number(m)>b||Number(m)<1)throw p(`invalid ${i}`,i);return Number(m)},"numeric"),o=r.has("after")?n("after",0,Number.MAX_SAFE_INTEGER):void 0,d=n("limit",100,1e3),a=Object.fromEntries(["operation","outcome","run_id","since","until"].filter(i=>r.has(i)).map(i=>[i,r.get(i)])),u=T(e.sub),l=u===void 0?{}:{sub:u};return{status:200,body:await X(e.class==="person"?null:e.grantee,{after:o,limit:d,...l,...a})}}s(ne,"auditList");async function se(e,r,n){let o=r;const d=performance.now(),a=Z(),{skipped:u}=W(a),l=h()?e.sub?await C(e.sub):[]:await j(),i=h()?new Set(S(l.filter(t=>t.sub===e.sub))):null,v=s(t=>!u.has(t)&&(i===null||i.has(t)),"shown"),b=new Set(a.filter(t=>t.enabled&&t.manifest.provider?.id===t.name&&v(t.name)).map(t=>t.name)),m=S(l).filter(v),g=[...new Set([...b,...m])].sort();if(o!==void 0){const t=J(o);if(t===null)throw new f("not_found",`provider "${o}" is not available`);o=t}if(o!==void 0&&!g.includes(o))throw new f("not_found",`provider "${o}" is not available`);const O=o===void 0?g:[o],$=e.class==="person"?l.flatMap(t=>t.status==="active"&&(!h()||t.sub===e.sub)?t.resolved_scopes.map(({scope:c})=>c):[]):e.resolved??[],w=await Promise.all(O.map(async t=>{if(b.has(t))return L(e,t);if(!$.some(y=>y.startsWith(`${t}:`)&&R(e,y)))return null;const c=V(t);return c===void 0?null:{provider:t,display_name:t,status:c.status,...c.error?{error:c.error}:{},groups:[],commands:[]}})).then(t=>t.filter(c=>c!==null));if(P({level:"debug",event:"api.provider.tools",duration_ms:performance.now()-d,fields:{caller:e.class,provider:o??null,providers:w.length}}),o!==void 0){if(w.length===0)throw new f("not_found",`provider "${o}" is not available`);return{status:200,body:w[0]}}return{status:200,body:{providers:w}}}s(se,"providerTools");async function ie(e,r,n){return z(e,r,n)}s(ie,"providerCall");async function de(e,r,n,o){if(!re())throw new f("not_found","provider operations need a directory-connected runtime");if(e==="audit.list")return await ne(r,n.query);if(e==="provider.tools")return se(r,n.params.provider===void 0?void 0:I(n.params.provider),o);if(e==="provider.call"){let d;try{d=te(n.body)}catch(a){const u=n.body&&typeof n.body=="object"&&!Array.isArray(n.body)?n.body:{};throw await H({request_id:o.requestId,caller:r,provider:typeof u.provider=="string"?u.provider:"",tool:typeof u.tool=="string"?u.tool:"",outcome:`refused:${a instanceof f?a.code:"invalid_request"}`}),a}return ie(r,d,o)}throw new f("not_found","unknown operation")}s(de,"handleProviderOperation");function ae(e){const r=new AbortController,n=s(()=>{e.writableFinished||r.abort()},"abort");return e.on("close",n),{signal:r.signal,release:s(()=>e.off("close",n),"release")}}s(ae,"abortOnClose");function ue(e,r,n,o){const d=M(e,r,n,o??void 0);return d.status>=500&&!(e instanceof f)&&P({event:"api.provider.failed",level:"error",error:e instanceof Error?e:new Error(String(e)),fields:{request_id:r}}),d}s(ue,"providerFailure");const $e=[{method:"GET",pattern:"/v1/audit",name:"audit.list"},{method:"GET",pattern:"/v1/providers/tools",name:"provider.tools"},{method:"GET",pattern:"/v1/providers/:provider/tools",name:"provider.tools"},{method:"POST",pattern:"/v1/provider/call",name:"provider.call"}].map(({method:e,pattern:r,name:n})=>({method:e,pattern:r,handler:s(async o=>{const d=N(),{signal:a,release:u}=ae(o.res);let l=null;try{return l=await K(o.principal),{...await de(n,l,{params:o.params,body:o.body,query:new URL(o.req.url??"/","http://runtime.local").searchParams},{requestId:d,signal:a,...o.causedBy===void 0?{}:{causedBy:o.causedBy}}),headers:{"Request-Id":d}}}catch(i){return ue(i,d,!1,l?.run_id)}finally{u()}},"handler")}));export{Re as PROVIDER_OPERATIONS,ae as abortOnClose,R as callerAllows,Ie as callerFromApp,K as callerFromRequest,de as handleProviderOperation,te as parseCallInput,I as parseProvider,ue as providerFailure,re as providerOperationsEnabled,$e as providerRoutes,Oe as requireGroup};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type CallLink, type CallToken } from '@north-light/identity';
|
|
2
2
|
import { type GrantSync } from '../../core/grants/cover.js';
|
|
3
3
|
import { type ActiveGrant } from '../../core/grants/mirror.js';
|
|
4
4
|
import type { ForwardedPrincipal, MachinePrincipal } from '../api/router.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var m=Object.defineProperty;var c=(n,e)=>m(n,"name",{value:e,configurable:!0});import{parsePrincipal as l}from"@north-light/identity";import{decodeEnvelope as v,EnvelopeError as w}from"../../core/peer/envelope.js";import{coverGrant as g}from"../../core/grants/cover.js";import{grantFor as z}from"../../core/grants/mirror.js";import{RunError as p}from"../../core/runs/operations.js";const t=c((n,e,i)=>({status:n,code:e,message:i}),"refuse"),b="the envelope does not match its token";function q(n){return async(e,i)=>{const a=c(()=>new p(403,"app_not_granted",`${e.sub} holds no active grant for ${i} on this machine`),"notGranted");if(e.grant===void 0){const o=await z(e.sub,i);if(o===null)throw a();return o}try{return await g(e.grant,e.rev??1,i,e.sub,n)}catch(o){throw o instanceof p&&o.status===401?a():o}}}c(q,"mirrorGrantLink");async function x(n,e,i){const a=n.chain[0];if(a===void 0||!a.sub.startsWith("runtime:"))return t(401,"unauthorized","not a machine's token");if(a.sub===i.self())return t(401,"unauthorized","a machine does not call itself");if(n.scope!==void 0)return t(401,"unauthorized","a provider token does not authorize on a machine");const o=i.relation(n.sub);if(o===null)return t(403,"forbidden","no relation reaches this machine");let u;if(e!==void 0){try{u=v(e)}catch(r){return t(400,"invalid_request",r instanceof w?r.message:"invalid envelope")}if(u.act.sub!==a.sub||u.sub!==n.sub)return t(401,"unauthorized",b);if(u.act.act!==void 0&&u.act.act.place===null)return t(400,"invalid_request","the envelope names an app with no run place")}const s=u?.act.act;if(n.chain.slice(1).some(r=>l(r.sub)?.kind!=="app"))return t(401,"unauthorized","the token chain names a link that is not an app principal");const f=n.chain.slice(1).filter(r=>l(r.sub)?.kind==="app");if(f.length>1)return t(401,"unauthorized","the token names more than one app");const d=f[0];if(d!==void 0&&(s===void 0||s.sub!==d.sub))return t(401,"unauthorized",b);const h=d??(s===void 0?void 0:{sub:s.sub});if(h!==void 0)try{await i.grantLink(h,n.sub)}catch(r){if(r instanceof p)return t(r.status,r.code,r.message);throw r}return u===void 0?{principal:{class:"machine",via:a.sub,sub:n.sub}}:s!==void 0?{principal:{class:"forwarded",via:a.sub,sub:n.sub,actor:{kind:"app",app:s.sub,node:s.node,node_scopes:s.node_scopes,place:s.place}}}:o!=="owner"?t(403,"forbidden","only the owner acts as the person"):{principal:{class:"forwarded",via:a.sub,sub:n.sub,actor:{kind:"person"}}}}c(x,"peerAuthority");export{q as mirrorGrantLink,x as peerAuthority};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.749",
|
|
4
4
|
"description": "crtr — agent runtime with memory, plugins, and marketplaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
"build:plugin": "tsc -p packages/crouter-plugin/tsconfig.json",
|
|
110
110
|
"typecheck": "tsc --noEmit && tsc -p src/doc-editor/tsconfig.json",
|
|
111
111
|
"typecheck:pi-packages": "npx tsc -p src/builtin-pi-packages/pi-crtr-extensions/tsconfig.json",
|
|
112
|
-
"test:runtime-packaging": "node --test scripts/runtime-smoke.test.mjs scripts/pack-args.test.mjs scripts/ensure-native-linux.test.mjs scripts/release-version.test.mjs scripts/sandbox-start.test.mjs",
|
|
112
|
+
"test:runtime-packaging": "node --test scripts/runtime-smoke.test.mjs scripts/pack-args.test.mjs scripts/ensure-native-linux.test.mjs scripts/release-version.test.mjs scripts/sandbox-start.test.mjs scripts/install-source.test.mjs",
|
|
113
113
|
"check:consumer-resolution": "node scripts/check-consumer-resolution.mjs",
|
|
114
114
|
"contract:check": "node scripts/contract.mjs check",
|
|
115
115
|
"contract:surface": "node scripts/contract.mjs generate",
|
|
@@ -158,8 +158,8 @@
|
|
|
158
158
|
},
|
|
159
159
|
"license": "UNLICENSED",
|
|
160
160
|
"dependencies": {
|
|
161
|
-
"@north-light/identity": "0.3.
|
|
162
|
-
"@north-light/plugin": "0.3.
|
|
161
|
+
"@north-light/identity": "0.3.749",
|
|
162
|
+
"@north-light/plugin": "0.3.749",
|
|
163
163
|
"@earendil-works/chord": "1.5.2",
|
|
164
164
|
"@earendil-works/pi-agent-core": "1.5.2",
|
|
165
165
|
"@earendil-works/pi-ai": "1.5.2",
|
|
@@ -263,5 +263,23 @@ export async function buildCanvasPanelLines(nodeId, asks, palette, source, crons
|
|
|
263
263
|
line: ` ${eye} ${muted(`${summary} · ↵ details`)}${RESET}`,
|
|
264
264
|
});
|
|
265
265
|
}
|
|
266
|
-
|
|
266
|
+
// What this node itself waits on: the person first, then named children, then other waits.
|
|
267
|
+
const waits = [];
|
|
268
|
+
if ((asks[nodeId] ?? 0) > 0)
|
|
269
|
+
waits.push('you');
|
|
270
|
+
if (live.length > 0) {
|
|
271
|
+
const first = navLabel((await detail(live[0])) ?? (await node(live[0])), live[0]);
|
|
272
|
+
waits.push(live.length === 1 ? first : `${first} +${live.length - 1}`);
|
|
273
|
+
}
|
|
274
|
+
if (reviews.length > 0)
|
|
275
|
+
waits.push('review');
|
|
276
|
+
if (bashSummary !== undefined)
|
|
277
|
+
waits.push(jobs.length === 1 ? 'a bash job' : `${jobs.length} bash jobs`);
|
|
278
|
+
if (cronSummary !== undefined)
|
|
279
|
+
waits.push(crons.length === 1 ? 'a cron' : `${crons.length} crons`);
|
|
280
|
+
for (const wait of roster?.object_waits ?? [])
|
|
281
|
+
if (wait.node_id === nodeId)
|
|
282
|
+
waits.push(wait.object_name);
|
|
283
|
+
const waiting = waits.length === 0 ? undefined : waits.join(', ');
|
|
284
|
+
return { reports: items.map((item) => item.line), reportIds, items, ...(waiting === undefined ? {} : { waiting }) };
|
|
267
285
|
}
|
|
@@ -76,6 +76,7 @@ export function createRoster(s, hooks) {
|
|
|
76
76
|
const others = remote ? undefined : { crons, reviews: openReviews, jobsOf: async (id) => (await cliClient().listBashJobs(id)).map(toBashJobStatus) };
|
|
77
77
|
const built = await buildCanvasPanelLines(s.nodeId, hooks.asks(), pal, canvasSource, ownedCrons, bashJobs, reviews, others, view ?? await canvasSource.panelView?.(s.nodeId));
|
|
78
78
|
items = built.items;
|
|
79
|
+
hooks.onWaiting?.(built.waiting);
|
|
79
80
|
// After an in-place swap, land on the previously open node, which has taken
|
|
80
81
|
// the swapped-to node's place in this self-excluding roster.
|
|
81
82
|
if (autoSelect !== undefined) {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// chrome/run-facts.ts — the gray fact line above the recap: how long the agent
|
|
2
|
+
// ran since the person's last message, when it finished, and what it waits on.
|
|
3
|
+
//
|
|
4
|
+
// Run time and finish time come from message timestamps on the broker stream
|
|
5
|
+
// (the welcome snapshot, then live message events). What the node waits on comes
|
|
6
|
+
// from the roster refresh, which already reads asks, children, reviews, jobs,
|
|
7
|
+
// crons and object waits for the wait rows below the editor.
|
|
8
|
+
import { formatBashElapsed } from '../../../core/bash-jobs.js';
|
|
9
|
+
import { isTrueUserMessage } from '../../../shared/tool-groups.js';
|
|
10
|
+
function stamp(message) {
|
|
11
|
+
return typeof message.timestamp === 'number' && Number.isFinite(message.timestamp) ? message.timestamp : undefined;
|
|
12
|
+
}
|
|
13
|
+
/** `2:31 PM` today, `Nov 18, 2:31 PM` on another day. */
|
|
14
|
+
export function finishLabel(atMs, nowMs) {
|
|
15
|
+
const at = new Date(atMs);
|
|
16
|
+
const time = at.toLocaleTimeString('en-US', { hour: 'numeric', minute: '2-digit' });
|
|
17
|
+
if (at.toDateString() === new Date(nowMs).toDateString())
|
|
18
|
+
return time;
|
|
19
|
+
return `${at.toLocaleDateString('en-US', { month: 'short', day: 'numeric' })}, ${time}`;
|
|
20
|
+
}
|
|
21
|
+
export function createRunFacts(onChange) {
|
|
22
|
+
let lastUserAt;
|
|
23
|
+
let finishedAt;
|
|
24
|
+
let waiting;
|
|
25
|
+
const take = (message) => {
|
|
26
|
+
const at = stamp(message);
|
|
27
|
+
if (at === undefined)
|
|
28
|
+
return;
|
|
29
|
+
if (isTrueUserMessage(message)) {
|
|
30
|
+
lastUserAt = at;
|
|
31
|
+
finishedAt = undefined;
|
|
32
|
+
}
|
|
33
|
+
else if (message.role === 'assistant') {
|
|
34
|
+
finishedAt = at;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
observe(frame) {
|
|
39
|
+
if (frame.type === 'welcome') {
|
|
40
|
+
lastUserAt = undefined;
|
|
41
|
+
finishedAt = undefined;
|
|
42
|
+
for (const message of frame.snapshot.messages)
|
|
43
|
+
take(message);
|
|
44
|
+
onChange();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (frame.type === 'agent_start' || frame.type === 'agent_end' || frame.type === 'agent_settled') {
|
|
48
|
+
onChange();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (frame.type === 'message_end' || (frame.type === 'message_start' && frame.message.role === 'user')) {
|
|
52
|
+
take(frame.message);
|
|
53
|
+
onChange();
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
setWaiting(label) {
|
|
57
|
+
if (label === waiting)
|
|
58
|
+
return;
|
|
59
|
+
waiting = label;
|
|
60
|
+
onChange();
|
|
61
|
+
},
|
|
62
|
+
line(streaming, nowMs = Date.now()) {
|
|
63
|
+
if (streaming)
|
|
64
|
+
return undefined;
|
|
65
|
+
const parts = [];
|
|
66
|
+
if (finishedAt !== undefined) {
|
|
67
|
+
if (lastUserAt !== undefined && finishedAt >= lastUserAt)
|
|
68
|
+
parts.push(`ran ${formatBashElapsed(finishedAt - lastUserAt)}`);
|
|
69
|
+
parts.push(`finished ${finishLabel(finishedAt, nowMs)}`);
|
|
70
|
+
}
|
|
71
|
+
if (waiting !== undefined)
|
|
72
|
+
parts.push(`waiting on ${waiting}`);
|
|
73
|
+
return parts.length === 0 ? undefined : parts.join(' · ');
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
// widgets in their fixed cockpit slots, and the queued-steering panel above
|
|
3
3
|
// the editor. Both read the folded `SessionState` the orchestrator owns, so it
|
|
4
4
|
// arrives as a getter rather than a captured value.
|
|
5
|
-
import { Text, truncateToWidth, wrapTextWithAnsi } from '@earendil-works/pi-tui';
|
|
5
|
+
import { Spacer, Text, truncateToWidth, wrapTextWithAnsi } from '@earendil-works/pi-tui';
|
|
6
6
|
import { splitRecapLines } from './recap.js';
|
|
7
|
-
export function createChromeWidgets(ctx, state
|
|
7
|
+
export function createChromeWidgets(ctx, state,
|
|
8
|
+
/** The gray fact line (run time, finish time, waiting on), painted above the recap. */
|
|
9
|
+
factLine = () => undefined) {
|
|
8
10
|
const { tui, pal } = ctx;
|
|
9
11
|
const { aboveWidgets, belowWidgets, queued } = ctx.containers;
|
|
10
12
|
/** Paint serializable extension widgets into their fixed cockpit slots. */
|
|
@@ -12,10 +14,17 @@ export function createChromeWidgets(ctx, state) {
|
|
|
12
14
|
const session = state();
|
|
13
15
|
aboveWidgets.clear();
|
|
14
16
|
belowWidgets.clear();
|
|
15
|
-
// The recap widget is split: its goal line is
|
|
16
|
-
// header, while its state line lands here in the
|
|
17
|
-
// slot, label stripped and
|
|
17
|
+
// The fact line comes first. The recap widget is split: its goal line is
|
|
18
|
+
// painted by the pinned header, while its state line lands here in the
|
|
19
|
+
// widget's own cockpit slot, label stripped, faint, and never cut short.
|
|
18
20
|
const span = Math.max(1, (process.stdout.columns ?? 80) - 2);
|
|
21
|
+
const facts = factLine();
|
|
22
|
+
if (facts !== undefined) {
|
|
23
|
+
for (const wrapped of wrapTextWithAnsi(pal.faint(facts), span))
|
|
24
|
+
aboveWidgets.addChild(new Text(wrapped, 1, 0));
|
|
25
|
+
if (session.display.widgets['crtr-recap'] !== undefined)
|
|
26
|
+
aboveWidgets.addChild(new Spacer(1));
|
|
27
|
+
}
|
|
19
28
|
for (const [key, widget] of Object.entries(session.display.widgets)) {
|
|
20
29
|
const recap = key === 'crtr-recap';
|
|
21
30
|
const lines = recap ? splitRecapLines(widget.lines).state : widget.lines;
|
|
@@ -34,6 +34,7 @@ import { createTicketPanel } from './chrome/ticket-panel.js';
|
|
|
34
34
|
import { createPaneFocus } from './session/pane-focus.js';
|
|
35
35
|
import { createStatusLine } from './chrome/status-line.js';
|
|
36
36
|
import { createChromeWidgets } from './chrome/widgets.js';
|
|
37
|
+
import { createRunFacts } from './chrome/run-facts.js';
|
|
37
38
|
import { createRecapHeader } from './chrome/header.js';
|
|
38
39
|
import { createChromeRefresh, isTransientDaemonFailure } from './session/chrome-refresh.js';
|
|
39
40
|
import { createTeardown } from './session/teardown.js';
|
|
@@ -357,7 +358,9 @@ onConnected) {
|
|
|
357
358
|
editorChrome.syncContextBadge();
|
|
358
359
|
// The two broker-fed container painters: extension widgets in their cockpit
|
|
359
360
|
// slots, and the queued-steering panel.
|
|
360
|
-
|
|
361
|
+
// The gray fact line above the recap: run time, finish time, what the node waits on.
|
|
362
|
+
const runFacts = createRunFacts(() => renderExtensionWidgets());
|
|
363
|
+
const { renderExtensionWidgets, renderQueued } = createChromeWidgets(ctx, () => sync.state(), () => runFacts.line(sync.state().engine?.isStreaming === true));
|
|
361
364
|
// The OWNER of the folded SessionState and of what each delta repaints.
|
|
362
365
|
sync = createSessionStateSync(role, {
|
|
363
366
|
setEngineState: (engine) => input.setState(engine),
|
|
@@ -424,6 +427,7 @@ onConnected) {
|
|
|
424
427
|
openInspector,
|
|
425
428
|
openObject,
|
|
426
429
|
syncCursor: () => paneFocus.sync(),
|
|
430
|
+
onWaiting: (label) => runFacts.setWaiting(label),
|
|
427
431
|
});
|
|
428
432
|
// The one hollow-cursor owner: pane focus AND neither list holding the highlight.
|
|
429
433
|
const paneFocus = createPaneFocus(editor, [roster.active, strip.active, ticketPanel.active]);
|
|
@@ -714,6 +718,7 @@ onConnected) {
|
|
|
714
718
|
if (frame.type === 'welcome' && !welcomed)
|
|
715
719
|
mark('viewer.welcome_received');
|
|
716
720
|
handleBrokerFrame(frame);
|
|
721
|
+
runFacts.observe(frame);
|
|
717
722
|
if (frame.type === 'welcome' && !welcomed)
|
|
718
723
|
onFirstWelcome();
|
|
719
724
|
},
|
|
@@ -726,6 +731,7 @@ onConnected) {
|
|
|
726
731
|
scheduleTmuxBindingInstall();
|
|
727
732
|
chatView.settleRun();
|
|
728
733
|
sync.patchLocal({ isStreaming: false });
|
|
734
|
+
renderExtensionWidgets();
|
|
729
735
|
},
|
|
730
736
|
onReconnecting: () => chatView.setPendingUndelivered(true),
|
|
731
737
|
// A message sent on a connection that had already died never reached the broker: send it again now that one answers.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// The canvas data-access layer. Nodes, their sessions, executions, and managed
|
|
2
2
|
// worktrees are SQL-authoritative. Node directories hold only artifacts.
|
|
3
|
+
import { parsePrincipal } from '@north-light/identity';
|
|
3
4
|
import { loadExactProfileManifest } from '../profiles/manifest.js';
|
|
4
5
|
import { envNodeId } from '../../shared/env.js';
|
|
5
6
|
import { lstatSync, realpathSync, rmdirSync, rmSync, statSync } from 'node:fs';
|
|
@@ -61,7 +62,7 @@ async function seedRow(meta, db) {
|
|
|
61
62
|
const profile = meta.profile_id ? await profileObjectFor(db, meta.profile_id, app, meta.grantee ?? 'app:terminal') : null;
|
|
62
63
|
await createObject(db, { id: meta.node_id, type: 'node', kind: meta.kind, owner: (profile ?? app).id, privacy: 'public', name: meta.name, preview: '' });
|
|
63
64
|
// A node directly under an app is readable by the person it was made for.
|
|
64
|
-
if (profile === null && meta.sub &&
|
|
65
|
+
if (profile === null && meta.sub && parsePrincipal(meta.sub)?.kind === 'user')
|
|
65
66
|
await writeActsFor(db, meta.node_id, meta.sub);
|
|
66
67
|
await db.prepare(`INSERT INTO nodes (node_id, description, title, icon, cycles, mode, lifecycle, cwd, host_kind, profile_id, parent, spawned_by, creator, fork_from, fork_source_file, created, passive_default, cycle_pending, model_override, persona_ack_json, review_binding_json, launch_config_json, scopes_json, isolated, status, intent, final_report, finalized_at, deadline_at, "window", tmux_session, pane, sub, grant_id, client_id, metadata_json, run_id, event_cursor, deleting_at, caused_by, app) VALUES (${Array(41).fill('?').join(', ')})`)
|
|
67
68
|
.run(meta.node_id, meta.description ?? null, meta.title ?? null, meta.icon ?? null, meta.cycles ?? null, meta.mode, meta.lifecycle, meta.cwd, meta.host_kind ?? null, meta.profile_id ?? null, meta.parent ?? null, meta.spawned_by ?? null, meta.creator ?? null, meta.fork_from ?? null, meta.fork_source_file ?? null, meta.created, meta.passive_default === true ? 1 : 0, meta.cycle_pending === true ? 1 : 0, meta.model_override ?? null, jsonValue(meta.persona_ack, 'persona_ack'), jsonValue(meta.review_binding, 'review_binding'), jsonValue(meta.launch, 'launch'), jsonValue(meta.scopes, 'scopes'), meta.isolated === true ? 1 : 0, meta.status ?? 'active', meta.intent ?? null, meta.final_report ?? null, meta.finalized_at ?? null, meta.deadline_at ?? null, meta.window ?? null, meta.tmux_session ?? null, meta.pane ?? null, meta.sub ?? null, meta.grant_id ?? null, meta.client_id ?? null, meta.metadata_json ?? null, meta.run_id ?? null, meta.event_cursor ?? null, meta.deleting_at ?? null, meta.caused_by ?? null, app.id);
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
/** The canvas schema version this build supports: the number of the highest delta in `schema-pg/` (the baseline
|
|
7
7
|
* `schema-pg.sql` is version 1). `scripts/install-runtime.mjs` reads this module from a candidate generation to refuse
|
|
8
8
|
* one below the live database's `schema_min_reader`. */
|
|
9
|
-
export const CANVAS_SCHEMA_VERSION =
|
|
9
|
+
export const CANVAS_SCHEMA_VERSION = 36;
|
|
10
10
|
/** The Postgres schema holding the canvas tables: `CRTR_DATABASE_SCHEMA` (`crtr` in the cloud deploy). Unset or empty
|
|
11
11
|
* means the role's own search_path (`public` on a Mac and on a VM). A name that is not a plain identifier is an error:
|
|
12
12
|
* it is put in a `search_path` connection option. */
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// complexity than a plain array walk for this interface contract.
|
|
5
5
|
// A plain array walk + a small flag parser is ~120 lines and has no surprising
|
|
6
6
|
// edge cases.
|
|
7
|
+
import { parsePrincipal } from '@north-light/identity';
|
|
7
8
|
import { renderRoot, renderBranch, renderLeafArgv, withAsyncHelpState, collapseWideChildren, rootPromotedChildren } from './help.js';
|
|
8
9
|
import { beginPreview, publishPreviewResult, readStdinRaw, peekStdinRaw, emit, handle, setJsonOutput, isJsonOutput } from './io.js';
|
|
9
10
|
import { renderResult } from './render.js';
|
|
@@ -721,7 +722,7 @@ export function takeMachineSelector(tokens) {
|
|
|
721
722
|
}
|
|
722
723
|
return machine === undefined ? { rest } : { rest, machine };
|
|
723
724
|
}
|
|
724
|
-
/** Take the `--as <
|
|
725
|
+
/** Take the `--as <principal>` / `--as=<user:id>` option out of an opted-in leaf's argv. Nothing after a bare `--` is a flag. */
|
|
725
726
|
export function takeActingAs(tokens) {
|
|
726
727
|
const rest = [];
|
|
727
728
|
let as;
|
|
@@ -737,8 +738,8 @@ export function takeActingAs(tokens) {
|
|
|
737
738
|
continue;
|
|
738
739
|
}
|
|
739
740
|
const value = inline ?? tokens[i + 1];
|
|
740
|
-
if (value === undefined ||
|
|
741
|
-
throw parseArgvError('missing_parameter', '--as requires a
|
|
741
|
+
if (value === undefined || parsePrincipal(value) === null) {
|
|
742
|
+
throw parseArgvError('missing_parameter', '--as requires a principal like user:<id> or app:<id>/<path>', '--as', 'as', 'Name the principal this call acts for, for example `--as user:alice`.');
|
|
742
743
|
}
|
|
743
744
|
if (inline === undefined)
|
|
744
745
|
i++;
|
|
@@ -128,7 +128,7 @@ export async function readerFor(db, principal, reposFn) {
|
|
|
128
128
|
if (!grant)
|
|
129
129
|
throw new ApiError(403, 'app_not_granted', `${principal.actor.app} holds no active grant for ${principal.sub} on this machine`);
|
|
130
130
|
const stored = principal.actor.node_scopes;
|
|
131
|
-
return { class: 'app', app: await appObject(db, principal.actor.app), place: principal.actor.place, launched: stored,
|
|
131
|
+
return { class: 'app', app: await appObject(db, principal.actor.app), sub: principal.sub, place: principal.actor.place, launched: stored,
|
|
132
132
|
scopes: stored === null ? grant.resolved : stored.filter((scope) => coveredByAny(grant.resolved, scope)) };
|
|
133
133
|
}
|
|
134
134
|
if (principal.class === 'cron') {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// Wire form: `Crtr-Envelope: <base64url JSON>` of
|
|
9
9
|
// {sub:"user:<id>", act:{sub:"runtime:<via>", act?:{sub:"app:<x>", node, node_scopes, place}}}
|
|
10
10
|
// A missing inner `act` means the person.
|
|
11
|
+
import { parsePrincipal } from '@north-light/identity';
|
|
11
12
|
import { joinedOwner } from '../directory/join.js';
|
|
12
13
|
import { nodePlace } from '../permissions/ceiling.js';
|
|
13
14
|
import { openDb } from '../canvas/db.js';
|
|
@@ -75,7 +76,7 @@ export function decodeEnvelope(header) {
|
|
|
75
76
|
const inner = act['act'];
|
|
76
77
|
if (inner === undefined)
|
|
77
78
|
return { sub: raw['sub'], act: { sub: act['sub'] } };
|
|
78
|
-
if (!isRecord(inner) || !isString(inner['sub']) ||
|
|
79
|
+
if (!isRecord(inner) || !isString(inner['sub']) || parsePrincipal(inner['sub'])?.kind !== 'app')
|
|
79
80
|
throw new EnvelopeError('the envelope names no calling app');
|
|
80
81
|
const { node, node_scopes: scopes, place } = inner;
|
|
81
82
|
if (node !== null && !isString(node))
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// A stub that watches carries the envelope identity it acts under (app, node, node_scopes, place).
|
|
10
10
|
// That identity names who the remote watcher is; it is never authority. What the stub may read is
|
|
11
11
|
// recomputed from the current mirrored grant every time an event is published (`readerForObject`).
|
|
12
|
+
import { parsePrincipal } from '@north-light/identity';
|
|
12
13
|
import { createObject, getById, ownerForGrantee, ownerLockKey } from '../graph/objects.js';
|
|
13
14
|
import { readLegacyPrivacy } from '../graph/types.js';
|
|
14
15
|
import { upsertKind } from '../graph/custom.js';
|
|
@@ -83,7 +84,10 @@ export async function lockInOrder(db, keys) {
|
|
|
83
84
|
}
|
|
84
85
|
/** The lock key to create the owner `grantee` names, or none when it exists (`ensureOwner` locks only a first sighting). */
|
|
85
86
|
async function missingOwnerKey(db, grantee) {
|
|
86
|
-
const
|
|
87
|
+
const principal = parsePrincipal(grantee);
|
|
88
|
+
if (principal === null)
|
|
89
|
+
throw new Error(`grantee ${JSON.stringify(grantee)} is not a principal`);
|
|
90
|
+
const [scheme, externalId] = principal.kind === 'app' ? ['app', principal.namespace] : ['user', grantee];
|
|
87
91
|
return await db.prepare('SELECT 1 FROM identities WHERE scheme = ? AND external_id = ?').get(scheme, externalId) === undefined ? [ownerLockKey(scheme, externalId)] : [];
|
|
88
92
|
}
|
|
89
93
|
/** Every advisory lock `ensureStub` takes for this object: the stub, the custom kind its reference declares, and each owner it may create.
|