@tomflow/chatloop-extension 0.4.12 → 0.4.14

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.
Files changed (36) hide show
  1. package/README.md +2 -2
  2. package/actions.generated.mjs +2 -1
  3. package/bin/cli.mjs +17 -8
  4. package/bin/native-host.mjs +26 -7
  5. package/capabilities/entry_test.mjs +1 -0
  6. package/extension/actions/clean.js +6 -3
  7. package/extension/actions/common.js +5 -2
  8. package/extension/actions/continue.js +22 -4
  9. package/extension/actions/entry_test.js +186 -0
  10. package/extension/actions/handoff.js +19 -4
  11. package/extension/actions/model-intent.js +4 -2
  12. package/extension/actions/start.js +11 -3
  13. package/extension/actions/status.js +2 -1
  14. package/extension/entry-test.html +6 -0
  15. package/extension/loop/api-observation-queue.generated.js +11 -3
  16. package/extension/loop/observer-approval.js +10 -9
  17. package/extension/manifest.json +1 -1
  18. package/extension/popup.js +9 -3
  19. package/extension/worker/action-result.js +2 -2
  20. package/extension/worker/action-take.js +8 -10
  21. package/extension/worker/adopt-prepare.js +7 -2
  22. package/extension/worker/adopt-recovery.js +2 -1
  23. package/extension/worker/adopt-result.js +7 -1
  24. package/extension/worker/bootstrap.js +16 -5
  25. package/extension/worker/manual.js +5 -7
  26. package/extension/worker/router.js +12 -3
  27. package/extension/worker/scheduler.js +35 -21
  28. package/extension/worker/turn-finished.js +11 -6
  29. package/lib/action-routing.mjs +1 -1
  30. package/lib/api-observation-queue.mjs +11 -3
  31. package/lib/bridge.mjs +50 -6
  32. package/lib/context-ipc.mjs +5 -1
  33. package/lib/owner-evidence.mjs +5 -1
  34. package/lib/session-file.mjs +27 -3
  35. package/package.json +3 -3
  36. package/scripts/build-actions.mjs +6 -2
@@ -72,7 +72,9 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
72
72
  // same-Chat, same-generation, one-shot recovery CAS. No new Chat,
73
73
  // task, project, approval or Handoff may be smuggled into recovery.
74
74
  if(replaceBlockedSessionId || !old || old.phase!=='BLOCKED'
75
- ||resumeBlockedUpdatedAt!==null&&old.updatedAt!==resumeBlockedUpdatedAt
75
+ ||!Number.isSafeInteger(resumeBlockedUpdatedAt)
76
+ ||resumeBlockedUpdatedAt<=0
77
+ ||old.updatedAt!==resumeBlockedUpdatedAt
76
78
  ||old.sessionId!==resumeBlockedSessionId
77
79
  ||next.sessionId!==old.sessionId
78
80
  ||next.projectId!==old.projectId
@@ -94,6 +96,20 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
94
96
  if(next.projectId!==old.projectId)throw fail('SESSION_PROJECT_CHANGED');
95
97
  if(next.taskId!==old.taskId)throw fail('SESSION_TASK_CHANGED');
96
98
  if(next.generation<old.generation)throw fail('SESSION_STALE_GENERATION');
99
+ // One verified Handoff advances exactly one generation. A skipped
100
+ // generation cannot become a durable Owner identity.
101
+ if(next.generation>old.generation+1)throw fail('SESSION_GENERATION_GAP');
102
+ if(next.generation===old.generation+1
103
+ &&(old.activeChatId===null||next.activeChatId===null
104
+ ||next.activeChatId===old.activeChatId))
105
+ throw fail('SESSION_HANDOFF_IDENTITY_UNVERIFIED');
106
+ // A terminal session may be re-read or fenced, not reassigned to
107
+ // another Chat or generation under the same sessionId.
108
+ if(['DONE','BLOCKED'].includes(old.phase)
109
+ &&(next.generation!==old.generation
110
+ ||next.activeChatId!==old.activeChatId
111
+ ||next.activeChatUrl!==old.activeChatUrl))
112
+ throw fail('SESSION_TERMINAL_IDENTITY_CHANGED');
97
113
  if(old.phase==='DONE'&&next.phase!=='DONE'||old.phase==='BLOCKED'
98
114
  && !['BLOCKED','DONE'].includes(next.phase)
99
115
  &&!(resumeBlockedSessionId===old.sessionId
@@ -111,10 +127,18 @@ export function writeSession(input,replaceBlockedSessionId=null,resumeBlockedSes
111
127
  && ['sessionId','projectId','taskId','phase','generation',
112
128
  'activeChatId','activeChatUrl'].every(key=>old[key]===next[key]))
113
129
  return old;
130
+ // updatedAt is the Native recovery CAS value, not merely display time.
131
+ // Two Worker transitions can occur inside one millisecond. Every actual
132
+ // write must advance that version; an identical projection returned above
133
+ // deliberately keeps the previous value.
134
+ const committed=old&&next.updatedAt<=old.updatedAt
135
+ ?{...next,updatedAt:old.updatedAt+1}:next;
136
+ if(!Number.isSafeInteger(committed.updatedAt))
137
+ throw fail('SESSION_CLOCK_EXHAUSTED');
114
138
  const temp=join(dir,'.active-session-'+randomUUID()+'.tmp');
115
- try{writeFileSync(temp,JSON.stringify(next,null,2)+'\n',{flag:'wx',mode:0o600});
139
+ try{writeFileSync(temp,JSON.stringify(committed,null,2)+'\n',{flag:'wx',mode:0o600});
116
140
  renameSync(temp,file);
117
141
  }catch(e){try{unlinkSync(temp);}catch{}throw e;}
118
- return next;
142
+ return committed;
119
143
  }finally{closeSync(fd);unlinkSync(lock);}
120
144
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@tomflow/chatloop-extension",
3
- "version": "0.4.12",
3
+ "version": "0.4.14",
4
4
  "type": "module",
5
- "description": "Chat Loop Extension package: nine formal Action pages and its own native CLI bridge",
5
+ "description": "Chat Loop Extension: reviewed formal Action pages, including TEST_ONLY native App entry",
6
6
  "bin": {
7
7
  "chatloop-extension": "bin/cli.mjs"
8
8
  },
@@ -33,6 +33,6 @@
33
33
  ".": "./index.mjs"
34
34
  },
35
35
  "dependencies": {
36
- "@tomflow/chatloop-trace": "0.4.5"
36
+ "@tomflow/chatloop-trace": "0.4.6"
37
37
  }
38
38
  }
@@ -64,12 +64,16 @@ export async function compileActions(source=join(root,'capabilities'),
64
64
  if(c.kind==='eye-read'&&(!c.id.startsWith('chat_')||
65
65
  !['text','dom'].includes(c.readMode)))
66
66
  throw fail('EXTENSION_EYE_READ_MODE_INVALID');
67
- if(newAction && c.kind!=='eye-read')
67
+ const reviewedEntry=c.id==='entry_test' && c.kind==='entry-test'
68
+ &&c.page==='entry-test.html' &&c.cli.join(' ')==='entry test'
69
+ &&c.waitMs===310000 &&c.textResult===true;
70
+ if(newAction && c.kind!=='eye-read' && !reviewedEntry)
68
71
  throw fail('EXTENSION_PRIVILEGED_ACTION_REVIEW_REQUIRED');
69
72
  if((c.id==='chat_text'&&c.readMode!=='text')||
70
73
  (c.id==='chat_dom'&&c.readMode!=='dom'))
71
74
  throw fail('EXTENSION_BUILTIN_EYE_MODE_CHANGED');
72
75
  const page=join(extension,c.page);
76
+ if(reviewedEntry&&!existsSync(page))throw fail('EXTENSION_ENTRY_ACTION_PAGE_MISSING');
73
77
  const generated=existsSync(page)&&
74
78
  readFileSync(page,'utf8').startsWith(generatedMarker);
75
79
  if(!existsSync(page) && !newAction)
@@ -79,7 +83,7 @@ export async function compileActions(source=join(root,'capabilities'),
79
83
  if(!readFileSync(page,'utf8').includes(expected))
80
84
  throw fail('EXTENSION_ACTION_EXECUTOR_MISMATCH');
81
85
  }
82
- actions.push({...c,file,generated:newAction});
86
+ actions.push({...c,file,generated:newAction && c.kind==='eye-read'});
83
87
  }
84
88
  actions.sort((a,b)=>(
85
89
  (originals.indexOf(a.id)<0?99:originals.indexOf(a.id))-