@dailephd/my-centcom 0.1.0 → 0.3.0

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 (175) hide show
  1. package/README.md +10 -5
  2. package/apps/daemon/dist/artifacts/returnSnapshots.d.ts +12 -0
  3. package/apps/daemon/dist/artifacts/returnSnapshots.js +41 -0
  4. package/apps/daemon/dist/bootstrap/app.d.ts +21 -0
  5. package/apps/daemon/dist/bootstrap/app.js +27 -0
  6. package/apps/daemon/dist/bootstrap/installLayout.d.ts +81 -0
  7. package/apps/daemon/dist/bootstrap/installLayout.js +164 -0
  8. package/apps/daemon/dist/bootstrap/main.d.ts +14 -0
  9. package/apps/daemon/dist/bootstrap/main.js +141 -0
  10. package/apps/daemon/dist/bootstrap/operatorConsole.d.ts +75 -0
  11. package/apps/daemon/dist/bootstrap/operatorConsole.js +293 -0
  12. package/apps/daemon/dist/bootstrap/privateDataRoot.d.ts +38 -0
  13. package/apps/daemon/dist/bootstrap/privateDataRoot.js +204 -0
  14. package/apps/daemon/dist/bootstrap/secureMain.d.ts +118 -0
  15. package/apps/daemon/dist/bootstrap/secureMain.js +403 -0
  16. package/apps/daemon/dist/bootstrap/setup.d.ts +93 -0
  17. package/apps/daemon/dist/bootstrap/setup.js +738 -0
  18. package/apps/daemon/dist/context/changeProposal.d.ts +97 -0
  19. package/apps/daemon/dist/context/changeProposal.js +259 -0
  20. package/apps/daemon/dist/context/gitEvidence.d.ts +88 -0
  21. package/apps/daemon/dist/context/gitEvidence.js +332 -0
  22. package/apps/daemon/dist/context/gitObservation.d.ts +30 -0
  23. package/apps/daemon/dist/context/gitObservation.js +113 -0
  24. package/apps/daemon/dist/context/projectReadIssuer.d.ts +68 -0
  25. package/apps/daemon/dist/context/projectReadIssuer.js +158 -0
  26. package/apps/daemon/dist/context/projectReadService.d.ts +153 -0
  27. package/apps/daemon/dist/context/projectReadService.js +652 -0
  28. package/apps/daemon/dist/context/projectViewService.d.ts +85 -0
  29. package/apps/daemon/dist/context/projectViewService.js +332 -0
  30. package/apps/daemon/dist/context/proposalRecorder.d.ts +11 -0
  31. package/apps/daemon/dist/context/proposalRecorder.js +19 -0
  32. package/apps/daemon/dist/plugins/drivers/codexMcpConfig.d.ts +40 -0
  33. package/apps/daemon/dist/plugins/drivers/codexMcpConfig.js +73 -0
  34. package/apps/daemon/dist/plugins/drivers/codexModelCompatibility.d.ts +49 -0
  35. package/apps/daemon/dist/plugins/drivers/codexModelCompatibility.js +70 -0
  36. package/apps/daemon/dist/plugins/drivers/fakePluginDriver.d.ts +16 -0
  37. package/apps/daemon/dist/plugins/drivers/fakePluginDriver.js +115 -0
  38. package/apps/daemon/dist/plugins/drivers/finiteCliDriver.d.ts +153 -0
  39. package/apps/daemon/dist/plugins/drivers/finiteCliDriver.js +505 -0
  40. package/apps/daemon/dist/plugins/registry/operationCatalog.d.ts +23 -0
  41. package/apps/daemon/dist/plugins/registry/operationCatalog.js +41 -0
  42. package/apps/daemon/dist/plugins/registry/registryOperationCatalog.d.ts +14 -0
  43. package/apps/daemon/dist/plugins/registry/registryOperationCatalog.js +29 -0
  44. package/apps/daemon/dist/plugins/registry/verifiedCapabilityRegistry.d.ts +151 -0
  45. package/apps/daemon/dist/plugins/registry/verifiedCapabilityRegistry.js +579 -0
  46. package/apps/daemon/dist/projects/codingAuthority.d.ts +102 -0
  47. package/apps/daemon/dist/projects/codingAuthority.js +244 -0
  48. package/apps/daemon/dist/projects/fixtureAuthorization.d.ts +54 -0
  49. package/apps/daemon/dist/projects/fixtureAuthorization.js +172 -0
  50. package/apps/daemon/dist/projects/pairedAuthority.d.ts +158 -0
  51. package/apps/daemon/dist/projects/pairedAuthority.js +273 -0
  52. package/apps/daemon/dist/projects/trustedCliConsent.d.ts +47 -0
  53. package/apps/daemon/dist/projects/trustedCliConsent.js +84 -0
  54. package/apps/daemon/dist/runs/changeApplier.d.ts +59 -0
  55. package/apps/daemon/dist/runs/changeApplier.js +319 -0
  56. package/apps/daemon/dist/runs/codingWorkflowService.d.ts +283 -0
  57. package/apps/daemon/dist/runs/codingWorkflowService.js +785 -0
  58. package/apps/daemon/dist/runs/durableIntentCoordinator.d.ts +72 -0
  59. package/apps/daemon/dist/runs/durableIntentCoordinator.js +160 -0
  60. package/apps/daemon/dist/runs/inMemoryCoordinator.d.ts +55 -0
  61. package/apps/daemon/dist/runs/inMemoryCoordinator.js +375 -0
  62. package/apps/daemon/dist/runs/runExecutor.d.ts +154 -0
  63. package/apps/daemon/dist/runs/runExecutor.js +295 -0
  64. package/apps/daemon/dist/runs/workflowService.d.ts +185 -0
  65. package/apps/daemon/dist/runs/workflowService.js +300 -0
  66. package/apps/daemon/dist/runtime/boundedProcessHost.d.ts +111 -0
  67. package/apps/daemon/dist/runtime/boundedProcessHost.js +752 -0
  68. package/apps/daemon/dist/runtime/evidenceRedaction.d.ts +30 -0
  69. package/apps/daemon/dist/runtime/evidenceRedaction.js +79 -0
  70. package/apps/daemon/dist/runtime/executionDiagnostics.d.ts +134 -0
  71. package/apps/daemon/dist/runtime/executionDiagnostics.js +213 -0
  72. package/apps/daemon/dist/runtime/modelExecutionPolicy.d.ts +22 -0
  73. package/apps/daemon/dist/runtime/modelExecutionPolicy.js +19 -0
  74. package/apps/daemon/dist/runtime/mxcExecution.d.ts +12 -0
  75. package/apps/daemon/dist/runtime/mxcExecution.js +163 -0
  76. package/apps/daemon/dist/runtime/mxcIntegrity.d.ts +24 -0
  77. package/apps/daemon/dist/runtime/mxcIntegrity.js +81 -0
  78. package/apps/daemon/dist/runtime/mxcWorker.d.ts +2 -0
  79. package/apps/daemon/dist/runtime/mxcWorker.js +45 -0
  80. package/apps/daemon/dist/runtime/provisionedExecution.d.ts +150 -0
  81. package/apps/daemon/dist/runtime/provisionedExecution.js +653 -0
  82. package/apps/daemon/dist/runtime/testExecution.d.ts +76 -0
  83. package/apps/daemon/dist/runtime/testExecution.js +106 -0
  84. package/apps/daemon/dist/runtime/testProfiles.d.ts +10 -0
  85. package/apps/daemon/dist/runtime/testProfiles.js +4 -0
  86. package/apps/daemon/dist/runtime/trustedAgentStaging.d.ts +89 -0
  87. package/apps/daemon/dist/runtime/trustedAgentStaging.js +262 -0
  88. package/apps/daemon/dist/runtime/trustedCaBundle.d.ts +77 -0
  89. package/apps/daemon/dist/runtime/trustedCaBundle.js +125 -0
  90. package/apps/daemon/dist/runtime/windows/windowsJobSupervisor.d.ts +166 -0
  91. package/apps/daemon/dist/runtime/windows/windowsJobSupervisor.js +521 -0
  92. package/apps/daemon/dist/storage/diagnosticLog.d.ts +63 -0
  93. package/apps/daemon/dist/storage/diagnosticLog.js +136 -0
  94. package/apps/daemon/dist/storage/executionTelemetry.d.ts +63 -0
  95. package/apps/daemon/dist/storage/executionTelemetry.js +247 -0
  96. package/apps/daemon/dist/storage/protectedSecrets.d.ts +39 -0
  97. package/apps/daemon/dist/storage/protectedSecrets.js +106 -0
  98. package/apps/daemon/dist/storage/sqliteLedger.d.ts +786 -0
  99. package/apps/daemon/dist/storage/sqliteLedger.js +1303 -0
  100. package/apps/daemon/dist/transports/http/dispatch.d.ts +43 -0
  101. package/apps/daemon/dist/transports/http/dispatch.js +405 -0
  102. package/apps/daemon/dist/transports/http/secureRoutes.d.ts +40 -0
  103. package/apps/daemon/dist/transports/http/secureRoutes.js +332 -0
  104. package/apps/daemon/dist/transports/http/workflowRoutes.d.ts +41 -0
  105. package/apps/daemon/dist/transports/http/workflowRoutes.js +473 -0
  106. package/apps/daemon/dist/transports/mcp/localProjectReadServer.d.ts +182 -0
  107. package/apps/daemon/dist/transports/mcp/localProjectReadServer.js +221 -0
  108. package/apps/daemon/dist/transports/native/nativeHost.d.ts +24 -0
  109. package/apps/daemon/dist/transports/native/nativeHost.js +344 -0
  110. package/apps/daemon/package.json +24 -0
  111. package/apps/daemon/src/runtime/benign/referenceEcho.mjs +27 -0
  112. package/apps/daemon/src/runtime/windows/buildSupervisor.mjs +87 -0
  113. package/apps/daemon/src/runtime/windows/supervisorMain.cs +676 -0
  114. package/apps/extension/manifest.secure.json +25 -0
  115. package/apps/extension/scripts/build.mjs +173 -0
  116. package/apps/extension/src/background/secureWorker.ts +1595 -0
  117. package/apps/extension/src/background/serviceWorker.ts +892 -0
  118. package/apps/extension/src/content/captureSelection.ts +64 -0
  119. package/apps/extension/src/content/secureInsert.ts +207 -0
  120. package/apps/extension/src/probe/index.html +41 -0
  121. package/apps/extension/src/probe/main.ts +201 -0
  122. package/apps/extension/src/sidepanel/index.html +203 -0
  123. package/apps/extension/src/sidepanel/main.ts +903 -0
  124. package/package.json +19 -3
  125. package/packages/contracts/dist/artifacts.d.ts +66 -0
  126. package/packages/contracts/dist/artifacts.js +64 -0
  127. package/packages/contracts/dist/automation.d.ts +540 -0
  128. package/packages/contracts/dist/automation.js +191 -0
  129. package/packages/contracts/dist/browser.d.ts +251 -0
  130. package/packages/contracts/dist/browser.js +131 -0
  131. package/packages/contracts/dist/context.d.ts +71 -0
  132. package/packages/contracts/dist/context.js +73 -0
  133. package/packages/contracts/dist/diagnostics.d.ts +99 -0
  134. package/packages/contracts/dist/diagnostics.js +284 -0
  135. package/packages/contracts/dist/effects.d.ts +42 -0
  136. package/packages/contracts/dist/effects.js +42 -0
  137. package/packages/contracts/dist/errors.d.ts +75 -0
  138. package/packages/contracts/dist/errors.js +70 -0
  139. package/packages/contracts/dist/events.d.ts +50 -0
  140. package/packages/contracts/dist/events.js +34 -0
  141. package/packages/contracts/dist/executionDiagnostics.d.ts +212 -0
  142. package/packages/contracts/dist/executionDiagnostics.js +101 -0
  143. package/packages/contracts/dist/identity.d.ts +54 -0
  144. package/packages/contracts/dist/identity.js +40 -0
  145. package/packages/contracts/dist/index.d.ts +20 -0
  146. package/packages/contracts/dist/index.js +20 -0
  147. package/packages/contracts/dist/invocation.d.ts +90 -0
  148. package/packages/contracts/dist/invocation.js +77 -0
  149. package/packages/contracts/dist/lifecycle.d.ts +130 -0
  150. package/packages/contracts/dist/lifecycle.js +135 -0
  151. package/packages/contracts/dist/plugin.d.ts +214 -0
  152. package/packages/contracts/dist/plugin.js +117 -0
  153. package/packages/contracts/dist/projectRead.d.ts +205 -0
  154. package/packages/contracts/dist/projectRead.js +162 -0
  155. package/packages/contracts/dist/secure.d.ts +128 -0
  156. package/packages/contracts/dist/secure.js +99 -0
  157. package/packages/contracts/package.json +32 -0
  158. package/packages/contracts/src/artifacts.ts +83 -0
  159. package/packages/contracts/src/automation.ts +238 -0
  160. package/packages/contracts/src/browser.ts +164 -0
  161. package/packages/contracts/src/context.ts +91 -0
  162. package/packages/contracts/src/diagnostics.ts +318 -0
  163. package/packages/contracts/src/effects.ts +49 -0
  164. package/packages/contracts/src/errors.ts +83 -0
  165. package/packages/contracts/src/events.ts +46 -0
  166. package/packages/contracts/src/executionDiagnostics.ts +116 -0
  167. package/packages/contracts/src/identity.ts +68 -0
  168. package/packages/contracts/src/index.ts +20 -0
  169. package/packages/contracts/src/invocation.ts +96 -0
  170. package/packages/contracts/src/lifecycle.ts +169 -0
  171. package/packages/contracts/src/plugin.ts +174 -0
  172. package/packages/contracts/src/projectRead.ts +179 -0
  173. package/packages/contracts/src/secure.ts +136 -0
  174. package/provenance.json +179 -9
  175. package/source.zip +0 -0
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Manifest V3 Content Script for the M03/M04 fixture path.
3
+ * Invariant: Captures ONLY elements marked with data-centcom-fixture-message.
4
+ * Does not scrape arbitrary DOM or claim ChatGPT Web DOM verification.
5
+ */
6
+
7
+ const FIXTURE_SELECTOR = '[data-centcom-fixture-message]';
8
+
9
+ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
10
+ // Only this extension's own worker may request a capture; page scripts cannot reach this listener.
11
+ if (sender.id !== chrome.runtime.id) {
12
+ return false;
13
+ }
14
+
15
+ if (message?.action === 'CAPTURE_SELECTION') {
16
+ const fixtureElements = document.querySelectorAll(FIXTURE_SELECTOR);
17
+
18
+ if (fixtureElements.length === 0) {
19
+ sendResponse({
20
+ success: false,
21
+ error: 'No element with [data-centcom-fixture-message] found in document',
22
+ });
23
+ return true;
24
+ }
25
+
26
+ if (fixtureElements.length > 1) {
27
+ sendResponse({
28
+ success: false,
29
+ error: 'Multiple [data-centcom-fixture-message] elements found; selection is ambiguous',
30
+ });
31
+ return true;
32
+ }
33
+
34
+ const fixtureElement = fixtureElements[0];
35
+ const text = fixtureElement.textContent?.trim() ?? '';
36
+ if (text.length === 0) {
37
+ sendResponse({
38
+ success: false,
39
+ error: 'Fixture message element is empty',
40
+ });
41
+ return true;
42
+ }
43
+
44
+ const conversationId =
45
+ fixtureElement.getAttribute('data-centcom-conversation-id') ||
46
+ 'conversation.m03-fixture';
47
+
48
+ sendResponse({
49
+ success: true,
50
+ text,
51
+ conversationId,
52
+ sourceUrl: window.location.href,
53
+ metadata: {
54
+ tagName: fixtureElement.tagName,
55
+ id: fixtureElement.id,
56
+ url: window.location.href,
57
+ hasExplicitMarker: true,
58
+ },
59
+ });
60
+ return true;
61
+ }
62
+
63
+ return false;
64
+ });
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Composer insertion (C01), B05 + SW-060 editor adapter + SW-061 ProseMirror adapter + SW-064 native-editing mechanism. This function is NOT a content
3
+ * script and is never declared in the manifest: the secure worker passes it to chrome.scripting.executeScript as `func` (ISOLATED world, one tab, main
4
+ * frame only), so Chrome serialises it. It must therefore stay fully self-contained: no imports, no module-level references, no chrome.* API.
5
+ *
6
+ * Contract. It writes `text` into the page's single supported composer as a DRAFT and nothing else:
7
+ * - top-level document only, and only the document the worker captured from (the per-document nonce kept in the isolated world by the capture
8
+ * function must equal `expectedNonce`; a reloaded or replaced document has none);
9
+ * - exactly ONE candidate composer. A candidate is either an element with id "prompt-textarea" (the legacy shape) or a ProseMirror editor: a DIV with
10
+ * class "ProseMirror", role "textbox", aria-multiline "true" and contenteditable "true"/"". The real chatgpt.com composer is the latter and carries NO
11
+ * id. Any other contenteditable is never a candidate. Zero candidates (COMPOSER_UNAVAILABLE), several (COMPOSER_AMBIGUOUS), or one that is hidden,
12
+ * disabled or read-only are refused and nothing is changed. Editors:
13
+ * TEXTAREA a <textarea>: the value property is set;
14
+ * PROSEMIRROR the validated ProseMirror editor, and
15
+ * CONTENTEDITABLE any other id "prompt-textarea" contenteditable block editor, both edited through the BROWSER'S NATIVE EDITING COMMANDS
16
+ * (SW-064): the composer is focused, a caret is placed in its first block, then document.execCommand('insertText') writes each line
17
+ * and document.execCommand('insertParagraph') separates lines. These are real user-level edits (beforeinput/input events, selection
18
+ * and DOM mutation produced by the browser itself), which the editor's own input handling turns into a transaction. The former
19
+ * mechanism (replacing the editor's paragraphs with foreign DOM nodes) only worked if the editor happened to adopt a foreign
20
+ * mutation, and a live editor that did not adopt it showed the text briefly and then dropped it. No HTML is parsed (literal text
21
+ * only), no clipboard, no synthetic paste or key event;
22
+ * A non-empty draft is never touched;
23
+ * - it never presses Enter or any key, never clicks, never submits a form, never reads or writes the clipboard. It DOES focus the composer (needed for
24
+ * native editing) and leaves it focused so the draft stays visible and editable;
25
+ * - success needs ALL of: the exact text in every block, the expected block shape, no placeholder marker on nonempty content, and that exact state
26
+ * held across repeated reads for a stable window (an editor that reverts or normalizes the change asynchronously is caught). Contenteditable failure is ROLLED
27
+ * BACK to the original empty state (select-all + native delete) and the result says truthfully whether the original state really came back
28
+ * (`restored`). Focus loss or trusted concurrent input prevents rollback, preserving user edits. Textarea failures also preserve observed bytes.
29
+ * INSERTED is only ever reported for exact LF text (including spaces, tabs, Unicode and trailing newlines), stable for 600ms.
30
+ * CR text is refused, never silently normalized. READBACK_MISMATCH is never downgraded. This bounded observation is not a promise against later edits.
31
+ * The result carries a fixed code only, a fixed-vocabulary count-only `detail`, and (failures after the page was touched) a privacy-preserving `diag`
32
+ * string made only of stage, byte lengths, a short non-reversible checksum of each side, the first mismatch offset and character CATEGORIES. Never text.
33
+ */
34
+ export interface InsertResult {
35
+ ok: boolean;
36
+ code?: string;
37
+ readback?: string;
38
+ editor?: 'TEXTAREA' | 'CONTENTEDITABLE' | 'PROSEMIRROR';
39
+ /** Failure after the page was touched only: true when the original empty state was verified back, false when it was not. */
40
+ restored?: boolean;
41
+ /** Count-only diagnostic token, e.g. "CANDIDATES=0". Never page text. */
42
+ detail?: string;
43
+ /** Privacy-preserving mismatch diagnostics, e.g. "S=SETTLE E=21 O=0 F=0 X=SPACE C=END D=1A2B3C4D.811C9DC5 P=1 R=1". Never page text. */
44
+ diag?: string;
45
+ }
46
+
47
+ export async function insertInPage(text: string, expectedNonce: string): Promise<InsertResult> {
48
+ const w = window as unknown as Record<string, unknown>;
49
+ if (window !== window.top) return { ok: false, code: 'NOT_TOP_FRAME' };
50
+ if (typeof w.__centcomDocNonce !== 'string' || w.__centcomDocNonce !== expectedNonce) return { ok: false, code: 'DOCUMENT_CHANGED' };
51
+
52
+ const candidates = new Set<Element>(Array.from(document.querySelectorAll('[id="prompt-textarea"]')));
53
+ for (const e of Array.from(document.querySelectorAll('div.ProseMirror[role="textbox"]'))) {
54
+ const c = e.getAttribute('contenteditable');
55
+ if (e.getAttribute('aria-multiline') === 'true' && (c === 'true' || c === '')) candidates.add(e);
56
+ }
57
+ if (candidates.size === 0) return { ok: false, code: 'COMPOSER_UNAVAILABLE', detail: 'CANDIDATES=0' };
58
+ if (candidates.size > 1) return { ok: false, code: 'COMPOSER_AMBIGUOUS', detail: `CANDIDATES=${candidates.size}` };
59
+ const el = Array.from(candidates)[0];
60
+ const fire = (): void => { el.dispatchEvent(new Event('input', { bubbles: true })); };
61
+ const visible = el.getClientRects().length > 0 && getComputedStyle(el).visibility !== 'hidden';
62
+ const sleep = (ms: number): Promise<void> => new Promise((r) => { setTimeout(r, ms); });
63
+
64
+ if (el instanceof HTMLTextAreaElement) {
65
+ if (el.disabled || el.readOnly || !visible) return { ok: false, code: 'COMPOSER_UNAVAILABLE', detail: 'CANDIDATE_NOT_USABLE' };
66
+ if (el.value !== '') return { ok: false, code: 'COMPOSER_NOT_EMPTY' };
67
+ const setter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
68
+ if (typeof setter !== 'function') return { ok: false, code: 'COMPOSER_UNSUPPORTED' };
69
+ // Textarea cannot represent CR faithfully. No trimming, Unicode or whitespace
70
+ // normalization is permitted: compare LF text exactly, including the final LF.
71
+ if (text.includes('\r')) return { ok: false, code: 'COMPOSER_UNSUPPORTED', detail: 'CARRIAGE_RETURN' };
72
+ el.focus({ preventScroll: true });
73
+ if (document.activeElement !== el) return { ok: false, code: 'COMPOSER_UNAVAILABLE' };
74
+ setter.call(el, text);
75
+ fire();
76
+ const started = Date.now();
77
+ let stable = true;
78
+ while (Date.now() - started < 600) {
79
+ await sleep(40);
80
+ if (!el.isConnected || document.activeElement !== el || el.value !== text) { stable = false; break; }
81
+ }
82
+ if (!stable) {
83
+ // A framework or a person may have changed the draft during the wait. Do
84
+ // not erase their bytes or steal focus to perform a speculative rollback.
85
+ return { ok: false, code: 'READBACK_MISMATCH', restored: el.isConnected && el.value === '' };
86
+ }
87
+ return { ok: true, readback: el.value, editor: 'TEXTAREA' };
88
+ }
89
+
90
+ const ce = el.getAttribute('contenteditable');
91
+ if (el instanceof HTMLElement && (ce === 'true' || ce === '') && el.isContentEditable) {
92
+ if (el.getAttribute('aria-disabled') === 'true' || el.getAttribute('aria-readonly') === 'true' || !visible) return { ok: false, code: 'COMPOSER_UNAVAILABLE', detail: 'CANDIDATE_NOT_USABLE' };
93
+ const isPm = el.tagName === 'DIV' && el.classList.contains('ProseMirror') && el.getAttribute('role') === 'textbox';
94
+ // empty means: no text at all and nothing but (at most) one placeholder block that holds only line breaks
95
+ const emptyShape = (): boolean => {
96
+ const blocks = Array.from(el.children);
97
+ const placeholderOnly = blocks.length === 0 || (blocks.length === 1 && blocks[0].textContent === '' && blocks[0].querySelectorAll('*:not(br)').length === 0);
98
+ return el.textContent === '' && placeholderOnly && el.childNodes.length === blocks.length;
99
+ };
100
+ if (!emptyShape()) return { ok: false, code: 'COMPOSER_NOT_EMPTY' };
101
+ if (text.indexOf('\r') >= 0) return { ok: false, code: 'COMPOSER_UNSUPPORTED', detail: 'CARRIAGE_RETURN' };
102
+ const marker = '[data-empty-paragraph="true"]';
103
+ const hadMarker = el.querySelector(marker) !== null;
104
+ const lines = text.split('\n');
105
+
106
+ // ---- privacy-preserving diagnostics: lengths, short checksums, first mismatch offset and character categories only ----
107
+ const h32 = (s: string): string => {
108
+ let h = 0x811c9dc5;
109
+ for (let i = 0; i < s.length; i += 1) { h ^= s.charCodeAt(i); h = Math.imul(h, 0x01000193) >>> 0; }
110
+ return h.toString(16).toUpperCase().padStart(8, '0');
111
+ };
112
+ const cat = (c: string | undefined): string => {
113
+ if (c === undefined) return 'END';
114
+ if (c === ' ') return 'SPACE';
115
+ if (c === ' ') return 'NBSP';
116
+ if (c === '\t') return 'TAB';
117
+ if (c === '\n') return 'NEWLINE';
118
+ if (/\s/.test(c)) return 'OTHERWS';
119
+ if (/[A-Za-z]/.test(c)) return 'LETTER';
120
+ if (/[0-9]/.test(c)) return 'DIGIT';
121
+ return c.charCodeAt(0) > 0x7f ? 'NONASCII' : 'PUNCT';
122
+ };
123
+ const nbytes = (s: string): number => new TextEncoder().encode(s).length;
124
+ const diagOf = (stage: string, observed: string, rolledBack: boolean | undefined): string => {
125
+ let off = 0;
126
+ while (off < text.length && off < observed.length && text[off] === observed[off]) off += 1;
127
+ const ph = el.isConnected && el.querySelector(marker) !== null ? 1 : 0;
128
+ const parts = [`S=${stage}`, `E=${nbytes(text)}`, `O=${nbytes(observed)}`, `F=${off}`, `X=${cat(text[off])}`, `C=${cat(observed[off])}`, `D=${h32(text)}.${h32(observed)}`, `P=${ph}`];
129
+ if (rolledBack !== undefined) parts.push(`R=${rolledBack ? 1 : 0}`);
130
+ return parts.join(' ').slice(0, 100);
131
+ };
132
+
133
+ const read = (): { dom: string; shapeOk: boolean } => {
134
+ const blocks = Array.from(el.children);
135
+ return {
136
+ dom: blocks.map((b) => b.textContent ?? '').join('\n'),
137
+ shapeOk: blocks.length === lines.length && el.childNodes.length === blocks.length && blocks.every((b) => Array.from(b.children).every((c) => c.tagName === 'BR')),
138
+ };
139
+ };
140
+ // Empty paragraphs may legitimately retain their placeholder decoration in
141
+ // a nonempty document. A marker on nonempty content remains inconsistent.
142
+ const exact = (): boolean => {
143
+ if (!el.isConnected) return false;
144
+ const r = read();
145
+ return r.dom === text && r.shapeOk && Array.from(el.querySelectorAll(marker)).every((p) => p.textContent === '');
146
+ };
147
+ const selectIn = (node: Node, whole: boolean): void => {
148
+ const sel = window.getSelection();
149
+ if (!sel) return;
150
+ const range = document.createRange();
151
+ if (whole) range.selectNodeContents(node); else { range.setStart(node, 0); range.collapse(true); }
152
+ sel.removeAllRanges();
153
+ sel.addRange(range);
154
+ };
155
+
156
+ // ---- native editing: focus, caret in the first block, one insertText per line and one insertParagraph between lines ----
157
+ el.focus({ preventScroll: true });
158
+ if (document.activeElement !== el) return { ok: false, code: 'COMPOSER_UNAVAILABLE', detail: 'CANDIDATE_NOT_FOCUSABLE' };
159
+ selectIn(el.firstElementChild ?? el, false);
160
+ let execOk = true;
161
+ for (let i = 0; i < lines.length && execOk; i += 1) {
162
+ if (i > 0) execOk = document.execCommand('insertParagraph');
163
+ if (execOk && lines[i].length > 0) execOk = document.execCommand('insertText', false, lines[i]);
164
+ }
165
+
166
+ // ---- prove persistence: the exact state must appear AND stay for a stable window; an editor that reverts or normalizes later is caught ----
167
+ const STABLE_MS = 600; const DEADLINE_MS = 3000;
168
+ let userEdited = false;
169
+ const onEdit = (event: Event): void => { if (event.isTrusted) userEdited = true; };
170
+ el.addEventListener('beforeinput', onEdit);
171
+ const t0 = Date.now();
172
+ let exactSince = -1; let stage = execOk ? 'SETTLE' : 'EXEC'; let ok = false;
173
+ while (execOk && Date.now() - t0 < DEADLINE_MS) {
174
+ await sleep(40);
175
+ if (userEdited) { stage = 'USER'; break; }
176
+ if (!el.isConnected) { stage = 'DETACHED'; break; }
177
+ if (document.activeElement !== el) { stage = 'FOCUS'; break; }
178
+ if (exact()) {
179
+ if (exactSince < 0) exactSince = Date.now();
180
+ if (Date.now() - exactSince >= STABLE_MS) { ok = true; break; }
181
+ } else if (exactSince >= 0) { stage = 'STABLE'; break; } // was exact, then the editor changed it
182
+ }
183
+ el.removeEventListener('beforeinput', onEdit);
184
+ if (ok) return { ok: true, readback: read().dom, editor: isPm ? 'PROSEMIRROR' : 'CONTENTEDITABLE' };
185
+
186
+ // ---- not exactly held: restore the original empty state through the same native path and verify it truly came back ----
187
+ const observation = el.isConnected ? read() : { dom: '', shapeOk: false };
188
+ const observed = observation.dom;
189
+ let restored = false;
190
+ if (!userEdited && el.isConnected && document.activeElement === el) {
191
+ el.focus({ preventScroll: true });
192
+ selectIn(el, true);
193
+ document.execCommand('delete');
194
+ for (let i = 0; i < 10 && !restored; i += 1) {
195
+ await sleep(i === 0 ? 0 : 40);
196
+ restored = el.isConnected && emptyShape() && (!hadMarker || el.querySelector(marker) !== null);
197
+ }
198
+ if (restored) { // an editor may re-adopt text late: the original state must also STAY back
199
+ await sleep(300);
200
+ restored = el.isConnected && emptyShape() && (!hadMarker || el.querySelector(marker) !== null);
201
+ }
202
+ }
203
+ return { ok: false, code: 'READBACK_MISMATCH', restored, diag: diagOf(stage, observed, restored),
204
+ ...((stage === 'SETTLE' || stage === 'STABLE') && observed === text ? { detail: observation.shapeOk ? 'PLACEHOLDER_MISMATCH' : 'BLOCK_SHAPE_MISMATCH' } : {}) };
205
+ }
206
+ return { ok: false, code: 'COMPOSER_UNSUPPORTED' };
207
+ }
@@ -0,0 +1,41 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <title>my-centcom M04 Walking Skeleton Probe</title>
6
+ <style>
7
+ body {
8
+ font-family: sans-serif;
9
+ margin: 20px;
10
+ }
11
+ #preview-area,
12
+ #result-area {
13
+ margin-top: 15px;
14
+ padding: 10px;
15
+ border: 1px solid #ccc;
16
+ min-height: 24px;
17
+ font-family: monospace;
18
+ }
19
+ #status-area {
20
+ margin-top: 10px;
21
+ color: #555;
22
+ }
23
+ </style>
24
+ </head>
25
+ <body>
26
+ <h1>my-centcom M04 Extension Probe</h1>
27
+ <button id="preview-button">Preview fixture selection</button>
28
+ <button id="dispatch-button" disabled>Dispatch fixture prompt</button>
29
+
30
+ <button id="evidence-button">Fetch read-only fixture evidence</button>
31
+ <button id="prepare-return-button" disabled>Prepare Return (test-only, no ChatGPT submission)</button>
32
+
33
+ <div id="status-area">IDLE</div>
34
+ <div id="evidence-area" data-testid="evidence"></div>
35
+ <div id="cargo-area" data-testid="cargo"></div>
36
+ <div id="preview-area"></div>
37
+ <div id="result-area"></div>
38
+
39
+ <script type="module" src="main.js"></script>
40
+ </body>
41
+ </html>
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Probe Page Controller for the M03/M04 fixture path.
3
+ * Invariants:
4
+ * - Nothing is dispatched on page load.
5
+ * - Dispatch is disabled until the user has explicitly obtained a successful preview.
6
+ * - Only fixed, worker-controlled status codes are rendered; raw daemon payloads are never shown.
7
+ */
8
+
9
+ interface PreviewState {
10
+ tabId: number;
11
+ sourceUrl: string;
12
+ conversationId: string;
13
+ fingerprint: string;
14
+ }
15
+
16
+ interface WorkerFailure {
17
+ errorType?: unknown;
18
+ errorCode?: unknown;
19
+ statusCode?: unknown;
20
+ }
21
+
22
+ function describeFailure(response: WorkerFailure | undefined): string {
23
+ const type = typeof response?.errorType === 'string' ? response.errorType : 'UNKNOWN_ERROR';
24
+ const code = typeof response?.errorCode === 'string' ? ` ${response.errorCode}` : '';
25
+ const status = typeof response?.statusCode === 'number' ? ` (HTTP ${response.statusCode})` : '';
26
+ return `${type}${code}${status}`;
27
+ }
28
+
29
+ window.addEventListener('DOMContentLoaded', () => {
30
+ const previewButton = document.getElementById('preview-button') as HTMLButtonElement | null;
31
+ const dispatchButton = document.getElementById('dispatch-button') as HTMLButtonElement | null;
32
+ const resultArea = document.getElementById('result-area') as HTMLDivElement | null;
33
+ const statusArea = document.getElementById('status-area') as HTMLDivElement | null;
34
+ const previewArea = document.getElementById('preview-area') as HTMLDivElement | null;
35
+
36
+ if (!previewButton || !dispatchButton || !resultArea || !statusArea || !previewArea) {
37
+ console.error('[probe] Required UI elements not found in probe DOM');
38
+ return;
39
+ }
40
+
41
+ // Test configuration from URL query params. No default daemon port is assumed.
42
+ const urlParams = new URLSearchParams(window.location.search);
43
+ const daemonUrl = urlParams.get('daemonUrl') ?? '';
44
+ const token = urlParams.get('token') ?? '';
45
+ const targetTabParam = urlParams.get('targetTabId');
46
+ const targetTabId =
47
+ targetTabParam !== null && /^[0-9]+$/.test(targetTabParam) ? Number(targetTabParam) : undefined;
48
+
49
+ let preview: PreviewState | undefined;
50
+ // One identity pair per preview: repeated Dispatch clicks are idempotent retries,
51
+ // while a new preview begins a new logical operation.
52
+ let requestId: string | undefined;
53
+ let idempotencyKey: string | undefined;
54
+
55
+ const resetPreview = () => {
56
+ preview = undefined;
57
+ dispatchButton.disabled = true;
58
+ previewArea.textContent = '';
59
+ previewArea.removeAttribute('data-fingerprint');
60
+ previewArea.removeAttribute('data-tab-id');
61
+ };
62
+
63
+ statusArea.textContent = 'READY';
64
+
65
+ previewButton.addEventListener('click', async () => {
66
+ statusArea.textContent = 'PREVIEWING';
67
+ resultArea.textContent = '';
68
+ resetPreview();
69
+
70
+ try {
71
+ const response = await chrome.runtime.sendMessage({
72
+ action: 'PREVIEW_FIXTURE_SELECTION',
73
+ targetTabId,
74
+ });
75
+
76
+ if (response && response.success === true && response.preview) {
77
+ const p = response.preview;
78
+ preview = {
79
+ tabId: p.tabId,
80
+ sourceUrl: p.sourceUrl,
81
+ conversationId: p.conversationId,
82
+ fingerprint: p.fingerprint,
83
+ };
84
+ previewArea.textContent = String(p.text);
85
+ previewArea.setAttribute('data-fingerprint', String(p.fingerprint));
86
+ previewArea.setAttribute('data-tab-id', String(p.tabId));
87
+ requestId = urlParams.get('requestId') || `req.m04-${crypto.randomUUID()}`;
88
+ idempotencyKey = urlParams.get('idempotencyKey') || `idem.m04-${crypto.randomUUID()}`;
89
+ dispatchButton.disabled = false;
90
+ statusArea.textContent = 'PREVIEWED';
91
+ } else {
92
+ statusArea.textContent = `PREVIEW_ERROR: ${describeFailure(response)}`;
93
+ }
94
+ } catch {
95
+ statusArea.textContent = 'PREVIEW_ERROR: MESSAGE_FAILED';
96
+ }
97
+ });
98
+
99
+ // --- M04 read-only evidence + test-only Prepare Return (no composer interaction) ---
100
+ const evidenceButton = document.getElementById('evidence-button') as HTMLButtonElement | null;
101
+ const prepareButton = document.getElementById('prepare-return-button') as HTMLButtonElement | null;
102
+ const evidenceArea = document.getElementById('evidence-area') as HTMLDivElement | null;
103
+ const cargoArea = document.getElementById('cargo-area') as HTMLDivElement | null;
104
+ let evidenceRequestId: string | undefined;
105
+
106
+ if (evidenceButton && prepareButton && evidenceArea && cargoArea) {
107
+ evidenceButton.addEventListener('click', async () => {
108
+ statusArea.textContent = 'FETCHING_EVIDENCE';
109
+ evidenceArea.textContent = '';
110
+ cargoArea.textContent = '';
111
+ prepareButton.disabled = true;
112
+ try {
113
+ const response = await chrome.runtime.sendMessage({
114
+ action: 'FETCH_FIXTURE_EVIDENCE',
115
+ daemonUrl,
116
+ token,
117
+ requestId: urlParams.get('evidenceRequestId') || undefined,
118
+ relativePath: urlParams.get('evidencePath') || undefined,
119
+ });
120
+ if (response && response.success === true) {
121
+ evidenceRequestId = String(response.requestId);
122
+ evidenceArea.textContent = String(response.file.content);
123
+ evidenceArea.setAttribute('data-sha256', String(response.file.sha256));
124
+ evidenceArea.setAttribute('data-request-id', evidenceRequestId);
125
+ prepareButton.disabled = response.hasSelection !== true;
126
+ statusArea.textContent = 'EVIDENCE_OK';
127
+ } else {
128
+ statusArea.textContent = `EVIDENCE_ERROR: ${describeFailure(response)}`;
129
+ }
130
+ } catch {
131
+ statusArea.textContent = 'EVIDENCE_ERROR: MESSAGE_FAILED';
132
+ }
133
+ });
134
+
135
+ prepareButton.addEventListener('click', async () => {
136
+ if (!evidenceRequestId) {
137
+ statusArea.textContent = 'ERROR: EVIDENCE_REQUIRED';
138
+ return;
139
+ }
140
+ try {
141
+ const response = await chrome.runtime.sendMessage({
142
+ action: 'PREPARE_FIXTURE_RETURN',
143
+ requestId: evidenceRequestId,
144
+ });
145
+ if (response && response.success === true) {
146
+ cargoArea.textContent = String(response.cargo.markdownSnippet);
147
+ cargoArea.setAttribute('data-cargo', JSON.stringify(response));
148
+ statusArea.textContent = `RETURN_PREPARED: ${response.deliveryStatus}`;
149
+ } else {
150
+ statusArea.textContent = `PREPARE_ERROR: ${describeFailure(response)}`;
151
+ }
152
+ } catch {
153
+ statusArea.textContent = 'PREPARE_ERROR: MESSAGE_FAILED';
154
+ }
155
+ });
156
+ }
157
+
158
+ dispatchButton.addEventListener('click', async () => {
159
+ if (!preview) {
160
+ statusArea.textContent = 'ERROR: PREVIEW_REQUIRED';
161
+ return;
162
+ }
163
+
164
+ statusArea.textContent = 'DISPATCHING';
165
+ resultArea.textContent = '';
166
+ dispatchButton.disabled = true;
167
+ previewButton.disabled = true;
168
+
169
+ try {
170
+ const response = await chrome.runtime.sendMessage({
171
+ action: 'DISPATCH_FIXTURE_PROMPT',
172
+ daemonUrl,
173
+ token,
174
+ preview,
175
+ requestId,
176
+ idempotencyKey,
177
+ });
178
+
179
+ if (response && response.success === true) {
180
+ statusArea.textContent = 'SUCCESS';
181
+ resultArea.textContent = typeof response.outputSummary === 'string' ? response.outputSummary : 'OK';
182
+ dispatchButton.disabled = false;
183
+ } else {
184
+ statusArea.textContent = `ERROR: ${describeFailure(response)}`;
185
+ resultArea.textContent = '';
186
+ if (response?.errorType === 'STALE_REQUEST_OR_SELECTION') {
187
+ // A stale preview must be replaced by a new explicit preview before any further dispatch.
188
+ resetPreview();
189
+ } else {
190
+ dispatchButton.disabled = false;
191
+ }
192
+ }
193
+ } catch {
194
+ statusArea.textContent = 'FATAL: MESSAGE_FAILED';
195
+ resultArea.textContent = '';
196
+ dispatchButton.disabled = false;
197
+ } finally {
198
+ previewButton.disabled = false;
199
+ }
200
+ });
201
+ });