claude-code-extensions 0.1.0 → 0.1.2

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 (115) hide show
  1. package/dist/ast.d.ts +43 -0
  2. package/dist/ast.js +308 -0
  3. package/dist/ast.js.map +1 -0
  4. package/dist/cli-list.d.ts +5 -0
  5. package/dist/cli-list.js +33 -0
  6. package/dist/cli-list.js.map +1 -0
  7. package/dist/cli-reload.d.ts +7 -0
  8. package/dist/cli-reload.js +24 -0
  9. package/dist/cli-reload.js.map +1 -0
  10. package/dist/cli-setup.d.ts +14 -0
  11. package/dist/cli-setup.js +110 -0
  12. package/dist/cli-setup.js.map +1 -0
  13. package/dist/cli.d.ts +14 -0
  14. package/dist/cli.js +183 -0
  15. package/dist/cli.js.map +1 -0
  16. package/dist/patch-worker.d.ts +6 -0
  17. package/dist/patch-worker.js +27 -0
  18. package/dist/patch-worker.js.map +1 -0
  19. package/dist/patches/always-show-context.d.ts +23 -0
  20. package/dist/patches/always-show-context.js +97 -0
  21. package/dist/patches/always-show-context.js.map +1 -0
  22. package/dist/patches/always-show-thinking.d.ts +18 -0
  23. package/dist/patches/always-show-thinking.js +55 -0
  24. package/dist/patches/always-show-thinking.js.map +1 -0
  25. package/dist/patches/banner.d.ts +10 -0
  26. package/dist/patches/banner.js +105 -0
  27. package/dist/patches/banner.js.map +1 -0
  28. package/dist/patches/cd-command.d.ts +16 -0
  29. package/dist/patches/cd-command.js +89 -0
  30. package/dist/patches/cd-command.js.map +1 -0
  31. package/dist/patches/cx-badge.d.ts +10 -0
  32. package/dist/patches/cx-badge.js +115 -0
  33. package/dist/patches/cx-badge.js.map +1 -0
  34. package/dist/patches/cx-resume-commands.d.ts +14 -0
  35. package/dist/patches/cx-resume-commands.js +53 -0
  36. package/dist/patches/cx-resume-commands.js.map +1 -0
  37. package/dist/patches/disable-paste-collapse.d.ts +16 -0
  38. package/dist/patches/disable-paste-collapse.js +49 -0
  39. package/dist/patches/disable-paste-collapse.js.map +1 -0
  40. package/dist/patches/disable-telemetry.d.ts +13 -0
  41. package/dist/patches/disable-telemetry.js +76 -0
  42. package/dist/patches/disable-telemetry.js.map +1 -0
  43. package/{patches/index.js → dist/patches/index.d.ts} +2 -0
  44. package/dist/patches/index.js +20 -0
  45. package/dist/patches/index.js.map +1 -0
  46. package/dist/patches/no-attribution.d.ts +15 -0
  47. package/dist/patches/no-attribution.js +42 -0
  48. package/dist/patches/no-attribution.js.map +1 -0
  49. package/dist/patches/no-feedback.d.ts +12 -0
  50. package/dist/patches/no-feedback.js +31 -0
  51. package/dist/patches/no-feedback.js.map +1 -0
  52. package/dist/patches/no-npm-warning.d.ts +9 -0
  53. package/dist/patches/no-npm-warning.js +31 -0
  54. package/dist/patches/no-npm-warning.js.map +1 -0
  55. package/dist/patches/no-tips.d.ts +10 -0
  56. package/dist/patches/no-tips.js +26 -0
  57. package/dist/patches/no-tips.js.map +1 -0
  58. package/dist/patches/persist-max-effort.d.ts +15 -0
  59. package/dist/patches/persist-max-effort.js +75 -0
  60. package/dist/patches/persist-max-effort.js.map +1 -0
  61. package/dist/patches/queue.d.ts +10 -0
  62. package/dist/patches/queue.js +202 -0
  63. package/dist/patches/queue.js.map +1 -0
  64. package/dist/patches/random-clawd.d.ts +9 -0
  65. package/dist/patches/random-clawd.js +49 -0
  66. package/dist/patches/random-clawd.js.map +1 -0
  67. package/dist/patches/reload.d.ts +10 -0
  68. package/dist/patches/reload.js +50 -0
  69. package/dist/patches/reload.js.map +1 -0
  70. package/dist/patches/show-file-in-collapsed-read.d.ts +17 -0
  71. package/dist/patches/show-file-in-collapsed-read.js +151 -0
  72. package/dist/patches/show-file-in-collapsed-read.js.map +1 -0
  73. package/dist/patches/simple-spinner.d.ts +12 -0
  74. package/dist/patches/simple-spinner.js +31 -0
  75. package/dist/patches/simple-spinner.js.map +1 -0
  76. package/dist/patches/swap-enter-submit.d.ts +26 -0
  77. package/dist/patches/swap-enter-submit.js +155 -0
  78. package/dist/patches/swap-enter-submit.js.map +1 -0
  79. package/dist/setup.d.ts +11 -0
  80. package/dist/setup.js +268 -0
  81. package/dist/setup.js.map +1 -0
  82. package/dist/transform-worker.d.ts +10 -0
  83. package/dist/transform-worker.js +35 -0
  84. package/dist/transform-worker.js.map +1 -0
  85. package/dist/transform.d.ts +12 -0
  86. package/dist/transform.js +83 -0
  87. package/dist/transform.js.map +1 -0
  88. package/dist/types.d.ts +105 -0
  89. package/dist/types.js +8 -0
  90. package/dist/types.js.map +1 -0
  91. package/package.json +19 -11
  92. package/ast.js +0 -276
  93. package/cx +0 -228
  94. package/cx-setup +0 -101
  95. package/patch-worker.js +0 -31
  96. package/patches/always-show-context.js +0 -123
  97. package/patches/always-show-thinking.js +0 -65
  98. package/patches/banner.js +0 -58
  99. package/patches/cd-command.js +0 -104
  100. package/patches/cx-badge.js +0 -112
  101. package/patches/cx-resume-commands.js +0 -58
  102. package/patches/disable-paste-collapse.js +0 -52
  103. package/patches/disable-telemetry.js +0 -84
  104. package/patches/no-attribution.js +0 -55
  105. package/patches/no-npm-warning.js +0 -32
  106. package/patches/no-tips.js +0 -29
  107. package/patches/persist-max-effort.js +0 -70
  108. package/patches/queue.js +0 -215
  109. package/patches/random-clawd.js +0 -52
  110. package/patches/reload.js +0 -68
  111. package/patches/show-file-in-collapsed-read.js +0 -178
  112. package/patches/swap-enter-submit.js +0 -188
  113. package/setup.js +0 -222
  114. package/transform-worker.js +0 -38
  115. package/transform.js +0 -99
@@ -1,178 +0,0 @@
1
- /**
2
- * Show File Paths in Collapsed Read/Search Display
3
- *
4
- * Instead of just "Read 3 files", shows the actual file paths:
5
- * Read 3 files (src/foo.ts, src/bar.ts, src/baz.ts)
6
- * Instead of just "Searched for 1 pattern", shows:
7
- * Searched for 1 pattern ("handleSubmit")
8
- *
9
- * Addresses: https://github.com/anthropics/claude-code/issues/21151 (184 👍)
10
- *
11
- * The data is already there — readFilePaths and searchArgs are extracted
12
- * from the message but only shown during active execution as a hint.
13
- * This patch adds them to the completed collapsed display.
14
- */
15
-
16
- export default {
17
- id: 'show-file-in-collapsed-read',
18
- name: 'Show File in Collapsed Read',
19
- description: 'Show file paths and search patterns in collapsed tool display',
20
-
21
- apply(ctx) {
22
- const { ast, editor, find, index, assert, src, query } = ctx;
23
- const { findFirst, findAll } = find;
24
-
25
- // ─── Step 1: Find the collapsed display rendering function ───
26
- // Identified by containing key:"read", key:"search", and key:"comma-r" literals.
27
- // Use the indexed findFunctionsContainingStrings for O(matches) lookup.
28
- const renderFns = query.findFunctionsContainingStrings(ast, 'comma-r', 'read', 'search');
29
- const renderFn = renderFns[0];
30
- assert(renderFn, 'Could not find collapsed display render function (markers: key:"read", key:"search", key:"comma-r")');
31
-
32
- // ─── Step 2: Discover variable names ───
33
- // Find the readFilePaths variable: pattern is X=q.readFilePaths
34
- // Find the searchArgs variable: pattern is X=q.searchArgs
35
- // Find the getDisplayPath function: pattern is X(Y):M where it's used near readFilePaths
36
-
37
- // Find readFilePaths property access
38
- const readFilePathsAccess = findFirst(renderFn, n =>
39
- n.type === 'MemberExpression'
40
- && n.property.type === 'Identifier'
41
- && n.property.name === 'readFilePaths'
42
- );
43
- assert(readFilePathsAccess, 'Could not find q.readFilePaths access');
44
-
45
- // The assignment: Q = q.readFilePaths — Q is the variable we need
46
- const readPathsAssignment = findFirst(renderFn, n =>
47
- n.type === 'VariableDeclarator'
48
- && n.init === readFilePathsAccess
49
- );
50
- assert(readPathsAssignment, 'Could not find readFilePaths variable assignment');
51
- const readPathsVar = readPathsAssignment.id.name;
52
-
53
- // Find searchArgs variable similarly
54
- const searchArgsAccess = findFirst(renderFn, n =>
55
- n.type === 'MemberExpression'
56
- && n.property.type === 'Identifier'
57
- && n.property.name === 'searchArgs'
58
- );
59
- assert(searchArgsAccess, 'Could not find q.searchArgs access');
60
- const searchArgsAssignment = findFirst(renderFn, n =>
61
- n.type === 'VariableDeclarator'
62
- && n.init === searchArgsAccess
63
- );
64
- assert(searchArgsAssignment, 'Could not find searchArgs variable assignment');
65
- const searchArgsVar = searchArgsAssignment.id.name;
66
-
67
- // Find getDisplayPath function name by looking for its call pattern:
68
- // It's called like: F5(X6) right after readFilePaths is accessed,
69
- // in the pattern: X!==void 0?F5(X):M
70
- // The call is on a variable that came from Q?.at(-1)
71
- const getDisplayPathCall = findFirst(renderFn, n => {
72
- if (n.type !== 'ConditionalExpression') return false;
73
- // Look for: X!==void 0 ? CALL(X) : Y
74
- // where CALL is a single-argument function call
75
- if (n.consequent.type !== 'CallExpression') return false;
76
- if (n.consequent.arguments.length !== 1) return false;
77
- // The callee should be an Identifier (the getDisplayPath function)
78
- if (n.consequent.callee.type !== 'Identifier') return false;
79
- // This should appear after readFilePaths is used
80
- return n.start > readFilePathsAccess.start;
81
- });
82
- assert(getDisplayPathCall, 'Could not find getDisplayPath call pattern');
83
- const displayPathFn = getDisplayPathCall.consequent.callee.name;
84
-
85
- // ─── Step 3: Find the React library reference ───
86
- // Look for createElement calls in the function — C4.default.createElement(...)
87
- // Find the pattern: X.default.createElement(Y, {key:"read"}, ...)
88
- const readElement = findFirst(renderFn, n => {
89
- if (n.type !== 'CallExpression') return false;
90
- // Check for: X.default.createElement
91
- const callee = n.callee;
92
- if (callee.type !== 'MemberExpression') return false;
93
- if (callee.property.name !== 'createElement') return false;
94
- // Check args for key:"read"
95
- return n.arguments.some(arg =>
96
- arg.type === 'ObjectExpression'
97
- && arg.properties?.some(p =>
98
- p.key?.name === 'key' && p.value?.value === 'read'
99
- )
100
- );
101
- });
102
- assert(readElement, 'Could not find createElement with key:"read"');
103
-
104
- // Extract the React reference (e.g., C4) from C4.default.createElement
105
- const reactRef = src(readElement.callee.object.object);
106
-
107
- // ─── Step 4: Find the Text component reference ───
108
- // The readElement is: createElement(T, {key:"read"}, M6, " ", createElement(T, {bold:!0}, b), ...)
109
- // The first argument (index 0) is the Text component reference.
110
- const textComponent = src(readElement.arguments[0]);
111
-
112
- // ─── Step 5: Find the "Searched for" element and inject search pattern ───
113
- // Pattern: z6.push(createElement(T, {key:"search"}, M6, " ", createElement(T, {bold:true}, I), " ", I===1?"pattern":"patterns"))
114
- // We want to add the search pattern text after "patterns")
115
- const searchElement = findFirst(renderFn, n => {
116
- if (n.type !== 'CallExpression') return false;
117
- if (n.callee.type !== 'MemberExpression') return false;
118
- if (n.callee.property.name !== 'createElement') return false;
119
- return n.arguments.some(arg =>
120
- arg.type === 'ObjectExpression'
121
- && arg.properties?.some(p =>
122
- p.key?.name === 'key' && p.value?.value === 'search'
123
- )
124
- );
125
- });
126
- assert(searchElement, 'Could not find createElement with key:"search"');
127
-
128
- // Find the push() call that contains this search element
129
- const searchPush = findFirst(renderFn, n =>
130
- n.type === 'CallExpression'
131
- && n.callee.type === 'MemberExpression'
132
- && n.callee.property.name === 'push'
133
- && n.arguments.length === 1
134
- && n.arguments[0] === searchElement
135
- );
136
- assert(searchPush, 'Could not find push() call for search element');
137
-
138
- // After the search push, inject a conditional that shows the search patterns
139
- // Show: (pattern1, pattern2, ...)
140
- const searchPathCode = `;if(${searchArgsVar}&&${searchArgsVar}.length>0){` +
141
- `z6.push(${reactRef}.default.createElement(${textComponent},{key:"search-args",dimColor:!0},` +
142
- `" (",${searchArgsVar}.map(function(p){return\'"\\'\\'"+p+\'"\\'\\'\'}).join(", "),")"))` +
143
- `}`;
144
-
145
- // Wait — the array variable name might not be z6. Let's find it.
146
- // The push() callee object is the array variable.
147
- const elemArrayVar = src(searchPush.callee.object);
148
-
149
- const searchPathCodeFinal = `;if(${searchArgsVar}&&${searchArgsVar}.length>0){` +
150
- `${elemArrayVar}.push(${reactRef}.default.createElement(${textComponent},{key:"search-args",dimColor:!0},` +
151
- `" (",${searchArgsVar}.map(function(p){return '"'+p+'"'}).join(", "),")"))` +
152
- `}`;
153
-
154
- // Find the enclosing if-block for the search element by walking up the parent chain
155
- const searchIfBlock = index.ancestor(searchElement, 'IfStatement');
156
- assert(searchIfBlock, 'Could not find if block containing search element');
157
-
158
- editor.insertAt(searchIfBlock.end, searchPathCodeFinal);
159
-
160
- // ─── Step 6: Find the "Read" element and inject file paths ───
161
- // After the if(b>0){...} block, inject file path display
162
- const readIfBlock = index.ancestor(readElement, 'IfStatement');
163
- assert(readIfBlock, 'Could not find if block containing read element');
164
-
165
- // Inject after the read if-block:
166
- // Show file paths: " (src/foo.ts, src/bar.ts)" for up to 3 files,
167
- // or " (src/foo.ts… +2 more)" for >3 files
168
- const readPathCode = `;if(${readPathsVar}&&${readPathsVar}.length>0){` +
169
- `var __paths=${readPathsVar}.length<=3?` +
170
- `${readPathsVar}.map(${displayPathFn}).join(", "):` +
171
- `${displayPathFn}(${readPathsVar}[${readPathsVar}.length-1])+"… +"+(${readPathsVar}.length-1)+" more";` +
172
- `${elemArrayVar}.push(${reactRef}.default.createElement(${textComponent},{key:"read-paths",dimColor:!0},` +
173
- `" (",__paths,")"))` +
174
- `}`;
175
-
176
- editor.insertAt(readIfBlock.end, readPathCode);
177
- },
178
- };
@@ -1,188 +0,0 @@
1
- /**
2
- * Swap Enter / Meta+Enter
3
- *
4
- * Makes Enter insert a newline and Meta+Enter (Option+Enter on macOS) submit.
5
- *
6
- * Addresses: https://github.com/anthropics/claude-code/issues/2054 (72 reactions)
7
- *
8
- * CJK users, SSH users, and anyone with Slack-style muscle memory constantly
9
- * submit half-written prompts by accident. This patch swaps the default
10
- * bindings so Enter is safe (newline) and Meta+Enter is deliberate (submit).
11
- *
12
- * Why keybinding changes alone aren't enough:
13
- *
14
- * The Enter key's submit behavior is hard-coded in useTextInput.ts's
15
- * handleEnter() function — it directly calls onSubmit() for plain Enter
16
- * and cursor.insert('\n') for Meta/Shift+Enter, bypassing the keybinding
17
- * system entirely.
18
- *
19
- * This patch modifies THREE layers:
20
- * 1. DEFAULT_BINDINGS — so shortcut hints and the help menu show correctly
21
- * 2. handleEnter() — so the actual key behavior is swapped
22
- * 3. Tip/help text — so instructions match the new behavior
23
- */
24
-
25
- export default {
26
- id: 'swap-enter-submit',
27
- name: 'Swap Enter / Meta+Enter',
28
- description: 'Enter inserts newline, Option/Alt+Enter submits',
29
- defaultEnabled: false,
30
-
31
- apply(ctx) {
32
- const { ast, editor, query, find, src, assert } = ctx;
33
- const { findObjectWithStringProps } = query;
34
- const { findFirst, findAll } = find;
35
-
36
- // ── Patch 1: DEFAULT_BINDINGS ────────────────────────────────────
37
-
38
- const obj = findObjectWithStringProps(ast, [
39
- ['enter', 'chat:submit'],
40
- ['up', 'history:previous'],
41
- ]);
42
- assert(obj, 'Could not find DEFAULT_BINDINGS object');
43
-
44
- const enterProp = obj.properties.find(p =>
45
- p.type === 'Property' &&
46
- ((p.key.type === 'Identifier' && p.key.name === 'enter') ||
47
- (p.key.type === 'Literal' && p.key.value === 'enter')));
48
- assert(enterProp, 'Could not find "enter" property in DEFAULT_BINDINGS');
49
-
50
- assert(
51
- enterProp.value.type === 'Literal' && enterProp.value.value === 'chat:submit',
52
- 'enter property value is not "chat:submit"',
53
- );
54
- editor.replaceRange(enterProp.value.start, enterProp.value.end, '"chat:newline"');
55
- editor.insertAt(enterProp.end, ',"meta+enter":"chat:submit"');
56
-
57
- // ── Patch 2: handleEnter() in useTextInput ───────────────────────
58
- //
59
- // Original handleEnter:
60
- // if (backslash) → backslash+newline (keep)
61
- // if (key.meta || key.shift) → cursor.insert('\n')
62
- // if (Apple_Terminal && shift) → cursor.insert('\n')
63
- // onSubmit?.(originalValue)
64
- //
65
- // After patch:
66
- // if (backslash) → backslash+newline (unchanged)
67
- // if (key.meta) → onSubmit (Meta/Option+Enter submits)
68
- // if (key.shift) → cursor.insert('\n') (Shift+Enter still inserts newline)
69
- // (Apple_Terminal block removed — not needed; Meta works via Option key,
70
- // and plain Enter newlines go through keybinding system)
71
- // return cursor (plain Enter = no-op; keybinding system handles
72
- // Enter → chat:newline → handleNewline in PromptInput)
73
-
74
- // Find handleEnter by stable markers. Take the SMALLEST matching
75
- // function (handleEnter is nested inside useTextInput).
76
- const isHandleEnterCandidate = node => {
77
- if (node.type !== 'FunctionDeclaration' && node.type !== 'FunctionExpression') return false;
78
- if (!findFirst(node, n => n.type === 'Literal' && n.value === 'Apple_Terminal')) return false;
79
- if (!findFirst(node, n =>
80
- n.type === 'CallExpression' && n.callee.type === 'MemberExpression' &&
81
- n.callee.property.name === 'backspace')) return false;
82
- return findFirst(node, n =>
83
- n.type === 'LogicalExpression' && n.operator === '||' &&
84
- n.left.type === 'MemberExpression' && n.left.property.name === 'meta' &&
85
- n.right.type === 'MemberExpression' && n.right.property.name === 'shift') !== null;
86
- };
87
- const candidates = findAll(ast, isHandleEnterCandidate);
88
- assert(candidates.length >= 1, 'Could not find handleEnter function');
89
- candidates.sort((a, b) => (a.end - a.start) - (b.end - b.start));
90
- const handleEnterFn = candidates[0];
91
-
92
- // Discover minified variable names
93
-
94
- // key variable: from key.meta || key.shift
95
- const metaOrShift = findFirst(handleEnterFn, n =>
96
- n.type === 'LogicalExpression' && n.operator === '||' &&
97
- n.left.type === 'MemberExpression' && n.left.property.name === 'meta' &&
98
- n.right.type === 'MemberExpression' && n.right.property.name === 'shift');
99
- const keyVar = src(metaOrShift.left.object);
100
-
101
- // if-statement that tests meta||shift
102
- const metaShiftIf = findFirst(handleEnterFn, n => {
103
- if (n.type !== 'IfStatement') return false;
104
- const t = n.test;
105
- return t.type === 'LogicalExpression' && t.operator === '||' &&
106
- t.left.type === 'MemberExpression' && t.left.property.name === 'meta' &&
107
- t.right.type === 'MemberExpression' && t.right.property.name === 'shift';
108
- });
109
- assert(metaShiftIf, 'Could not find if-statement for meta||shift');
110
-
111
- // cursor variable: from cursor.insert('\n') (where cursor is a plain Identifier)
112
- const isNewlineArg = (n) =>
113
- (n.type === 'Literal' && n.value === '\n') ||
114
- (n.type === 'TemplateLiteral' && n.expressions.length === 0 &&
115
- n.quasis.length === 1 && n.quasis[0].value.cooked === '\n');
116
- const cursorInserts = findAll(handleEnterFn, n =>
117
- n.type === 'CallExpression' &&
118
- n.callee.type === 'MemberExpression' &&
119
- n.callee.object.type === 'Identifier' &&
120
- n.callee.property.name === 'insert' &&
121
- n.arguments.length === 1 && isNewlineArg(n.arguments[0]));
122
- assert(cursorInserts.length >= 1, 'Could not find cursor.insert("\\n") in handleEnter');
123
- const cursorVar = cursorInserts[0].callee.object.name;
124
-
125
- // onSubmit?.(originalValue): last statement in handleEnter body
126
- const bodyStmts = handleEnterFn.body.body;
127
- const lastStmt = bodyStmts[bodyStmts.length - 1];
128
- assert(
129
- lastStmt.type === 'ExpressionStatement',
130
- 'Last statement of handleEnter is not an ExpressionStatement',
131
- );
132
- const onSubmitCallSrc = src(lastStmt.expression);
133
-
134
- // Apple Terminal if-block
135
- const appleTerminalIf = findFirst(handleEnterFn, n => {
136
- if (n.type !== 'IfStatement') return false;
137
- return findFirst(n.test, t => t.type === 'Literal' && t.value === 'Apple_Terminal') !== null;
138
- });
139
-
140
- // ── Apply edits (editor applies in reverse position order) ───────
141
-
142
- // 2d: Replace fallthrough onSubmit with return cursor (no-op).
143
- editor.replaceRange(lastStmt.start, lastStmt.end, `return ${cursorVar}`);
144
-
145
- // 2c: Remove Apple Terminal if-block — no longer needed.
146
- // Meta/Option works natively in Apple Terminal (sends ESC+CR when
147
- // "Use Option as Meta Key" is enabled via /terminal-setup).
148
- // Plain Enter newlines go through the keybinding system.
149
- if (appleTerminalIf) {
150
- editor.replaceRange(appleTerminalIf.start, appleTerminalIf.end, '');
151
- }
152
-
153
- // 2b: Replace meta||shift block. Now: Meta+Enter (Option+Enter) → submit,
154
- // Shift+Enter → newline (for CSI u terminals), plain Enter → no-op.
155
- // Meta+Enter is the only reliable modifier+Enter across all terminals
156
- // because it sends ESC+CR — a distinct sequence. Ctrl+Enter and
157
- // Shift+Enter send the same byte as plain Enter in most terminals.
158
- editor.replaceRange(metaShiftIf.start, metaShiftIf.end,
159
- `if(${keyVar}.meta){${onSubmitCallSrc};return}` +
160
- `if(${keyVar}.shift)return ${cursorVar}.insert("\\n");`);
161
-
162
- // ── Patch 3: Tip text ────────────────────────────────────────────
163
-
164
- const shiftEnterTip = findFirst(ast, n =>
165
- n.type === 'Literal' && n.value === 'Press Shift+Enter to send a multi-line message');
166
- if (shiftEnterTip) {
167
- editor.replaceRange(shiftEnterTip.start, shiftEnterTip.end,
168
- '"Press Option+Enter to submit your message"');
169
- }
170
-
171
- const optionEnterTip = findFirst(ast, n =>
172
- n.type === 'Literal' && n.value === 'Press Option+Enter to send a multi-line message');
173
- if (optionEnterTip) {
174
- editor.replaceRange(optionEnterTip.start, optionEnterTip.end,
175
- '"Press Option+Enter to submit your message"');
176
- }
177
-
178
- // ── Patch 4: Help menu newline instructions ──────────────────────
179
-
180
- for (const val of ['shift + ⏎ for newline', '\\⏎ for newline',
181
- 'backslash (\\) + return (⏎) for newline']) {
182
- const nodes = findAll(ast, n => n.type === 'Literal' && n.value === val);
183
- for (const node of nodes) {
184
- editor.replaceRange(node.start, node.end, '"option + ⏎ to send"');
185
- }
186
- }
187
- },
188
- };
package/setup.js DELETED
@@ -1,222 +0,0 @@
1
- /**
2
- * Interactive patch configurator.
3
- * Toggle patches on/off with a keyboard-driven TUI.
4
- *
5
- * Called by `cx setup` — not meant to be run directly.
6
- */
7
-
8
- import { readFileSync, writeFileSync, existsSync, rmSync } from 'fs';
9
- import { resolve, dirname } from 'path';
10
- import { fileURLToPath } from 'url';
11
- import { listPatches } from './transform.js';
12
-
13
- const __dirname = dirname(fileURLToPath(import.meta.url));
14
- const CONFIG_PATH = resolve(__dirname, '.cx-patches.json');
15
-
16
- // ── Config persistence ────────────────────────────────────────────────────
17
-
18
- function loadConfig() {
19
- if (!existsSync(CONFIG_PATH)) return {};
20
- try { return JSON.parse(readFileSync(CONFIG_PATH, 'utf-8')); } catch { return {}; }
21
- }
22
-
23
- function saveConfig(patches) {
24
- writeFileSync(CONFIG_PATH, JSON.stringify({ patches }, null, 2) + '\n');
25
- }
26
-
27
- // ── Themed groups ────────────────────────────────────────────────────────
28
-
29
- const groups = [
30
- { label: 'Display', ids: [
31
- 'always-show-thinking', 'disable-paste-collapse',
32
- 'show-file-in-collapsed-read', 'cx-badge',
33
- 'cx-resume-commands', 'random-clawd',
34
- ]},
35
- { label: 'Input', ids: [
36
- 'queue', 'swap-enter-submit', 'reload',
37
- ]},
38
- { label: 'Behavior', ids: [
39
- 'persist-max-effort', 'no-npm-warning',
40
- ]},
41
- ];
42
-
43
- // ── State ─────────────────────────────────────────────────────────────────
44
-
45
- const patchMap = Object.fromEntries(listPatches().map(p => [p.id, p]));
46
-
47
- // Patches that are always on and should not appear in the setup TUI
48
- const hidden = new Set(['banner']);
49
-
50
- // Build ordered list from groups, append any ungrouped patches at the end
51
- const groupedIds = new Set(groups.flatMap(g => g.ids));
52
- const ungrouped = listPatches().filter(p => !groupedIds.has(p.id) && !hidden.has(p.id));
53
- if (ungrouped.length) groups.push({ label: 'Other', ids: ungrouped.map(p => p.id) });
54
-
55
- const allPatches = groups.flatMap(g => g.ids.map(id => patchMap[id]).filter(Boolean));
56
- // sectionStarts[i] = label if patch i starts a new section
57
- const sectionStarts = {};
58
- let idx = 0;
59
- for (const g of groups) {
60
- const valid = g.ids.filter(id => patchMap[id]);
61
- if (valid.length) { sectionStarts[idx] = g.label; idx += valid.length; }
62
- }
63
-
64
- const config = loadConfig();
65
- const states = allPatches.map(p =>
66
- config.patches?.[p.id] !== undefined ? config.patches[p.id] : (p.defaultEnabled !== false)
67
- );
68
- let cursor = 0;
69
- let dirty = false;
70
-
71
- // ── Rendering ─────────────────────────────────────────────────────────────
72
-
73
- const ESC = '\x1b';
74
- const CLEAR = `${ESC}[2J${ESC}[H`;
75
- const HIDE_CURSOR = `${ESC}[?25l`;
76
- const SHOW_CURSOR = `${ESC}[?25h`;
77
- const BOLD = `${ESC}[1m`;
78
- const DIM = `${ESC}[2m`;
79
- const RESET = `${ESC}[0m`;
80
- const GREEN = `${ESC}[32m`;
81
- const YELLOW = `${ESC}[33m`;
82
- const CYAN = `${ESC}[36m`;
83
- const WHITE = `${ESC}[37m`;
84
- const BG_HIGHLIGHT = `${ESC}[48;5;236m`;
85
-
86
- const maxId = Math.max(...allPatches.map(p => p.id.length));
87
-
88
- function render() {
89
- const rows = process.stdout.rows || 24;
90
- const lines = [];
91
- const patchLineIndex = [];
92
-
93
- // Header
94
- lines.push('');
95
- lines.push(` ${BOLD}${CYAN}cx setup${RESET} ${DIM}— toggle patches on/off${RESET}`);
96
-
97
- // Patch list with section headers
98
- for (let i = 0; i < allPatches.length; i++) {
99
- if (sectionStarts[i]) {
100
- lines.push('');
101
- lines.push(` ${DIM}${sectionStarts[i]}${RESET}`);
102
- }
103
-
104
- const p = allPatches[i];
105
- const on = states[i];
106
- const sel = i === cursor;
107
-
108
- const bg = sel ? BG_HIGHLIGHT : '';
109
- const pointer = sel ? `${bg}${WHITE}❯ ` : `${bg} `;
110
- const checkbox = on ? `${GREEN}✔${RESET}${bg}` : `${DIM}○${RESET}${bg}`;
111
- const name = sel ? `${BOLD}${WHITE}${p.id}${RESET}${bg}` : p.id;
112
- const pad = ' '.repeat(maxId - p.id.length + 2);
113
- const desc = `${DIM}${p.description}${RESET}`;
114
-
115
- patchLineIndex[i] = lines.length;
116
- lines.push(`${pointer}${checkbox} ${name}${pad}${desc}${RESET}`);
117
- }
118
-
119
- // Footer
120
- lines.push('');
121
- let footer = ` ${DIM}↑↓${RESET} navigate ${DIM}space${RESET} toggle ${DIM}enter${RESET} save ${DIM}esc${RESET} cancel`;
122
- if (dirty) {
123
- footer += ` ${YELLOW}● unsaved${RESET}`;
124
- }
125
- lines.push(footer);
126
-
127
- const prefix = CLEAR + HIDE_CURSOR;
128
-
129
- // Everything fits — render as-is
130
- if (lines.length <= rows) {
131
- process.stdout.write(prefix + lines.join('\n') + '\n');
132
- return;
133
- }
134
-
135
- // Scrolling — reserve 2 lines for indicators
136
- const usable = Math.max(1, rows - 2);
137
- const target = patchLineIndex[cursor];
138
- let scrollTop = Math.max(0, target - Math.floor(usable / 2));
139
- scrollTop = Math.min(scrollTop, lines.length - usable);
140
-
141
- const visible = lines.slice(scrollTop, scrollTop + usable);
142
- const top = scrollTop > 0 ? ` ${DIM}↑ more${RESET}` : '';
143
- const bottom = scrollTop + usable < lines.length ? ` ${DIM}↓ more${RESET}` : '';
144
-
145
- process.stdout.write(prefix + top + '\n' + visible.join('\n') + '\n' + bottom + '\n');
146
- }
147
-
148
- // ── Input handling ────────────────────────────────────────────────────────
149
-
150
- function cleanup() {
151
- process.stdout.write(SHOW_CURSOR + CLEAR);
152
- process.stdin.setRawMode(false);
153
- process.stdin.pause();
154
- }
155
-
156
- export default function setup() {
157
- if (!process.stdin.isTTY) {
158
- console.error('cx setup requires an interactive terminal.');
159
- process.exit(1);
160
- }
161
-
162
- process.stdin.setRawMode(true);
163
- process.stdin.resume();
164
- process.stdin.setEncoding('utf8');
165
-
166
- process.stdout.on('resize', render);
167
- render();
168
-
169
- process.stdin.on('data', (key) => {
170
- // Ctrl+C
171
- if (key === '\x03') {
172
- cleanup();
173
- process.exit(0);
174
- }
175
-
176
- // ESC
177
- if (key === '\x1b' || key === 'q') {
178
- cleanup();
179
- console.log(' Cancelled — no changes saved.\n');
180
- process.exit(0);
181
- }
182
-
183
- // Arrow up / k
184
- if (key === '\x1b[A' || key === 'k') {
185
- cursor = Math.max(0, cursor - 1);
186
- }
187
-
188
- // Arrow down / j
189
- if (key === '\x1b[B' || key === 'j') {
190
- cursor = Math.min(allPatches.length - 1, cursor + 1);
191
- }
192
-
193
- // Space — toggle
194
- if (key === ' ') {
195
- states[cursor] = !states[cursor];
196
- dirty = true;
197
- }
198
-
199
- // Enter — save and exit
200
- if (key === '\r' || key === '\n') {
201
- const patches = {};
202
- for (let i = 0; i < allPatches.length; i++) {
203
- patches[allPatches[i].id] = states[i];
204
- }
205
- saveConfig(patches);
206
- cleanup();
207
-
208
- // Delete cache so next run re-transforms
209
- try { rmSync(resolve(__dirname, '.cache'), { recursive: true, force: true }); } catch { /* ok */ }
210
-
211
- console.log(` ${GREEN}✔${RESET} Config saved to .cx-patches.json\n`);
212
- const enabled = allPatches.filter((_, i) => states[i]).map(p => p.id);
213
- const disabled = allPatches.filter((_, i) => !states[i]).map(p => p.id);
214
- if (enabled.length) console.log(` ${GREEN}enabled${RESET} ${enabled.join(', ')}`);
215
- if (disabled.length) console.log(` ${DIM}disabled${RESET} ${disabled.join(', ')}`);
216
- console.log(`\n Run ${BOLD}cx${RESET} to start with these patches.\n`);
217
- process.exit(0);
218
- }
219
-
220
- render();
221
- });
222
- }
@@ -1,38 +0,0 @@
1
- /**
2
- * Single worker that does all heavy work: parse, index, apply patches.
3
- * Sends progress messages so the main thread can update the UI.
4
- *
5
- * Receives: { source, patchIds, patchesDir }
6
- * Sends: { type: 'ready' } — parse + index done
7
- * { type: 'done', id } — one patch applied
8
- * { type: 'complete', patched } — final result
9
- */
10
-
11
- import { workerData, parentPort } from 'worker_threads';
12
- import * as acorn from 'acorn';
13
- import { ASTIndex, SourceEditor, buildContext } from './ast.js';
14
-
15
- const { source, patchIds, patchesDir } = workerData;
16
-
17
- try {
18
- const ast = acorn.parse(source, { ecmaVersion: 'latest', sourceType: 'module', allowHashBang: true });
19
- const index = new ASTIndex(ast);
20
- parentPort.postMessage({ type: 'ready' });
21
-
22
- const editor = new SourceEditor();
23
- const ctx = buildContext(source, index, editor);
24
-
25
- for (const id of patchIds) {
26
- const mod = await import(`${patchesDir}/${id}.js`);
27
- try {
28
- mod.default.apply(ctx);
29
- } catch (err) {
30
- throw new Error(`Patch "${id}" failed: ${err.message}`);
31
- }
32
- parentPort.postMessage({ type: 'done', id });
33
- }
34
-
35
- parentPort.postMessage({ type: 'complete', patched: editor.apply(source) });
36
- } catch (err) {
37
- parentPort.postMessage({ type: 'error', error: err.message });
38
- }