surshar / claude-code
Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.
Built by Anthropic · github.com/anthropics
| @@ -10,49 +10,37 @@ | ||
| 10 | 10 | |
| 11 | 11 | seat('builtin') |
| 12 | 12 | |
| 13 | -const SURVEY: CommandRunInput = { | |
| 14 | - command: 'survey', | |
| 15 | - args: '', | |
| 16 | - origin: { kind: 'composer' }, | |
| 17 | -} | |
| 18 | -const SHOWN: CommandRunInput = { | |
| 19 | - command: 'shown', | |
| 20 | - args: '', | |
| 21 | - origin: { kind: 'composer' }, | |
| 22 | -} | |
| 23 | 13 | const BEARER: SessionAuthorization = { handle: 'the-handle', kind: 'bearer' } |
| 24 | 14 | const ACCEPTED: HttpResponse = { status: 200, ok: true, headers: {}, text: '' } |
| 25 | 15 | |
| 26 | 16 | /** |
| 27 | - * A plugin that records through `$.telemetry`: `/survey` logs an answered | |
| 28 | - * survey, `/shown` a row under the built-in panel's own name; each answers | |
| 29 | - * "sent", or why the row was refused. | |
| 17 | + * `/record <event>`, which the recording plugin answers. | |
| 30 | 18 | */ |
| 19 | +const record = (event: string): CommandRunInput => ({ | |
| 20 | + command: 'record', | |
| 21 | + args: event, | |
| 22 | + origin: { kind: 'composer' }, | |
| 23 | +}) | |
| 24 | + | |
| 25 | +/** | |
| 26 | + * A plugin whose `/record <event>` logs that event through `$.telemetry`, | |
| 27 | + * answering "sent", or why the row was refused. | |
| 28 | + */ | |
| 31 | 29 | const recording: Plugin = { |
| 32 | 30 | name: 'recording', |
| 33 | 31 | register(on) { |
| 34 | - on('command.run', { command: 'survey' }, $ => | |
| 35 | - $.telemetry | |
| 36 | - .log({ event: 'survey_answered', props: { answer: 2, seen: true } }) | |
| 37 | - .then( | |
| 38 | - () => ({ text: 'sent' }), | |
| 39 | - (error: unknown) => ({ text: String(error) }), | |
| 40 | - ), | |
| 32 | + on('command.run', { command: 'record' }, ($, e) => | |
| 33 | + $.telemetry.log({ event: e.args, props: { answer: 2, seen: true } }).then( | |
| 34 | + () => ({ text: 'sent' }), | |
| 35 | + (error: unknown) => ({ text: String(error) }), | |
| 36 | + ), | |
| 41 | 37 | ) |
| 42 | - on('command.run', { command: 'shown' }, $ => | |
| 43 | - $.telemetry | |
| 44 | - .log({ event: 'tengu_repl_diff_panel_shown', props: { seen: true } }) | |
| 45 | - .then( | |
| 46 | - () => ({ text: 'sent' }), | |
| 47 | - (error: unknown) => ({ text: String(error) }), | |
| 48 | - ), | |
| 49 | - ) | |
| 50 | 38 | }, |
| 51 | 39 | } |
| 52 | 40 | |
| 53 | 41 | /** |
| 54 | 42 | * A first-party session: its id and model, the credential it holds, and |
| 55 | - * the ingest accepting each row, which is kept as it was posted. | |
| 43 | + * the ingest accepting each row, each post kept as it was made. | |
| 56 | 44 | */ |
| 57 | 45 | function firstPartySession( |
| 58 | 46 | on: On, |
| @@ -72,13 +60,10 @@ | ||
| 72 | 60 | } |
| 73 | 61 | |
| 74 | 62 | /** |
| 75 | - * The one row a post to the ingest carries. | |
| 63 | + * The batch a post to the ingest carries, as it was sent. | |
| 76 | 64 | */ |
| 77 | -function rowOf(post: Args<'http.fetch'> | undefined) { | |
| 78 | - const batch: { events: { event_data: Readonly<Record<string, unknown>> }[] } = | |
| 79 | - JSON.parse(String(post?.init?.body)) | |
| 80 | - | |
| 81 | - return batch.events[0]?.event_data | |
| 65 | +function batchOf(post: Args<'http.fetch'>): unknown { | |
| 66 | + return JSON.parse(String(post.init?.body)) | |
| 82 | 67 | } |
| 83 | 68 | |
| 84 | 69 | test( |
| @@ -88,14 +73,25 @@ | ||
| 88 | 73 | memoryEnv(on, { USER_TYPE: 'ant' }) |
| 89 | 74 | const posts = firstPartySession(on) |
| 90 | 75 | |
| 91 | - expect(await $.command.run(SURVEY)).toEqual({ text: 'sent' }) | |
| 76 | + expect(await $.command.run(record('survey_answered'))).toEqual({ | |
| 77 | + text: 'sent', | |
| 78 | + }) | |
| 92 | 79 | expect(posts).toHaveLength(1) |
| 93 | - expect(posts[0]?.init).toMatchObject({ method: 'POST', auth: 'the-handle' }) | |
| 94 | - expect(rowOf(posts[0])).toMatchObject({ | |
| 95 | - event_name: 'tengu_plugin_survey_answered', | |
| 96 | - session_id: 'the-session', | |
| 97 | - model: 'the-model', | |
| 98 | - user_type: 'ant', | |
| 80 | + | |
| 81 | + const [post] = posts | |
| 82 | + | |
| 83 | + expect(post.init).toMatchObject({ method: 'POST', auth: 'the-handle' }) | |
| 84 | + expect(batchOf(post)).toMatchObject({ | |
| 85 | + events: [ | |
| 86 | + { | |
| 87 | + event_data: { | |
| 88 | + event_name: 'tengu_plugin_survey_answered', | |
| 89 | + session_id: 'the-session', | |
| 90 | + model: 'the-model', | |
| 91 | + user_type: 'ant', | |
| 92 | + }, | |
| 93 | + }, | |
| 94 | + ], | |
| 99 | 95 | }) |
| 100 | 96 | }, |
| 101 | 97 | ) |
| @@ -107,12 +103,20 @@ | ||
| 107 | 103 | memoryEnv(on, {}) |
| 108 | 104 | const posts = firstPartySession(on) |
| 109 | 105 | |
| 110 | - await $.command.run(SHOWN) | |
| 106 | + await $.command.run(record('tengu_repl_diff_panel_shown')) | |
| 111 | 107 | |
| 112 | - expect(rowOf(posts[0])).toMatchObject({ | |
| 113 | - event_name: 'tengu_repl_diff_panel_shown', | |
| 114 | - user_type: 'external', | |
| 115 | - }) | |
| 108 | + expect(posts.map(batchOf)).toMatchObject([ | |
| 109 | + { | |
| 110 | + events: [ | |
| 111 | + { | |
| 112 | + event_data: { | |
| 113 | + event_name: 'tengu_repl_diff_panel_shown', | |
| 114 | + user_type: 'external', | |
| 115 | + }, | |
| 116 | + }, | |
| 117 | + ], | |
| 118 | + }, | |
| 119 | + ]) | |
| 116 | 120 | }, |
| 117 | 121 | ) |
| 118 | 122 | |
| @@ -123,7 +127,9 @@ | ||
| 123 | 127 | memoryEnv(on, { DO_NOT_TRACK: '1' }) |
| 124 | 128 | const posts = firstPartySession(on) |
| 125 | 129 | |
| 126 | - expect(await $.command.run(SURVEY)).toEqual({ text: 'sent' }) | |
| 130 | + expect(await $.command.run(record('survey_answered'))).toEqual({ | |
| 131 | + text: 'sent', | |
| 132 | + }) | |
| 127 | 133 | expect(posts).toEqual([]) |
| 128 | 134 | }, |
| 129 | 135 | ) |
| @@ -135,7 +141,7 @@ | ||
| 135 | 141 | memoryEnv(on, { CLAUDE_CODE_USE_BEDROCK: '1' }) |
| 136 | 142 | const posts = firstPartySession(on) |
| 137 | 143 | |
| 138 | - await $.command.run(SURVEY) | |
| 144 | + await $.command.run(record('survey_answered')) | |
| 139 | 145 | |
| 140 | 146 | expect(posts).toEqual([]) |
| 141 | 147 | }, |
| @@ -147,7 +153,7 @@ | ||
| 147 | 153 | async ($, on) => { |
| 148 | 154 | memoryEnv(on, {}) |
| 149 | 155 | const posts = firstPartySession(on, null) |
| 150 | - const { text } = await $.command.run(SURVEY) | |
| 156 | + const { text } = await $.command.run(record('survey_answered')) | |
| 151 | 157 | |
| 152 | 158 | expect(text).toEndWith( |
| 153 | 159 | '$.telemetry.log: this session has no first-party credential to ' + |