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
116 lines · 2.2 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 * `$.process.run`.
36 */
37 run: (
38 argv: readonly string[],
39 init: ProcessRunInit,
40 ) => Promise<ProcessRunResult>
41
42 /**
43 * `$.fs.stat`.
44 */
45 stat: (path: string) => Promise<FsStat>
46
47 /**
48 * `$.fs.list`: a directory's entries by kind, links never followed.
49 */
50 listDir: (path: string) => Promise<FsEntry[]>
51
52 /**
53 * `$.fs.read`.
54 */
55 readFile: (path: string) => Promise<string>
56
57 /**
58 * Reads the plugin's store (`$.store.get`).
59 */
60 storeGet: (key: string) => Promise<unknown>
61
62 /**
63 * Writes the plugin's store (`$.store.set`).
64 */
65 storeSet: (key: string, value: unknown) => Promise<void>
66
67 /**
68 * `$.session.messages`.
69 */
70 messages: () => Promise<SessionMessage[]>
71
72 /**
73 * `$.ui.invalidate("ui.render")`: every pane instance draws again.
74 */
75 invalidate: () => void
76
77 /**
78 * `$.ui.status`: the plugin's line under the prompt.
79 */
80 status: (text: string | undefined) => void
81
82 /**
83 * One debug line under the plugin's name (`$.ui.log`).
84 */
85 uiLog: (text: string) => void
86
87 /**
88 * `$.ui.open`.
89 */
90 openPane: (pane: PaneOpenArgs) => Promise<unknown>
91
92 /**
93 * `$.ui.close`.
94 */
95 closePane: (pane: PaneCloseArgs) => Promise<void>
96
97 /**
98 * `$.command.register`; rejects while another `/diff` is listed.
99 */
100 registerCommand: (spec: CommandSpec) => Promise<unknown>
101
102 /**
103 * Which session the pane-shown row is latched to, as `$.session.id` says.
104 */
105 sessionId: () => Promise<string>
106
107 /**
108 * `$.telemetry.mark`; rejects where the telemetry built-in is absent.
109 */
110 mark: EngineInterface['telemetry']['mark']
111
112 /**
113 * `$.telemetry.log`; rejects where the telemetry built-in is absent.
114 */
115 log: EngineInterface['telemetry']['log']
116}