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
130 lines · 2.7 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 * Whether the session checkpoints edits (`$.settings.read`, `$.env.get`):
69 * the built-in panel opens on an edit only while it does.
70 */
71 isCheckpointing: () => Promise<boolean>
72
73 /**
74 * `$.session.messages`.
75 */
76 messages: () => Promise<SessionMessage[]>
77
78 /**
79 * `$.ui.invalidate("ui.render")`: every pane instance draws again.
80 */
81 invalidate: () => void
82
83 /**
84 * `$.ui.status`: the plugin's line under the prompt.
85 */
86 status: (text: string | undefined) => void
87
88 /**
89 * One debug line under the plugin's name (`$.ui.log`).
90 */
91 uiLog: (text: string) => void
92
93 /**
94 * `$.ui.open`.
95 */
96 openPane: (pane: PaneOpenArgs) => Promise<unknown>
97
98 /**
99 * `$.ui.close`.
100 */
101 closePane: (pane: PaneCloseArgs) => Promise<void>
102
103 /**
104 * `$.command.register`; rejects while another `/diff` is listed.
105 */
106 registerCommand: (spec: CommandSpec) => Promise<unknown>
107
108 /**
109 * Which session the pane-shown row is latched to, as `$.session.id` says.
110 */
111 sessionId: () => Promise<string>
112
113 /**
114 * When the session began, `$.session.usage`'s `startedAt`: where the line
115 * between this session's edits and earlier ones falls, a resumed session's
116 * first start, moved by `/clear`. Not a number under an engine that
117 * predates it, where the plugin's own start stands in.
118 */
119 startedAt: () => Promise<unknown>
120
121 /**
122 * `$.telemetry.mark`; rejects where the telemetry built-in is absent.
123 */
124 mark: EngineInterface['telemetry']['mark']
125
126 /**
127 * `$.telemetry.log`; rejects where the telemetry built-in is absent.
128 */
129 log: EngineInterface['telemetry']['log']
130}