spacehub

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

claude-code / mods / diff / hooks / host / host.ts
121 lines · 2.3 KBRaw
1import type {
2 CommandSpec,
3 EngineInterface,
4 FsEntry,
5 FsStat,
6 PaneCloseArgs,
7 PaneOpenArgs,
8 ProcessRunInit,
9 ProcessRunResult,
10 SessionMessage,
11 TimerCall,
12} from 'claude-code'
13
14/**
15 * The engine as `session.start` bound it from its `$`, each member spelled
16 * `$.noun.event(...)` there; used by every later hook, timer and press.
17 */
18export type Host = {
19 /**
20 * `$.clock.now`.
21 */
22 now: () => Promise<number>
23
24 /**
25 * `$.clock.after`.
26 */
27 after: TimerCall
28
29 /**
30 * `$.clock.every`.
31 */
32 every: TimerCall
33
34 /**
35 * `$.clock.sleep`, no signal.
36 */
37 sleep: (ms: number) => Promise<void>
38
39 /**
40 * `$.process.run`.
41 */
42 run: (
43 argv: readonly string[],
44 init: ProcessRunInit,
45 ) => Promise<ProcessRunResult>
46
47 /**
48 * `$.fs.stat`.
49 */
50 stat: (path: string) => Promise<FsStat>
51
52 /**
53 * `$.fs.list`: a directory's entries by kind, links never followed.
54 */
55 listDir: (path: string) => Promise<FsEntry[]>
56
57 /**
58 * `$.fs.read`.
59 */
60 readFile: (path: string) => Promise<string>
61
62 /**
63 * Reads the plugin's store (`$.store.get`).
64 */
65 storeGet: (key: string) => Promise<unknown>
66
67 /**
68 * Writes the plugin's store (`$.store.set`).
69 */
70 storeSet: (key: string, value: unknown) => Promise<void>
71
72 /**
73 * `$.session.messages`.
74 */
75 messages: () => Promise<SessionMessage[]>
76
77 /**
78 * `$.ui.invalidate("ui.render")`: every pane instance draws again.
79 */
80 invalidate: () => void
81
82 /**
83 * `$.ui.status`: the plugin's line under the prompt.
84 */
85 status: (text: string | undefined) => void
86
87 /**
88 * One debug line under the plugin's name (`$.ui.log`).
89 */
90 uiLog: (text: string) => void
91
92 /**
93 * `$.ui.open`.
94 */
95 openPane: (pane: PaneOpenArgs) => Promise<void>
96
97 /**
98 * `$.ui.close`.
99 */
100 closePane: (pane: PaneCloseArgs) => Promise<void>
101
102 /**
103 * `$.command.register`; rejects while another `/diff` is listed.
104 */
105 registerCommand: (spec: CommandSpec) => Promise<unknown>
106
107 /**
108 * Which session the pane-shown row is latched to, as `$.session.id` says.
109 */
110 sessionId: () => Promise<string>
111
112 /**
113 * `$.telemetry.mark`; rejects where the telemetry built-in is absent.
114 */
115 mark: EngineInterface['telemetry']['mark']
116
117 /**
118 * `$.telemetry.log`; rejects where the telemetry built-in is absent.
119 */
120 log: EngineInterface['telemetry']['log']
121}