@north-light/cli 0.3.602 → 0.3.603

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.
@@ -4,5 +4,8 @@ export interface GrantEffectsRoles {
4
4
  }
5
5
  /** Do this process's part of whatever changed grant `grantId`, from its row as it reads now. Idempotent. */
6
6
  export declare function applyGrantEffects(roles: GrantEffectsRoles, grantId: string): Promise<void>;
7
- /** Subscribe this process to `grant:<id>` signals. Returns the unsubscribe. */
8
- export declare function startGrantEffects(roles: GrantEffectsRoles): Promise<() => void>;
7
+ /** Subscribe this process to `grant:<id>` signals. Returns the unsubscribe. A process that runs lanes also looks every `sweepMs` for a
8
+ * removal that is still owed (a cascade that failed, or one no signal or catch-up reached) and runs it again. */
9
+ export declare function startGrantEffects(roles: GrantEffectsRoles, tuning?: {
10
+ sweepMs?: number;
11
+ }): Promise<() => void>;
@@ -1 +1 @@
1
- var v=Object.defineProperty;var a=(t,e)=>v(t,"name",{value:e,configurable:!0});import{openDb as l}from"../../core/canvas/db.js";import{isCloudRole as _}from"../../core/canvas/person.js";import{endLiveExecution as E,liveExecutionForNode as y}from"../../core/canvas/executions.js";import{emitEvent as c}from"../../core/events/emit.js";import{afterRevocationStop as S}from"../../core/grants/on-sync.js";import{allGrants as u,grantIdsWhere as h,grantStanding as m,mirrorOnly as b}from"../../core/grants/mirror.js";import{removeApp as g,removePersonData as k}from"../../core/grants/remove.js";import{wakeAllGrantWaiters as N,wakeGrantWaiters as x}from"../../core/grants/watch.js";import{discardOrphanedTokens as p,discardTokensForGrant as O}from"../../core/providers/token-cache.js";import{runnerForExecution as T}from"../../core/runtime/runner/index.js";import{closeGrantStreams as L,heldGrantIds as D}from"../../core/runs/events.js";import{stopNodeSandboxes as R}from"../../core/spaces/stop.js";import{brokerSignalBus as G}from"../broker-signals/bus.js";import{withRowClaim as A}from"./row-claim.js";const P=6e4;function f(t,e,r){c({level:"error",event:`daemon.grants.${t}`,error:e,fields:r})}a(f,"failed");function C(t,e,r){try{const n=e.sub===null||e.grantee===null?p(r):O({sub:e.sub,grantee:e.grantee,active:e.standing==="active"},r);n.tokens>0&&c({level:"info",event:"daemon.grants.outbound_tokens_discarded",fields:{grant:t,tokens:n.tokens}})}catch(n){f("outbound_tokens_discard_failed",n,{grant:t})}}a(C,"discardTokens");async function w(){try{await(await import("../../core/providers/bundles.js")).syncProviderBundles()}catch(t){c({level:"error",event:"daemon.providers.bundle_sync_failed",error:t})}}a(w,"reconcileProviderBundles");async function W(t,e){if(x(t),e.standing==="inactive"){const r=L(t);r>0&&c({level:"info",event:"daemon.grants.streams_closed",fields:{grant:t,grantee:e.grantee,streams:r}})}await w()}a(W,"serveEffects");async function F(t,e){const r=await A("nodes",t,P,async n=>{const o=await y(t);if(o===null)return;await n.assertOwned(),c({level:"info",event:"daemon.grants.node_stop",node_id:t,fields:{grant:e,execution_id:o.executionId}});const i=a(async()=>{await n.assertOwned(),await E(t,{reason:"permission_revoked"}),await S(t)},"finish");if(o.runner==="process"){const d=await R(t,"permission_revoked",{holdRecovery:!0,after:i});if(!d.confirmed)throw d.error??new Error(`stop of ${t} was not confirmed`);return}const s=await T(o.runner).stop(o,{reason:"permission_revoked"});if(!s.confirmed)throw s.error??new Error(`stop of ${t} was not confirmed`);await i()})}a(F,"stopRevokedNode");async function M(t,e){if(!(e.grantee!==null&&b({grantee:e.grantee}))){if(e.standing==="inactive"){const r=await(await l()).prepare("SELECT DISTINCT n.node_id FROM nodes n JOIN executions e ON e.node_id = n.node_id AND e.state != 'exited' WHERE n.grant_id = ?").all(t);for(const{node_id:n}of r)try{await F(n,t)}catch(o){f("node_stop_failed",o,{grant:t,node_id:n})}}if(e.status==="removed"&&e.removal_done_at===null&&e.grantee!==null&&e.sub!==null)try{e.grantee!=="app:terminal"?await g(e.grantee,e.sub):_()?await k(e.grantee,e.sub):c({level:"info",event:"daemon.grants.removal_settled_without_cleanup",fields:{grant:t,grantee:e.grantee,sub:e.sub}}),await(await l()).prepare("UPDATE grants SET removal_done_at = ? WHERE id = ? AND rev = ? AND removal_done_at IS NULL").run(new Date().toISOString(),t,e.rev)}catch(r){f("removal_failed",r,{grant:t,grantee:e.grantee})}}}a(M,"laneEffects");async function U(t,e){const r=await m(e);C(e,r,await u()),await Promise.all([t.serves?W(e,r):void 0,t.runsLanes&&r.standing!=="lagging"?M(e,r):void 0])}a(U,"applyGrantEffects");async function $(t){const e=new Set;if(t.serves)for(const n of D())e.add(n);if(t.runsLanes){const n=await(await l()).prepare("SELECT DISTINCT n.grant_id FROM nodes n JOIN executions e ON e.node_id = n.node_id AND e.state != 'exited' WHERE n.grant_id IS NOT NULL").all();for(const{grant_id:o}of n)e.add(o)}const r=[];for(const n of e)(await m(n)).status===null&&r.push(n);return r}a($,"goneGrantIds");async function re(t){const e=new Map,r=a(o=>{const i=(e.get(o)??Promise.resolve()).then(()=>U(t,o)).catch(s=>f("effects_failed",s,{grant:o})).finally(()=>{e.get(o)===i&&e.delete(o)});return e.set(o,i),i},"run"),n=a(async()=>{const o=t.serves?w():void 0;try{t.serves&&N(),p(await u());const i=new Set(await h(`status <> 'active' OR expires_at <= '${new Date().toISOString()}'`));for(const s of await $(t))i.add(s);await Promise.all([...i].map(r))}catch(i){f("catch_up_failed",i,{})}await o},"catchUp");return await G.subscribe(o=>{r(o)},{kinds:["grant"],onListenStart:a(()=>{n()},"onListenStart")})}a(re,"startGrantEffects");export{U as applyGrantEffects,re as startGrantEffects};
1
+ var k=Object.defineProperty;var a=(t,e)=>k(t,"name",{value:e,configurable:!0});import{canvasPoolSize as x,openDb as p}from"../../core/canvas/db.js";import{isCloudRole as L}from"../../core/canvas/person.js";import{endLiveExecution as O,liveExecutionForNode as D}from"../../core/canvas/executions.js";import{emitEvent as u}from"../../core/events/emit.js";import{afterRevocationStop as M}from"../../core/grants/on-sync.js";import{allGrants as h,grantIdsWhere as y,grantStanding as E,mirrorOnly as R}from"../../core/grants/mirror.js";import{removeApp as A,removePersonData as P}from"../../core/grants/remove.js";import{wakeAllGrantWaiters as G,wakeGrantWaiters as C}from"../../core/grants/watch.js";import{discardOrphanedTokens as g,discardTokensForGrant as W}from"../../core/providers/token-cache.js";import{isUnsandboxedMachine as F}from"../../core/runtime/unsandboxed.js";import{runnerForExecution as U}from"../../core/runtime/runner/index.js";import{closeGrantStreams as B,heldGrantIds as $}from"../../core/runs/events.js";import{stopNodeSandboxes as H}from"../../core/spaces/stop.js";import{brokerSignalBus as J}from"../broker-signals/bus.js";import{withRowClaim as z}from"./row-claim.js";const K=6e4,V=a(()=>Math.max(1,Math.floor(x()/3)),"grantSlotLimit");let v=0;const b=[];async function X(t){for(;v>=V();)await new Promise(e=>{b.push(e)});v+=1;try{return await t()}finally{v-=1,b.shift()?.()}}a(X,"withGrantSlot");const Y=3e4,j=5;function d(t,e,n){u({level:"error",event:`daemon.grants.${t}`,error:e,fields:n})}a(d,"failed");function q(t,e,n){try{const r=e.sub===null||e.grantee===null?g(n):W({sub:e.sub,grantee:e.grantee,active:e.standing==="active"},n);r.tokens>0&&u({level:"info",event:"daemon.grants.outbound_tokens_discarded",fields:{grant:t,tokens:r.tokens}})}catch(r){d("outbound_tokens_discard_failed",r,{grant:t})}}a(q,"discardTokens");async function N(){try{await(await import("../../core/providers/bundles.js")).syncProviderBundles()}catch(t){u({level:"error",event:"daemon.providers.bundle_sync_failed",error:t})}}a(N,"reconcileProviderBundles");async function Q(t,e){if(C(t),e.standing==="inactive"){const n=B(t);n>0&&u({level:"info",event:"daemon.grants.streams_closed",fields:{grant:t,grantee:e.grantee,streams:n}})}await N()}a(Q,"serveEffects");async function Z(t,e){const n=await z("nodes",t,K,async r=>{const i=await D(t);if(i===null)return;await r.assertOwned(),u({level:"info",event:"daemon.grants.node_stop",node_id:t,fields:{grant:e,execution_id:i.executionId}});const l=a(async()=>{await r.assertOwned(),await O(t,{reason:"permission_revoked"}),await M(t)},"finish");if(i.runner==="process"){const m=await H(t,"permission_revoked",{holdRecovery:!0,after:l});if(!m.confirmed)throw m.error??new Error(`stop of ${t} was not confirmed`);return}const f=await U(i.runner).stop(i,{reason:"permission_revoked"});if(!f.confirmed)throw f.error??new Error(`stop of ${t} was not confirmed`);await l()})}a(Z,"stopRevokedNode");async function I(t,e){if(!(e.grantee!==null&&R({grantee:e.grantee}))){if(e.standing==="inactive"){const n=await(await p()).prepare("SELECT DISTINCT n.node_id FROM nodes n JOIN executions e ON e.node_id = n.node_id AND e.state != 'exited' WHERE n.grant_id = ?").all(t);for(const{node_id:r}of n)try{await Z(r,t)}catch(i){d("node_stop_failed",i,{grant:t,node_id:r})}}if(e.status==="removed"&&e.removal_done_at===null&&e.grantee!==null&&e.sub!==null)try{e.grantee!=="app:terminal"?await A(e.grantee,e.sub):L()?await P(e.grantee,e.sub):u({level:"info",event:"daemon.grants.removal_settled_without_cleanup",fields:{grant:t,grantee:e.grantee,sub:e.sub}}),await(await p()).prepare("UPDATE grants SET removal_done_at = ? WHERE id = ? AND rev = ? AND removal_done_at IS NULL").run(new Date().toISOString(),t,e.rev)}catch(n){d("removal_failed",n,{grant:t,grantee:e.grantee})}}}a(I,"laneEffects");async function ee(t,e){let n;await X(async()=>{const r=await E(e);q(e,r,await h()),t.serves&&(n=Q(e,r)),t.runsLanes&&r.standing!=="lagging"&&await I(e,r)}),await n}a(ee,"applyGrantEffects");async function te(t){const e=new Set;if(t.serves)for(const r of $())e.add(r);if(t.runsLanes){const r=await(await p()).prepare("SELECT DISTINCT n.grant_id FROM nodes n JOIN executions e ON e.node_id = n.node_id AND e.state != 'exited' WHERE n.grant_id IS NOT NULL").all();for(const{grant_id:i}of r)e.add(i)}const n=[];for(const r of e)(await E(r)).status===null&&n.push(r);return n}a(te,"goneGrantIds");async function Se(t,e={}){const n=new Map,r=a(o=>{const c=(n.get(o)??Promise.resolve()).then(()=>ee(t,o)).catch(s=>d("effects_failed",s,{grant:o})).finally(()=>{n.get(o)===c&&n.delete(o)});return n.set(o,c),c},"run"),i=a(async()=>{const o=t.serves?N():void 0;try{t.serves&&G(),g(await h());const c=new Set(await y(`status <> 'active' OR expires_at <= '${new Date().toISOString()}'`));for(const s of await te(t))c.add(s);await Promise.all([...c].map(r))}catch(c){d("catch_up_failed",c,{})}await o},"catchUp"),l=new Map;let f=!1;const m=a(async()=>{if(!f){f=!0;try{const o=new Set(await y(`status = 'removed' AND removal_done_at IS NULL${F()?" AND grantee = 'app:terminal'":""}`));for(const s of l.keys())o.has(s)||l.delete(s);const c=[...o].filter(s=>!n.has(s)&&(l.get(s)?.notBefore??0)<=Date.now());await Promise.all(c.map(async s=>{await r(s);const S=(l.get(s)?.failures??0)+1;l.set(s,{failures:S,notBefore:Date.now()+_*2**Math.min(S,j)})}))}catch(o){d("removal_sweep_failed",o,{})}finally{f=!1}}},"sweepRemovals"),_=e.sweepMs??Y,w=t.runsLanes?setInterval(()=>{m()},_):void 0;w?.unref();const T=await J.subscribe(o=>{r(o)},{kinds:["grant"],onListenStart:a(()=>{i()},"onListenStart")});return()=>{w!==void 0&&clearInterval(w),T()}}a(Se,"startGrantEffects");export{ee as applyGrantEffects,Se as startGrantEffects};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.602",
3
+ "version": "0.3.603",
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.602",
148
+ "@north-light/identity": "0.3.603",
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",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@north-light/identity",
3
- "version": "0.3.602",
3
+ "version": "0.3.603",
4
4
  "description": "Northlight access-token verification and scope rules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/runtime.lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@north-light/cli",
3
- "version": "0.3.602",
3
+ "version": "0.3.603",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@north-light/cli",
9
- "version": "0.3.602",
9
+ "version": "0.3.603",
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.602",
31
+ "@north-light/identity": "0.3.603",
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.602",
11959
+ "version": "0.3.603",
11960
11960
  "license": "UNLICENSED"
11961
11961
  },
11962
11962
  "packages/crouter-env-docker": {
11963
11963
  "name": "@north-light/env-docker",
11964
- "version": "0.3.602",
11964
+ "version": "0.3.603",
11965
11965
  "license": "UNLICENSED"
11966
11966
  },
11967
11967
  "packages/crouter-identity": {
11968
11968
  "name": "@north-light/identity",
11969
- "version": "0.3.602",
11969
+ "version": "0.3.603",
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.602",
11977
+ "version": "0.3.603",
11978
11978
  "license": "UNLICENSED",
11979
11979
  "dependencies": {
11980
- "@north-light/api": "0.3.602",
11981
- "@north-light/identity": "0.3.602"
11980
+ "@north-light/api": "0.3.603",
11981
+ "@north-light/identity": "0.3.603"
11982
11982
  }
11983
11983
  },
11984
11984
  "packages/crouter-sdk": {
11985
11985
  "name": "@north-light/sdk",
11986
- "version": "0.3.602",
11986
+ "version": "0.3.603",
11987
11987
  "license": "UNLICENSED",
11988
11988
  "dependencies": {
11989
- "@north-light/api": "0.3.602",
11990
- "@north-light/identity": "0.3.602",
11991
- "@north-light/plugin": "0.3.602",
11989
+ "@north-light/api": "0.3.603",
11990
+ "@north-light/identity": "0.3.603",
11991
+ "@north-light/plugin": "0.3.603",
11992
11992
  "jose": "^6.2.1"
11993
11993
  },
11994
11994
  "bin": {