@tomflow/chatloop-extension 0.4.6 → 0.4.8

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/bin/cli.mjs CHANGED
@@ -133,7 +133,7 @@ if(help!==null){
133
133
  }
134
134
  // After the CLI reply is produced, allow bounded observation delivery.
135
135
  // This never changes its result or retries its business side effect.
136
- const audit=await cliContract[Symbol.for('chat-loop.telemetry.drain.internal')]?.(4200);
136
+ const audit=await cliContract[Symbol.for('chat-loop.telemetry.drain.internal')]?.(5000);
137
137
  if(audit?.status!=='OK'){
138
138
  // Sanitized counters only; the already-emitted RESULT is authoritative.
139
139
  process.stderr.write('CHAT_LOOP_AUDIT_GAP '+JSON.stringify({
@@ -77,7 +77,7 @@ process.stdin.on('data',async chunk=>{
77
77
  // Observation-only requests cannot recursively generate Native audit.
78
78
  // Never delay their Writer receipt for an unrelated drain timeout.
79
79
  if(!observationOnly){
80
- const audit=await hostContract[Symbol.for('chat-loop.telemetry.drain.internal')]?.(2500);
80
+ const audit=await hostContract[Symbol.for('chat-loop.telemetry.drain.internal')]?.(4200);
81
81
  if(audit?.status!=='OK'){
82
82
  // The business reply is already written and remains authoritative.
83
83
  process.stderr.write('CHAT_LOOP_AUDIT_GAP '+JSON.stringify({
@@ -1,11 +1,11 @@
1
1
  // Keep each API span ordered at the existing single Supervisor writer.
2
2
  // Telemetry is best-effort: it neither changes nor retries the business call.
3
3
  // Concurrent spans are allowed; BEGIN and terminal of one call never race.
4
- function createOrderedApiObservationSender(deliver,{parallel=16,capacity=2048}={}){
4
+ function createOrderedApiObservationSender(deliver,{parallel=8,capacity=2048}={}){
5
5
  if(typeof deliver!=='function'||!Number.isInteger(parallel)||parallel<1||
6
6
  !Number.isInteger(capacity)||capacity<2)throw TypeError('OBSERVATION_SENDER_INVALID');
7
7
  const waiting=[],active=new Set();
8
- const health={submitted:0,confirmed:0,dropped:0,failed:0};
8
+ const health={submitted:0,confirmed:0,dropped:0,failed:0,lastFailureCode:null};
9
9
  let running=0,scheduled=false;
10
10
  function pump(){
11
11
  scheduled=false;
@@ -18,8 +18,12 @@ function createOrderedApiObservationSender(deliver,{parallel=16,capacity=2048}={
18
18
  Promise.resolve().then(()=>deliver(record)).then(result=>{
19
19
  success=result!==false;
20
20
  if(success)health.confirmed++;
21
- else health.failed++;
22
- },()=>{health.failed++}).finally(()=>{
21
+ else{health.failed++;health.lastFailureCode='OBSERVATION_REJECTED'}
22
+ },error=>{
23
+ health.failed++;
24
+ health.lastFailureCode=/^[A-Z][A-Z0-9_]{1,95}$/.test(error?.code||'')
25
+ ?error.code:'OBSERVATION_TRANSPORT_FAILED';
26
+ }).finally(()=>{
23
27
  // Keep later terminal evidence even when BEGIN transport failed:
24
28
  // an orphan terminal is an auditable gap, not an invisible call.
25
29
  active.delete(id);running--;resolve(success);schedule();
@@ -34,6 +38,7 @@ function createOrderedApiObservationSender(deliver,{parallel=16,capacity=2048}={
34
38
  health.submitted++;
35
39
  if(waiting.length>=capacity){
36
40
  health.dropped++;
41
+ health.lastFailureCode='OBSERVATION_QUEUE_FULL';
37
42
  return Promise.resolve(false);
38
43
  }
39
44
  return new Promise(resolve=>{waiting.push({record,resolve});schedule()});
@@ -59,7 +64,8 @@ function createObservationDrain(aspect,sender){
59
64
  const a=aspect.health(),s=sender.health();
60
65
  state={pending:a.pending+s.pending,inFlight:a.inFlight+s.inFlight,
61
66
  dropped:a.dropped+s.dropped,failed:a.sinkFailures+s.failed,
62
- submitted:s.submitted,confirmed:s.confirmed};
67
+ submitted:s.submitted,confirmed:s.confirmed,
68
+ lastFailureCode:s.lastFailureCode};
63
69
  if(state.pending===0&&state.inFlight===0)break;
64
70
  }while(Date.now()<deadline);
65
71
  return Object.freeze({...state,status:state.pending||state.inFlight
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "manifest_version": 3,
3
3
  "name": "Chat Loop Extension",
4
- "version": "0.4.6",
4
+ "version": "0.4.8",
5
5
  "description": "Chat Loop browser companion: Eye actions, Turn observer, Continue and Handoff Actions",
6
6
  "permissions": [
7
7
  "activeTab",
@@ -1,11 +1,11 @@
1
1
  // Keep each API span ordered at the existing single Supervisor writer.
2
2
  // Telemetry is best-effort: it neither changes nor retries the business call.
3
3
  // Concurrent spans are allowed; BEGIN and terminal of one call never race.
4
- export function createOrderedApiObservationSender(deliver,{parallel=16,capacity=2048}={}){
4
+ export function createOrderedApiObservationSender(deliver,{parallel=8,capacity=2048}={}){
5
5
  if(typeof deliver!=='function'||!Number.isInteger(parallel)||parallel<1||
6
6
  !Number.isInteger(capacity)||capacity<2)throw TypeError('OBSERVATION_SENDER_INVALID');
7
7
  const waiting=[],active=new Set();
8
- const health={submitted:0,confirmed:0,dropped:0,failed:0};
8
+ const health={submitted:0,confirmed:0,dropped:0,failed:0,lastFailureCode:null};
9
9
  let running=0,scheduled=false;
10
10
  function pump(){
11
11
  scheduled=false;
@@ -18,8 +18,12 @@ export function createOrderedApiObservationSender(deliver,{parallel=16,capacity=
18
18
  Promise.resolve().then(()=>deliver(record)).then(result=>{
19
19
  success=result!==false;
20
20
  if(success)health.confirmed++;
21
- else health.failed++;
22
- },()=>{health.failed++}).finally(()=>{
21
+ else{health.failed++;health.lastFailureCode='OBSERVATION_REJECTED'}
22
+ },error=>{
23
+ health.failed++;
24
+ health.lastFailureCode=/^[A-Z][A-Z0-9_]{1,95}$/.test(error?.code||'')
25
+ ?error.code:'OBSERVATION_TRANSPORT_FAILED';
26
+ }).finally(()=>{
23
27
  // Keep later terminal evidence even when BEGIN transport failed:
24
28
  // an orphan terminal is an auditable gap, not an invisible call.
25
29
  active.delete(id);running--;resolve(success);schedule();
@@ -34,6 +38,7 @@ export function createOrderedApiObservationSender(deliver,{parallel=16,capacity=
34
38
  health.submitted++;
35
39
  if(waiting.length>=capacity){
36
40
  health.dropped++;
41
+ health.lastFailureCode='OBSERVATION_QUEUE_FULL';
37
42
  return Promise.resolve(false);
38
43
  }
39
44
  return new Promise(resolve=>{waiting.push({record,resolve});schedule()});
@@ -59,7 +64,8 @@ export function createObservationDrain(aspect,sender){
59
64
  const a=aspect.health(),s=sender.health();
60
65
  state={pending:a.pending+s.pending,inFlight:a.inFlight+s.inFlight,
61
66
  dropped:a.dropped+s.dropped,failed:a.sinkFailures+s.failed,
62
- submitted:s.submitted,confirmed:s.confirmed};
67
+ submitted:s.submitted,confirmed:s.confirmed,
68
+ lastFailureCode:s.lastFailureCode};
63
69
  if(state.pending===0&&state.inFlight===0)break;
64
70
  }while(Date.now()<deadline);
65
71
  return Object.freeze({...state,status:state.pending||state.inFlight
@@ -65,9 +65,11 @@ export async function nativeContextControl(command,args){
65
65
  return reply.result;
66
66
  }
67
67
 
68
- // Independent, best-effort observation channel. These records contain only
69
- // generated call IDs, allowlisted API names and timings; never business data.
70
- // A missing Supervisor only drops telemetry, never retries a native action.
68
+ // Independent, best-effort observation channel. No business data.
69
+ // A separate identity ping for every event (or a shared ping for a burst)
70
+ // caused the observed Supervisor IPC timeout fan-out. The existing private
71
+ // manager.lock contains the current Manager identity: include it on the
72
+ // observation itself, then let the Supervisor verify it atomically on receipt.
71
73
  const API_UUID=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
72
74
  const API_NAME=/^extension\.[A-Za-z][A-Za-z0-9_.:-]{1,119}$/;
73
75
  const API_CODE=/^[A-Z][A-Z0-9_]{1,95}$/;
@@ -92,16 +94,17 @@ export async function nativeApiObservation(record){
92
94
  (process.getuid&&stat.uid!==process.getuid()))
93
95
  throw fail('API_OBSERVATION_UNTRUSTED');
94
96
  privateFile(join(dir,'control.sock'),'socket');
95
- privateFile(join(dir,'manager.lock'),'file');
96
- const hello=await ipc({action:'__ping'},700);
97
- const owner=JSON.parse(readFileSync(join(dir,'manager.lock'),'utf8'));
98
- if(hello.contract!=='chat-loop.local-control.v1'||
99
- hello.ownerNonce!==owner.nonce||hello.managerPid!==owner.pid||
100
- hello.version!==owner.version||hello.version!==hello.packageVersion)
101
- throw fail('API_OBSERVATION_OWNER_MISMATCH');
102
- const request={contract:hello.contract,action:'__api_observation',
103
- requestId:randomUUID(),...record};
104
- const response=await ipc(request,1100);
105
- return response.contract===hello.contract&&
97
+ const lockFile=join(dir,'manager.lock');
98
+ privateFile(lockFile,'file');
99
+ const manager=JSON.parse(readFileSync(lockFile,'utf8'));
100
+ if(!API_UUID.test(manager.nonce||'')||!Number.isSafeInteger(manager.pid)
101
+ ||manager.pid<1||typeof manager.version!=='string')
102
+ throw fail('API_OBSERVATION_OWNER_UNTRUSTED');
103
+ const request={contract:'chat-loop.local-control.v1',action:'__api_observation',
104
+ requestId:randomUUID(),ownerNonce:manager.nonce,managerPid:manager.pid,...record};
105
+ // The Supervisor verifies ownerNonce and managerPid before appending.
106
+ // This is one socket and one ACK per event, never an Action retry.
107
+ const response=await ipc(request,3500);
108
+ return response.contract===request.contract&&
106
109
  response.requestId===request.requestId&&response.status==='OK';
107
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "type": "module",
5
5
  "description": "Chat Loop Extension package: nine formal Action pages and its own native CLI bridge",
6
6
  "bin": {