kimaki 0.4.76 → 0.4.78

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 (162) hide show
  1. package/dist/adapter-rest-boundary.test.js +34 -0
  2. package/dist/agent-model.e2e.test.js +2 -20
  3. package/dist/cli.js +50 -13
  4. package/dist/commands/channel-ref.js +16 -0
  5. package/dist/commands/diff.js +20 -85
  6. package/dist/commands/merge-worktree.js +5 -17
  7. package/dist/commands/new-worktree.js +5 -9
  8. package/dist/commands/permissions.js +77 -11
  9. package/dist/commands/resume.js +5 -9
  10. package/dist/commands/screenshare.js +295 -0
  11. package/dist/commands/session.js +6 -17
  12. package/dist/critique-utils.js +95 -0
  13. package/dist/diff-patch-plugin.js +314 -0
  14. package/dist/discord-bot.js +19 -14
  15. package/dist/discord-js-import-boundary.test.js +62 -0
  16. package/dist/discord-utils.js +44 -0
  17. package/dist/event-stream-real-capture.e2e.test.js +2 -20
  18. package/dist/gateway-proxy.e2e.test.js +2 -5
  19. package/dist/generated/cloudflare/browser.js +17 -0
  20. package/dist/generated/cloudflare/client.js +34 -0
  21. package/dist/generated/cloudflare/commonInputTypes.js +10 -0
  22. package/dist/generated/cloudflare/enums.js +48 -0
  23. package/dist/generated/cloudflare/internal/class.js +47 -0
  24. package/dist/generated/cloudflare/internal/prismaNamespace.js +252 -0
  25. package/dist/generated/cloudflare/internal/prismaNamespaceBrowser.js +222 -0
  26. package/dist/generated/cloudflare/internal/query_compiler_fast_bg.js +135 -0
  27. package/dist/generated/cloudflare/models/bot_api_keys.js +1 -0
  28. package/dist/generated/cloudflare/models/bot_tokens.js +1 -0
  29. package/dist/generated/cloudflare/models/channel_agents.js +1 -0
  30. package/dist/generated/cloudflare/models/channel_directories.js +1 -0
  31. package/dist/generated/cloudflare/models/channel_mention_mode.js +1 -0
  32. package/dist/generated/cloudflare/models/channel_models.js +1 -0
  33. package/dist/generated/cloudflare/models/channel_verbosity.js +1 -0
  34. package/dist/generated/cloudflare/models/channel_worktrees.js +1 -0
  35. package/dist/generated/cloudflare/models/forum_sync_configs.js +1 -0
  36. package/dist/generated/cloudflare/models/global_models.js +1 -0
  37. package/dist/generated/cloudflare/models/ipc_requests.js +1 -0
  38. package/dist/generated/cloudflare/models/part_messages.js +1 -0
  39. package/dist/generated/cloudflare/models/scheduled_tasks.js +1 -0
  40. package/dist/generated/cloudflare/models/session_agents.js +1 -0
  41. package/dist/generated/cloudflare/models/session_events.js +1 -0
  42. package/dist/generated/cloudflare/models/session_models.js +1 -0
  43. package/dist/generated/cloudflare/models/session_start_sources.js +1 -0
  44. package/dist/generated/cloudflare/models/thread_sessions.js +1 -0
  45. package/dist/generated/cloudflare/models/thread_worktrees.js +1 -0
  46. package/dist/generated/cloudflare/models.js +1 -0
  47. package/dist/generated/node/browser.js +17 -0
  48. package/dist/generated/node/client.js +37 -0
  49. package/dist/generated/node/commonInputTypes.js +10 -0
  50. package/dist/generated/node/enums.js +48 -0
  51. package/dist/generated/node/internal/class.js +49 -0
  52. package/dist/generated/node/internal/prismaNamespace.js +252 -0
  53. package/dist/generated/node/internal/prismaNamespaceBrowser.js +222 -0
  54. package/dist/generated/node/models/bot_api_keys.js +1 -0
  55. package/dist/generated/node/models/bot_tokens.js +1 -0
  56. package/dist/generated/node/models/channel_agents.js +1 -0
  57. package/dist/generated/node/models/channel_directories.js +1 -0
  58. package/dist/generated/node/models/channel_mention_mode.js +1 -0
  59. package/dist/generated/node/models/channel_models.js +1 -0
  60. package/dist/generated/node/models/channel_verbosity.js +1 -0
  61. package/dist/generated/node/models/channel_worktrees.js +1 -0
  62. package/dist/generated/node/models/forum_sync_configs.js +1 -0
  63. package/dist/generated/node/models/global_models.js +1 -0
  64. package/dist/generated/node/models/ipc_requests.js +1 -0
  65. package/dist/generated/node/models/part_messages.js +1 -0
  66. package/dist/generated/node/models/scheduled_tasks.js +1 -0
  67. package/dist/generated/node/models/session_agents.js +1 -0
  68. package/dist/generated/node/models/session_events.js +1 -0
  69. package/dist/generated/node/models/session_models.js +1 -0
  70. package/dist/generated/node/models/session_start_sources.js +1 -0
  71. package/dist/generated/node/models/thread_sessions.js +1 -0
  72. package/dist/generated/node/models/thread_worktrees.js +1 -0
  73. package/dist/generated/node/models.js +1 -0
  74. package/dist/interaction-handler.js +10 -0
  75. package/dist/kimaki-digital-twin.e2e.test.js +2 -20
  76. package/dist/message-flags-boundary.test.js +54 -0
  77. package/dist/message-formatting.js +3 -62
  78. package/dist/onboarding-tutorial-plugin.js +1 -1
  79. package/dist/opencode-command.js +129 -0
  80. package/dist/opencode-command.test.js +48 -0
  81. package/dist/opencode-interrupt-plugin.js +19 -1
  82. package/dist/opencode-interrupt-plugin.test.js +0 -5
  83. package/dist/opencode-plugin-loading.e2e.test.js +9 -20
  84. package/dist/opencode-plugin.js +4 -4
  85. package/dist/opencode.js +150 -27
  86. package/dist/patch-text-parser.js +97 -0
  87. package/dist/platform/components-v2.js +20 -0
  88. package/dist/platform/discord-adapter.js +1440 -0
  89. package/dist/platform/discord-routes.js +31 -0
  90. package/dist/platform/message-flags.js +8 -0
  91. package/dist/platform/platform-value.js +41 -0
  92. package/dist/platform/slack-adapter.js +872 -0
  93. package/dist/platform/slack-markdown.js +169 -0
  94. package/dist/platform/types.js +4 -0
  95. package/dist/queue-advanced-e2e-setup.js +265 -0
  96. package/dist/queue-advanced-footer.e2e.test.js +173 -0
  97. package/dist/queue-advanced-model-switch.e2e.test.js +299 -0
  98. package/dist/queue-advanced-permissions-typing.e2e.test.js +73 -1
  99. package/dist/runtime-lifecycle.e2e.test.js +2 -20
  100. package/dist/session-handler/event-stream-state.js +5 -0
  101. package/dist/session-handler/event-stream-state.test.js +6 -2
  102. package/dist/session-handler/thread-session-runtime.js +32 -2
  103. package/dist/system-message.js +26 -23
  104. package/dist/test-utils.js +16 -0
  105. package/dist/thread-message-queue.e2e.test.js +2 -20
  106. package/dist/utils.js +3 -1
  107. package/dist/voice-message.e2e.test.js +2 -20
  108. package/dist/voice.js +122 -9
  109. package/dist/voice.test.js +17 -2
  110. package/dist/websockify.js +69 -0
  111. package/dist/worktree-lifecycle.e2e.test.js +308 -0
  112. package/package.json +4 -2
  113. package/skills/critique/SKILL.md +17 -0
  114. package/skills/egaki/SKILL.md +35 -0
  115. package/skills/event-sourcing-state/SKILL.md +252 -0
  116. package/skills/goke/SKILL.md +1 -0
  117. package/skills/npm-package/SKILL.md +21 -2
  118. package/skills/playwriter/SKILL.md +1 -1
  119. package/skills/x-articles/SKILL.md +554 -0
  120. package/src/agent-model.e2e.test.ts +4 -19
  121. package/src/cli.ts +60 -13
  122. package/src/commands/diff.ts +25 -99
  123. package/src/commands/merge-worktree.ts +5 -21
  124. package/src/commands/new-worktree.ts +5 -11
  125. package/src/commands/permissions.ts +100 -15
  126. package/src/commands/resume.ts +5 -12
  127. package/src/commands/screenshare.ts +354 -0
  128. package/src/commands/session.ts +6 -23
  129. package/src/critique-utils.ts +139 -0
  130. package/src/discord-bot.ts +20 -15
  131. package/src/discord-utils.ts +53 -0
  132. package/src/event-stream-real-capture.e2e.test.ts +4 -20
  133. package/src/gateway-proxy.e2e.test.ts +2 -5
  134. package/src/interaction-handler.ts +15 -0
  135. package/src/kimaki-digital-twin.e2e.test.ts +2 -21
  136. package/src/message-formatting.ts +3 -68
  137. package/src/onboarding-tutorial-plugin.ts +1 -1
  138. package/src/opencode-command.test.ts +70 -0
  139. package/src/opencode-command.ts +188 -0
  140. package/src/opencode-interrupt-plugin.test.ts +0 -5
  141. package/src/opencode-interrupt-plugin.ts +34 -1
  142. package/src/opencode-plugin-loading.e2e.test.ts +25 -35
  143. package/src/opencode-plugin.ts +5 -4
  144. package/src/opencode.ts +199 -32
  145. package/src/patch-text-parser.ts +107 -0
  146. package/src/queue-advanced-e2e-setup.ts +273 -0
  147. package/src/queue-advanced-footer.e2e.test.ts +211 -0
  148. package/src/queue-advanced-model-switch.e2e.test.ts +383 -0
  149. package/src/queue-advanced-permissions-typing.e2e.test.ts +92 -0
  150. package/src/runtime-lifecycle.e2e.test.ts +4 -19
  151. package/src/session-handler/event-stream-state.test.ts +6 -2
  152. package/src/session-handler/event-stream-state.ts +5 -0
  153. package/src/session-handler/thread-session-runtime.ts +45 -2
  154. package/src/system-message.ts +26 -23
  155. package/src/test-utils.ts +17 -0
  156. package/src/thread-message-queue.e2e.test.ts +2 -20
  157. package/src/utils.ts +3 -1
  158. package/src/voice-message.e2e.test.ts +3 -20
  159. package/src/voice.test.ts +26 -2
  160. package/src/voice.ts +147 -9
  161. package/src/websockify.ts +101 -0
  162. package/src/worktree-lifecycle.e2e.test.ts +391 -0
@@ -140,6 +140,8 @@ Use Node ESM-compatible compiler settings:
140
140
  ```json
141
141
  {
142
142
  "compilerOptions": {
143
+ "allowImportingTsExtensions": true,
144
+ "rewriteRelativeImportExtensions": true,
143
145
  "rootDir": "src",
144
146
  "outDir": "dist",
145
147
  "module": "nodenext",
@@ -159,7 +161,25 @@ Use Node ESM-compatible compiler settings:
159
161
 
160
162
  - Always use "rootDir": "src"
161
163
  - Add `"DOM"` to `lib` only when browser globals are needed.
162
- - Keep source imports with `.js` extensions in TypeScript ESM files.
164
+ - Use `.ts` and `.tsx` extensions in source imports. `tsc` rewrites them to
165
+ `.js` in the emitted `dist/` output automatically via
166
+ `rewriteRelativeImportExtensions`. This means source code works directly in
167
+ runtimes like `tsx`, `bun`, and frameworks like Next.js that expect `.ts`
168
+ extensions, while the published `dist/` has correct `.js` imports that Node.js
169
+ and other consumers resolve without issues.
170
+ ```ts
171
+ // source (src/index.ts) — use .ts/.tsx extensions
172
+ import { helper } from './utils.ts'
173
+ import { Button } from './button.tsx'
174
+
175
+ // emitted output (dist/index.js) — tsc rewrites to .js
176
+ // import { helper } from './utils.js'
177
+ // import { Button } from './button.js'
178
+ ```
179
+ - Only relative imports are rewritten. Path aliases (`paths` in tsconfig) are
180
+ not supported by `rewriteRelativeImportExtensions` — this is fine since npm
181
+ packages should use relative imports anyway.
182
+ - Requires TypeScript 5.7+. Pin the typescript devDependency to at least `5.7.0`.
163
183
  - Install `@types/node` as a dev dependency whenever Node APIs are used.
164
184
  - If generation is required, keep generators in `scripts/*.ts` and invoke them
165
185
  from package scripts before build/publish.
@@ -201,4 +221,3 @@ test files should be close with the associated source files. for example if you
201
221
 
202
222
  - if you need to use zod always use latest version
203
223
  - always install packages as dev dependencies if used only for scripts, testing or types only
204
- -
@@ -8,7 +8,7 @@ description: Control the user own Chrome browser via Playwriter extension with P
8
8
  **Before using playwriter, you MUST run this command:**
9
9
 
10
10
  ```bash
11
- playwriter skill
11
+ playwriter skill # IMPORTANT! do not use | head here. read in full!
12
12
  ```
13
13
 
14
14
  This outputs the complete documentation including:
@@ -0,0 +1,554 @@
1
+ ---
2
+ name: x-articles
3
+ description: >
4
+ Edit x.com (Twitter) long-form article drafts reliably. Use this for
5
+ markdown imports, bulk formatting, code blocks, headings, lists, and
6
+ repeated inline styling. Inspect and validate with Playwriter, but prefer
7
+ x.com (Twitter) article GraphQL mutations for deterministic updates.
8
+ version: 0.1.0
9
+ ---
10
+
11
+ <!-- Skill for editing x.com (Twitter) article drafts through Playwriter plus content-state mutations. -->
12
+
13
+ Use this skill when editing long-form article drafts on `x.com/compose/articles`
14
+ (Twitter Articles).
15
+
16
+ ## Read Playwriter First
17
+
18
+ Before using this skill, read the `playwriter` skill and run:
19
+
20
+ ```bash
21
+ playwriter skill
22
+ ```
23
+
24
+ This skill assumes Playwriter is already set up and connected to the user's
25
+ existing Chrome session.
26
+
27
+ Read the full output. Do not pipe it through `head`, `tail`, or other
28
+ truncation commands.
29
+
30
+ ## Core idea
31
+
32
+ Use Playwriter for three things:
33
+
34
+ 1. connect to the already-open x.com (Twitter) article draft
35
+ 2. inspect the editor and capture one real network mutation
36
+ 3. validate the final rendered result after updates
37
+
38
+ For anything bigger than a tiny tweak, do **not** rely on manual typing inside
39
+ the editor. Generate the article `content_state` locally and send the same
40
+ GraphQL mutation x.com (Twitter) already uses.
41
+
42
+ ## Editor model
43
+
44
+ The article body is represented as a `content_state` object with two main
45
+ parts:
46
+
47
+ - `blocks`: ordered content blocks
48
+ - `entity_map`: supporting entities, especially code blocks
49
+
50
+ Important block types:
51
+
52
+ - `unstyled` — normal paragraph
53
+ - `header-two` — section subheading
54
+ - `ordered-list-item` — numbered list item
55
+ - `atomic` — embedded block like a markdown code block
56
+
57
+ Important entity type:
58
+
59
+ - `MARKDOWN` — used for code blocks, with the markdown fence stored in
60
+ `entity_map[*].value.data.markdown`
61
+
62
+ Longer example `content_state`:
63
+
64
+ ````json
65
+ {
66
+ "blocks": [
67
+ {
68
+ "key": "k0",
69
+ "text": "event sourcing for application state",
70
+ "type": "header-two",
71
+ "data": {},
72
+ "entity_ranges": [],
73
+ "inline_style_ranges": []
74
+ },
75
+ {
76
+ "key": "k1",
77
+ "text": "your clanker loves state",
78
+ "type": "unstyled",
79
+ "data": {},
80
+ "entity_ranges": [],
81
+ "inline_style_ranges": [
82
+ { "offset": 19, "length": 5, "style": "Bold" }
83
+ ]
84
+ },
85
+ {
86
+ "key": "k2",
87
+ "text": "doubles your final app state",
88
+ "type": "ordered-list-item",
89
+ "data": {},
90
+ "entity_ranges": [],
91
+ "inline_style_ranges": []
92
+ },
93
+ {
94
+ "key": "k3",
95
+ "text": "doubles your bugs",
96
+ "type": "ordered-list-item",
97
+ "data": {},
98
+ "entity_ranges": [],
99
+ "inline_style_ranges": []
100
+ },
101
+ {
102
+ "key": "k4",
103
+ "text": " ",
104
+ "type": "atomic",
105
+ "data": {},
106
+ "entity_ranges": [
107
+ { "key": 0, "offset": 0, "length": 1 }
108
+ ],
109
+ "inline_style_ranges": []
110
+ },
111
+ {
112
+ "key": "k5",
113
+ "text": "if you can derive it, don't store it.",
114
+ "type": "unstyled",
115
+ "data": {},
116
+ "entity_ranges": [],
117
+ "inline_style_ranges": [
118
+ { "offset": 7, "length": 6, "style": "Bold" }
119
+ ]
120
+ }
121
+ ],
122
+ "entity_map": [
123
+ {
124
+ "key": "0",
125
+ "value": {
126
+ "type": "MARKDOWN",
127
+ "mutability": "Mutable",
128
+ "data": {
129
+ "markdown": "```typescript\nfunction shouldShowFooter() {\n return true\n}\n```"
130
+ }
131
+ }
132
+ }
133
+ ]
134
+ }
135
+ ````
136
+
137
+ This is the minimum mental model:
138
+
139
+ - `blocks` is the article in order
140
+ - each paragraph, heading, and list item is a separate block
141
+ - code blocks are `atomic` blocks that point into `entity_map`
142
+ - inline bold lives in `inline_style_ranges`
143
+
144
+ ## Recommended workflow
145
+
146
+ ### 1. Open or locate the draft
147
+
148
+ Find the existing article editor page in the connected browser. The URL format
149
+ is:
150
+
151
+ ```text
152
+ https://x.com/compose/articles/edit/<article_id>
153
+ ```
154
+
155
+ Always parse and keep the numeric `article_id`. The content mutation needs it.
156
+
157
+ Example Playwriter check:
158
+
159
+ ```bash
160
+ playwriter session new
161
+ playwriter -s 1 -e '
162
+ state.page = context.pages().find((p) => {
163
+ return p.url().includes("/compose/articles/edit/")
164
+ })
165
+ if (!state.page) {
166
+ throw new Error("No article editor page found")
167
+ }
168
+ console.log(state.page.url())
169
+ '
170
+ ```
171
+
172
+ ### 2. Explore with small manual edits first
173
+
174
+ Use the UI to learn how the editor reacts before doing bulk updates. Good
175
+ exploration tasks:
176
+
177
+ - add one paragraph
178
+ - convert one block to `Sottotitolo`
179
+ - insert one code block
180
+ - bold one word in one paragraph
181
+
182
+ After each change, inspect the rendered HTML with `getCleanHTML()`.
183
+
184
+ Example validation command:
185
+
186
+ ```bash
187
+ playwriter -s 1 -e '
188
+ state.page = context.pages().find((p) => {
189
+ return p.url().includes("/compose/articles/edit/")
190
+ })
191
+ console.log(
192
+ await getCleanHTML({
193
+ locator: state.page.locator("[data-testid=\"composer\"]"),
194
+ showDiffSinceLastCall: false,
195
+ }),
196
+ )
197
+ '
198
+ ```
199
+
200
+ ### 3. Capture real network traffic
201
+
202
+ Watch GraphQL requests while making one tiny manual change. This gives you the
203
+ exact mutation names and payload shapes used by the current x.com (Twitter)
204
+ editor.
205
+
206
+ The two important mutations found in this session were:
207
+
208
+ - `ArticleEntityUpdateTitle`
209
+ - `ArticleEntityUpdateContent`
210
+
211
+ The content mutation URL looked like:
212
+
213
+ ```text
214
+ https://x.com/i/api/graphql/<queryId>/ArticleEntityUpdateContent
215
+ ```
216
+
217
+ The exact `queryId` can change over time. Do not hardcode it blindly without
218
+ first confirming it from a real request in the current session.
219
+
220
+ Example request logger:
221
+
222
+ ```bash
223
+ playwriter -s 1 -e '
224
+ state.page = context.pages().find((p) => {
225
+ return p.url().includes("/compose/articles/edit/")
226
+ })
227
+ state.requests = []
228
+ state.page.removeAllListeners("request")
229
+ state.page.on("request", (req) => {
230
+ if (req.url().includes("ArticleEntity") || req.url().includes("graphql")) {
231
+ state.requests.push({
232
+ url: req.url(),
233
+ method: req.method(),
234
+ postData: req.postData(),
235
+ })
236
+ }
237
+ })
238
+ console.log(
239
+ "Ready: now make one tiny manual edit in the page, then rerun this command to inspect state.requests",
240
+ )
241
+ '
242
+ ```
243
+
244
+ ### 4. Use direct content updates for bulk work
245
+
246
+ Once you know the current mutation shape, generate the full `content_state`
247
+ locally and send the content update directly.
248
+
249
+ This is the reliable path for:
250
+
251
+ - full markdown import
252
+ - replacing large sections
253
+ - converting paragraphs to ordered lists
254
+ - adding one bold keyword per paragraph
255
+ - fixing code block languages
256
+
257
+ Concrete pattern:
258
+
259
+ 1. build `content_state` in a local JSON file
260
+ 2. read `ct0` from `document.cookie`
261
+ 3. send `ArticleEntityUpdateContent` with the same `queryId` and feature flags
262
+ 4. reload the page
263
+
264
+ ### 5. Reload and validate
265
+
266
+ After every direct mutation:
267
+
268
+ 1. reload the article editor page
269
+ 2. inspect `getCleanHTML()`
270
+ 3. search for expected headings, list items, bold splits, and code labels
271
+
272
+ Do not trust the visual editor alone.
273
+
274
+ Example reload + search:
275
+
276
+ ```bash
277
+ playwriter -s 1 -e '
278
+ state.page = context.pages().find((p) => {
279
+ return p.url().includes("/compose/articles/edit/")
280
+ })
281
+ await state.page.reload({ waitUntil: "domcontentloaded" })
282
+ await waitForPageLoad({ page: state.page, timeout: 8000 })
283
+ console.log(
284
+ await getCleanHTML({
285
+ locator: state.page.locator("[data-testid=\"composer\"]"),
286
+ search: /debugging with event streams|typescript|ordered-list-item/i,
287
+ showDiffSinceLastCall: false,
288
+ }),
289
+ )
290
+ '
291
+ ```
292
+
293
+ ## Block type cheatsheet
294
+
295
+ ### Paragraphs
296
+
297
+ Use:
298
+
299
+ ```json
300
+ {
301
+ "type": "unstyled",
302
+ "text": "your paragraph text"
303
+ }
304
+ ```
305
+
306
+ ### Subheadings
307
+
308
+ Use:
309
+
310
+ ```json
311
+ {
312
+ "type": "header-two",
313
+ "text": "debugging with event streams"
314
+ }
315
+ ```
316
+
317
+ ### Numbered lists
318
+
319
+ Each item is its own block:
320
+
321
+ ```json
322
+ {
323
+ "type": "ordered-list-item",
324
+ "text": "doubles your bug surface"
325
+ }
326
+ ```
327
+
328
+ ### Code blocks
329
+
330
+ Code blocks are not plain text blocks. They are:
331
+
332
+ 1. one `atomic` block in `blocks`
333
+ 2. one `MARKDOWN` entity in `entity_map`
334
+
335
+ The atomic block points to the entity with `entity_ranges`.
336
+
337
+ The entity markdown should include the full fence, for example:
338
+
339
+ ````text
340
+ ```typescript
341
+ const x = 1
342
+ ```
343
+ ````
344
+
345
+ If you want the visible language label to say `typescript`, the stored fence
346
+ must be ` ```typescript `, not ` ```ts `.
347
+
348
+ ## Inline styles
349
+
350
+ Bold text is represented with `inlineStyleRanges` inside a block.
351
+
352
+ Important session learning:
353
+
354
+ - the style name is `Bold`
355
+ - not `BOLD`
356
+
357
+ Example:
358
+
359
+ ```json
360
+ {
361
+ "text": "your clanker loves state",
362
+ "inlineStyleRanges": [
363
+ { "offset": 19, "length": 5, "style": "Bold" }
364
+ ]
365
+ }
366
+ ```
367
+
368
+ Always calculate offsets against the raw block text exactly as stored.
369
+
370
+ ## Known UI pitfalls
371
+
372
+ The manual editor flow has several traps:
373
+
374
+ ### Heading inheritance
375
+
376
+ After creating a heading, pressing `Enter` once can keep the next block in the
377
+ same heading style. To reset to a paragraph, press `Enter` again.
378
+
379
+ ### Post-code-block cursor placement
380
+
381
+ Typing after a code block is unreliable. The editor can:
382
+
383
+ - append text to the wrong block
384
+ - split text unexpectedly
385
+ - create stray headings
386
+ - leave part of a sentence in one block and the rest in another
387
+
388
+ For anything more than a tiny manual tweak, use direct content updates instead.
389
+
390
+ ### Visual feedback is incomplete
391
+
392
+ The editor can look correct while the underlying block structure is wrong.
393
+ Always inspect the HTML or mutation payload.
394
+
395
+ ### Playwriter sessions can reset
396
+
397
+ If the relay server restarts or the extension reconnects, Playwriter sessions
398
+ can disappear. If that happens, create a new Playwriter session and reattach to
399
+ the already-open article page.
400
+
401
+ Recovery command:
402
+
403
+ ```bash
404
+ playwriter session new
405
+ playwriter -s 1 -e '
406
+ state.page = context.pages().find((p) => {
407
+ return p.url().includes("/compose/articles/edit/")
408
+ })
409
+ if (!state.page) {
410
+ throw new Error("No article editor page found")
411
+ }
412
+ console.log(state.page.url())
413
+ '
414
+ ```
415
+
416
+ ## Auth and request details
417
+
418
+ Direct content updates need proper auth headers. In this session, the direct
419
+ `fetch()` worked only after including:
420
+
421
+ - the X bearer token
422
+ - `x-csrf-token` from the `ct0` cookie
423
+ - the standard X active-user/auth/client-language headers
424
+
425
+ If you get `403`, inspect the successful browser request and match its headers.
426
+
427
+ In this session, the direct fetch succeeded only after matching:
428
+
429
+ - bearer token
430
+ - `x-csrf-token`
431
+ - `x-twitter-active-user`
432
+ - `x-twitter-auth-type`
433
+ - `x-twitter-client-language`
434
+
435
+ ## Validation checklist
436
+
437
+ After updating an article, verify all of these:
438
+
439
+ 1. correct title in the title field
440
+ 2. headings appear as `header-two`
441
+ 3. ordered lists appear as `ordered-list-item`
442
+ 4. code blocks render as `markdown-code-block`
443
+ 5. code block language labels say what you expect, for example `typescript`
444
+ 6. bold keywords are split into separate styled spans in the HTML
445
+ 7. no stray empty headings or broken split paragraphs remain
446
+
447
+ ## Useful recipes
448
+
449
+ ### Import a markdown article
450
+
451
+ 1. parse the markdown locally
452
+ 2. map paragraphs to `unstyled`
453
+ 3. map `##` headings to `header-two`
454
+ 4. map numbered list items to `ordered-list-item`
455
+ 5. map fenced code blocks to `atomic` + `MARKDOWN` entities
456
+ 6. send `ArticleEntityUpdateContent`
457
+ 7. reload and validate
458
+
459
+ The fastest implementation is usually:
460
+
461
+ 1. generate `./tmp/x-article-content-state.json`
462
+ 2. read it from a Playwriter command with `fs.readFileSync`
463
+ 3. push it with the direct content mutation
464
+
465
+ ### Bold one keyword per paragraph
466
+
467
+ 1. choose one keyword per paragraph
468
+ 2. compute exact `offset` and `length`
469
+ 3. add `inlineStyleRanges` with style `Bold`
470
+ 4. push the updated `content_state`
471
+ 5. reload and verify the HTML splits around the bold span
472
+
473
+ ### Fix code language labels
474
+
475
+ Update the markdown entity fences. Example:
476
+
477
+ - bad: ` ```ts `
478
+ - good: ` ```typescript `
479
+
480
+ Then resend the full `content_state` and reload the editor.
481
+
482
+ ## Minimal bulk update example
483
+
484
+ Use this pattern when you already have the right `queryId` and payload shape:
485
+
486
+ ```bash
487
+ playwriter -s 1 -e '
488
+ const fs = require("node:fs")
489
+ state.page = context.pages().find((p) => {
490
+ return p.url().includes("/compose/articles/edit/")
491
+ })
492
+ const articleId = state.page.url().match(/edit\/(\d+)/)?.[1]
493
+ const contentState = JSON.parse(
494
+ fs.readFileSync("./tmp/x-article-content-state.json", "utf8"),
495
+ )
496
+ const csrfToken = await state.page.evaluate(() => {
497
+ return document.cookie
498
+ .split("; ")
499
+ .find((x) => x.startsWith("ct0="))
500
+ ?.slice(4) || ""
501
+ })
502
+ const payload = {
503
+ variables: {
504
+ content_state: contentState,
505
+ article_entity: articleId,
506
+ },
507
+ features: {
508
+ profile_label_improvements_pcf_label_in_post_enabled: true,
509
+ responsive_web_profile_redirect_enabled: false,
510
+ rweb_tipjar_consumption_enabled: false,
511
+ verified_phone_label_enabled: false,
512
+ responsive_web_graphql_skip_user_profile_image_extensions_enabled: false,
513
+ responsive_web_graphql_timeline_navigation_enabled: true,
514
+ },
515
+ queryId: "<capture-from-real-request>",
516
+ }
517
+ const response = await state.page.evaluate(async ({ payload, csrfToken }) => {
518
+ const res = await fetch(
519
+ `https://x.com/i/api/graphql/${payload.queryId}/ArticleEntityUpdateContent`,
520
+ {
521
+ method: "POST",
522
+ credentials: "include",
523
+ headers: {
524
+ authorization: "<capture-from-real-request>",
525
+ "content-type": "application/json",
526
+ "x-csrf-token": csrfToken,
527
+ "x-twitter-active-user": "yes",
528
+ "x-twitter-auth-type": "OAuth2Session",
529
+ "x-twitter-client-language": "it",
530
+ },
531
+ body: JSON.stringify(payload),
532
+ },
533
+ )
534
+ return { status: res.status, text: await res.text() }
535
+ }, { payload, csrfToken })
536
+ console.log(response.status)
537
+ console.log(response.text.slice(0, 1000))
538
+ '
539
+ ```
540
+
541
+ Replace the bearer token and `queryId` with values captured from a successful
542
+ browser request in the current session.
543
+
544
+ ## Default strategy
545
+
546
+ Use this default unless the task is tiny:
547
+
548
+ 1. inspect the current draft in the browser
549
+ 2. capture one real content mutation from X
550
+ 3. generate the final `content_state` locally
551
+ 4. update the draft with the same mutation shape
552
+ 5. validate the result in the live editor HTML
553
+
554
+ That is the fastest path and the most likely to work in one shot.
@@ -11,7 +11,7 @@
11
11
  // Poll timeouts: 4s max, 100ms interval.
12
12
 
13
13
  import fs from 'node:fs'
14
- import net from 'node:net'
14
+
15
15
  import path from 'node:path'
16
16
  import url from 'node:url'
17
17
  import {
@@ -44,6 +44,7 @@ import { getPrisma } from './db.js'
44
44
  import { startHranaServer, stopHranaServer } from './hrana-server.js'
45
45
  import { initializeOpencodeForDirectory, stopOpencodeServer } from './opencode.js'
46
46
  import {
47
+ chooseLockPort,
47
48
  cleanupTestSessions,
48
49
  waitForBotMessageContaining,
49
50
  waitForFooterMessage,
@@ -68,23 +69,7 @@ function createRunDirectories() {
68
69
  return { root, dataDir, projectDirectory }
69
70
  }
70
71
 
71
- function chooseLockPort(): Promise<number> {
72
- return new Promise((resolve, reject) => {
73
- const server = net.createServer()
74
- server.listen(0, () => {
75
- const address = server.address()
76
- if (!address || typeof address === 'string') {
77
- server.close()
78
- reject(new Error('Failed to resolve lock port'))
79
- return
80
- }
81
- const port = address.port
82
- server.close(() => {
83
- resolve(port)
84
- })
85
- })
86
- })
87
- }
72
+
88
73
 
89
74
  function createDiscordJsClient({ restUrl }: { restUrl: string }) {
90
75
  return new Client({
@@ -200,7 +185,7 @@ describe('agent model resolution', () => {
200
185
  beforeAll(async () => {
201
186
  testStartTime = Date.now()
202
187
  directories = createRunDirectories()
203
- const lockPort = await chooseLockPort()
188
+ const lockPort = chooseLockPort({ key: TEXT_CHANNEL_ID })
204
189
 
205
190
  process.env['KIMAKI_LOCK_PORT'] = String(lockPort)
206
191
  setDataDir(directories.dataDir)