portercode 0.1.3 → 0.1.10

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 (188) hide show
  1. package/LICENSE +174 -21
  2. package/README.md +101 -2
  3. package/dist/auth/index.d.ts +99 -0
  4. package/dist/brand/index.d.ts +7 -0
  5. package/dist/brand/loader.d.ts +463 -0
  6. package/dist/brand/rules.d.ts +25 -0
  7. package/dist/brand/schema.d.ts +246 -0
  8. package/dist/cli/auth.d.ts +14 -2
  9. package/dist/cli/brand.d.ts +6 -0
  10. package/dist/config/config.d.ts +0 -720
  11. package/dist/constants/index.d.ts +6 -9
  12. package/dist/constants/version.d.ts +5 -0
  13. package/dist/gateway/index.d.ts +5 -4
  14. package/dist/global/index.d.ts +12 -0
  15. package/dist/index.js +39 -1
  16. package/dist/prompt/template.d.ts +24 -0
  17. package/dist/provider/models.d.ts +0 -3
  18. package/dist/provider/provider.d.ts +5 -1
  19. package/dist/server/services/agent.d.ts +11 -0
  20. package/dist/session/context-cache.d.ts +75 -0
  21. package/dist/session/context-optimization.d.ts +5 -0
  22. package/dist/session/llm.d.ts +38 -1
  23. package/dist/session/message-optimizer.d.ts +32 -0
  24. package/dist/session/session.d.ts +101 -9
  25. package/dist/session/types.d.ts +92 -16
  26. package/dist/src/auth/index.d.ts +202 -0
  27. package/dist/src/brand/index.d.ts +7 -0
  28. package/dist/src/bus/bus-event.d.ts +10 -0
  29. package/dist/src/bus/global.d.ts +7 -0
  30. package/dist/src/bus/index.d.ts +26 -0
  31. package/dist/src/cli/auth.d.ts +23 -0
  32. package/dist/src/cli/index.d.ts +1 -0
  33. package/dist/src/cli/ui.d.ts +26 -0
  34. package/dist/src/command/index.d.ts +54 -0
  35. package/dist/src/config/config.d.ts +6036 -0
  36. package/dist/src/config/index.d.ts +2 -0
  37. package/dist/src/config/markdown.d.ts +415 -0
  38. package/dist/src/constants/index.d.ts +6 -0
  39. package/dist/src/constants/version.d.ts +5 -0
  40. package/dist/src/diff/engine.d.ts +15 -0
  41. package/dist/src/diff/index.d.ts +8 -0
  42. package/dist/src/diff/types.d.ts +66 -0
  43. package/dist/src/file/ignore.d.ts +7 -0
  44. package/dist/src/flag/index.d.ts +19 -0
  45. package/dist/src/gateway/bridge.d.ts +11 -0
  46. package/dist/src/gateway/handlers/llm.d.ts +7 -0
  47. package/dist/src/gateway/handlers/permission.d.ts +15 -0
  48. package/dist/src/gateway/handlers/session.d.ts +7 -0
  49. package/dist/src/gateway/handlers/system.d.ts +7 -0
  50. package/dist/src/gateway/handlers/tool.d.ts +7 -0
  51. package/dist/src/gateway/index.d.ts +18 -0
  52. package/dist/src/gateway/protocol.d.ts +159 -0
  53. package/dist/src/gateway/router.d.ts +7 -0
  54. package/dist/src/gateway/server.d.ts +24 -0
  55. package/dist/src/global/index.d.ts +23 -0
  56. package/dist/src/index.d.ts +2 -0
  57. package/dist/src/permission/index.d.ts +2 -0
  58. package/dist/src/permission/permission.d.ts +172 -0
  59. package/dist/src/permission/types.d.ts +109 -0
  60. package/dist/src/project/index.d.ts +3 -0
  61. package/dist/src/project/instance.d.ts +33 -0
  62. package/dist/src/project/project.d.ts +82 -0
  63. package/dist/src/project/state.d.ts +4 -0
  64. package/dist/src/prompt/index.d.ts +5 -0
  65. package/dist/src/prompt/system.d.ts +29 -0
  66. package/dist/src/prompt/template.d.ts +24 -0
  67. package/dist/src/provider/index.d.ts +3 -0
  68. package/dist/src/provider/models.d.ts +14 -0
  69. package/dist/src/provider/provider.d.ts +848 -0
  70. package/dist/src/provider/types.d.ts +328 -0
  71. package/dist/src/server/index.d.ts +21 -0
  72. package/dist/src/server/routes/api.d.ts +2 -0
  73. package/dist/src/server/routes/auth.d.ts +2 -0
  74. package/dist/src/server/routes/events.d.ts +2 -0
  75. package/dist/src/server/routes/health.d.ts +2 -0
  76. package/dist/src/server/routes/sessions.d.ts +2 -0
  77. package/dist/src/server/services/agent.d.ts +40 -0
  78. package/dist/src/server/services/permission.d.ts +43 -0
  79. package/dist/src/server/sse/emitter.d.ts +57 -0
  80. package/dist/src/session/context-cache.d.ts +75 -0
  81. package/dist/src/session/context-optimization.d.ts +165 -0
  82. package/dist/src/session/index.d.ts +5 -0
  83. package/dist/src/session/llm.d.ts +68 -0
  84. package/dist/src/session/message-optimizer.d.ts +32 -0
  85. package/dist/src/session/session.d.ts +524 -0
  86. package/dist/src/session/title-generator.d.ts +11 -0
  87. package/dist/src/session/types.d.ts +713 -0
  88. package/dist/src/snapshot/index.d.ts +40 -0
  89. package/dist/src/storage/index.d.ts +1 -0
  90. package/dist/src/storage/storage.d.ts +34 -0
  91. package/dist/src/theme.d.ts +66 -0
  92. package/dist/src/tool/bash.d.ts +19 -0
  93. package/dist/src/tool/edit.d.ts +21 -0
  94. package/dist/src/tool/glob.d.ts +15 -0
  95. package/dist/src/tool/grep.d.ts +20 -0
  96. package/dist/src/tool/image.d.ts +22 -0
  97. package/dist/src/tool/index.d.ts +11 -0
  98. package/dist/src/tool/ls.d.ts +14 -0
  99. package/dist/src/tool/read.d.ts +17 -0
  100. package/dist/src/tool/registry.d.ts +30 -0
  101. package/dist/src/tool/think.d.ts +11 -0
  102. package/dist/src/tool/todo.d.ts +76 -0
  103. package/dist/src/tool/tool.d.ts +65 -0
  104. package/dist/src/tool/webfetch.d.ts +15 -0
  105. package/dist/src/tool/websearch.d.ts +18 -0
  106. package/dist/src/tool/write.d.ts +16 -0
  107. package/dist/src/tui/App.d.ts +10 -0
  108. package/dist/src/tui/components/Header.d.ts +13 -0
  109. package/dist/src/tui/components/LoadingIndicator.d.ts +26 -0
  110. package/dist/src/tui/components/Message/AssistantMessage.d.ts +11 -0
  111. package/dist/src/tui/components/Message/ReasoningMessage.d.ts +21 -0
  112. package/dist/src/tui/components/Message/ToolCallMessage.d.ts +26 -0
  113. package/dist/src/tui/components/Message/UserMessage.d.ts +12 -0
  114. package/dist/src/tui/components/Message/index.d.ts +16 -0
  115. package/dist/src/tui/components/PermissionPrompt.d.ts +6 -0
  116. package/dist/src/tui/components/PromptInput.d.ts +33 -0
  117. package/dist/src/tui/components/REPL.d.ts +22 -0
  118. package/dist/src/tui/components/Spinner.d.ts +13 -0
  119. package/dist/src/tui/components/StatusBar.d.ts +13 -0
  120. package/dist/src/tui/components/TodoList.d.ts +17 -0
  121. package/dist/src/tui/components/WelcomeBox.d.ts +13 -0
  122. package/dist/src/tui/components/dialogs/DiagnosticsPanel.d.ts +12 -0
  123. package/dist/src/tui/components/dialogs/HelpPanel.d.ts +11 -0
  124. package/dist/src/tui/components/dialogs/ModelSelector.d.ts +14 -0
  125. package/dist/src/tui/components/dialogs/PermissionPrompt.d.ts +17 -0
  126. package/dist/src/tui/components/dialogs/SessionPicker.d.ts +20 -0
  127. package/dist/src/tui/components/dialogs/index.d.ts +10 -0
  128. package/dist/src/tui/components/diff/DiffHunk.d.ts +12 -0
  129. package/dist/src/tui/components/diff/DiffLine.d.ts +14 -0
  130. package/dist/src/tui/components/diff/DiffStats.d.ts +12 -0
  131. package/dist/src/tui/components/diff/DiffView.d.ts +15 -0
  132. package/dist/src/tui/components/diff/index.d.ts +9 -0
  133. package/dist/src/tui/hooks/useAnimatedLabel.d.ts +12 -0
  134. package/dist/src/tui/hooks/usePermission.d.ts +34 -0
  135. package/dist/src/tui/hooks/useTermWidth.d.ts +13 -0
  136. package/dist/src/tui/index.d.ts +20 -0
  137. package/dist/src/tui/theme.d.ts +8 -0
  138. package/dist/src/tui/utils/Cursor.d.ts +37 -0
  139. package/dist/src/tui/utils/clipboard.d.ts +3 -0
  140. package/dist/src/tui/utils/keypress.d.ts +39 -0
  141. package/dist/src/tui/utils/markdown.d.ts +13 -0
  142. package/dist/src/tui/utils/openContent.d.ts +22 -0
  143. package/dist/src/util/ascii.d.ts +22 -0
  144. package/dist/src/util/bell.d.ts +14 -0
  145. package/dist/src/util/color.d.ts +28 -0
  146. package/dist/src/util/context.d.ts +10 -0
  147. package/dist/src/util/debug.d.ts +51 -0
  148. package/dist/src/util/error.d.ts +294 -0
  149. package/dist/src/util/example-commands.d.ts +18 -0
  150. package/dist/src/util/filesystem.d.ts +17 -0
  151. package/dist/src/util/id.d.ts +24 -0
  152. package/dist/src/util/iife.d.ts +1 -0
  153. package/dist/src/util/index.d.ts +7 -0
  154. package/dist/src/util/lazy.d.ts +1 -0
  155. package/dist/src/util/log.d.ts +26 -0
  156. package/dist/src/util/paths.d.ts +45 -0
  157. package/dist/src/util/shell.d.ts +36 -0
  158. package/dist/src/util/timeout.d.ts +1 -0
  159. package/dist/src/util/wildcard.d.ts +8 -0
  160. package/dist/theme.d.ts +64 -0
  161. package/dist/tool/image.d.ts +3 -4
  162. package/dist/tool/think.d.ts +11 -0
  163. package/dist/tool/webfetch.d.ts +15 -0
  164. package/dist/tool/websearch.d.ts +18 -0
  165. package/dist/tools/think.d.ts +2 -0
  166. package/dist/tui/App.d.ts +1 -1
  167. package/dist/tui/components/Header.d.ts +2 -1
  168. package/dist/tui/components/LoadingIndicator.d.ts +26 -0
  169. package/dist/tui/components/Message/AssistantMessage.d.ts +2 -1
  170. package/dist/tui/components/Message/ReasoningMessage.d.ts +2 -1
  171. package/dist/tui/components/Message/ToolCallMessage.d.ts +3 -2
  172. package/dist/tui/components/Message/UserMessage.d.ts +2 -1
  173. package/dist/tui/components/Message/index.d.ts +4 -1
  174. package/dist/tui/components/PromptInput.d.ts +2 -1
  175. package/dist/tui/components/REPL.d.ts +6 -1
  176. package/dist/tui/components/StatusBar.d.ts +2 -1
  177. package/dist/tui/components/dialogs/SessionPicker.d.ts +6 -1
  178. package/dist/tui/hooks/useAnimatedLabel.d.ts +12 -0
  179. package/dist/tui/hooks/usePermission.d.ts +9 -1
  180. package/dist/tui/hooks/useTermWidth.d.ts +13 -0
  181. package/dist/tui/index.d.ts +5 -0
  182. package/dist/tui/theme.d.ts +4 -23
  183. package/dist/util/ascii.d.ts +22 -0
  184. package/dist/util/bell.d.ts +14 -0
  185. package/dist/util/color.d.ts +28 -0
  186. package/dist/util/paths.d.ts +45 -0
  187. package/dist/util/shell.d.ts +36 -0
  188. package/package.json +21 -1
@@ -0,0 +1,159 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Porter Wire Protocol (PWP)
4
+ * Protocolo de comunicacion bidireccional via WebSocket
5
+ * Usa MessagePack para serializacion binaria eficiente
6
+ */
7
+ export declare const MessageType: z.ZodEnum<["request", "response", "event", "stream"]>;
8
+ export type MessageType = z.infer<typeof MessageType>;
9
+ export declare const Channel: z.ZodEnum<["session", "llm", "tool", "permission", "system"]>;
10
+ export type Channel = z.infer<typeof Channel>;
11
+ export declare const PorterMessage: z.ZodObject<{
12
+ version: z.ZodLiteral<1>;
13
+ type: z.ZodEnum<["request", "response", "event", "stream"]>;
14
+ id: z.ZodString;
15
+ timestamp: z.ZodNumber;
16
+ channel: z.ZodEnum<["session", "llm", "tool", "permission", "system"]>;
17
+ action: z.ZodString;
18
+ payload: z.ZodUnknown;
19
+ }, "strip", z.ZodTypeAny, {
20
+ version: 1;
21
+ type: "event" | "request" | "response" | "stream";
22
+ id: string;
23
+ timestamp: number;
24
+ channel: "llm" | "session" | "tool" | "permission" | "system";
25
+ action: string;
26
+ payload?: unknown;
27
+ }, {
28
+ version: 1;
29
+ type: "event" | "request" | "response" | "stream";
30
+ id: string;
31
+ timestamp: number;
32
+ channel: "llm" | "session" | "tool" | "permission" | "system";
33
+ action: string;
34
+ payload?: unknown;
35
+ }>;
36
+ export type PorterMessage = z.infer<typeof PorterMessage>;
37
+ export declare function createRequest<T>(channel: Channel, action: string, payload: T): PorterMessage;
38
+ export declare function createResponse<T>(requestId: string, channel: Channel, action: string, payload: T): PorterMessage;
39
+ export declare function createEvent<T>(channel: Channel, action: string, payload: T): PorterMessage;
40
+ export declare function createStream<T>(streamId: string, channel: Channel, action: string, payload: T): PorterMessage;
41
+ export declare function createError(requestId: string, channel: Channel, error: string, details?: unknown): PorterMessage;
42
+ export declare const SessionPayloads: {
43
+ create: z.ZodObject<{
44
+ title: z.ZodOptional<z.ZodString>;
45
+ }, "strip", z.ZodTypeAny, {
46
+ title?: string | undefined;
47
+ }, {
48
+ title?: string | undefined;
49
+ }>;
50
+ list: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
51
+ get: z.ZodObject<{
52
+ sessionId: z.ZodString;
53
+ }, "strip", z.ZodTypeAny, {
54
+ sessionId: string;
55
+ }, {
56
+ sessionId: string;
57
+ }>;
58
+ messages: z.ZodObject<{
59
+ sessionId: z.ZodString;
60
+ }, "strip", z.ZodTypeAny, {
61
+ sessionId: string;
62
+ }, {
63
+ sessionId: string;
64
+ }>;
65
+ };
66
+ export declare const LLMPayloads: {
67
+ prompt: z.ZodObject<{
68
+ sessionId: z.ZodString;
69
+ content: z.ZodString;
70
+ attachments: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
71
+ }, "strip", z.ZodTypeAny, {
72
+ sessionId: string;
73
+ content: string;
74
+ attachments?: string[] | undefined;
75
+ }, {
76
+ sessionId: string;
77
+ content: string;
78
+ attachments?: string[] | undefined;
79
+ }>;
80
+ cancel: z.ZodObject<{
81
+ sessionId: z.ZodString;
82
+ }, "strip", z.ZodTypeAny, {
83
+ sessionId: string;
84
+ }, {
85
+ sessionId: string;
86
+ }>;
87
+ };
88
+ export declare const ToolPayloads: {
89
+ list: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
90
+ execute: z.ZodObject<{
91
+ toolId: z.ZodString;
92
+ args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
93
+ }, "strip", z.ZodTypeAny, {
94
+ toolId: string;
95
+ args: Record<string, unknown>;
96
+ }, {
97
+ toolId: string;
98
+ args: Record<string, unknown>;
99
+ }>;
100
+ };
101
+ export declare const PermissionPayloads: {
102
+ respond: z.ZodObject<{
103
+ id: z.ZodString;
104
+ granted: z.ZodBoolean;
105
+ pattern: z.ZodOptional<z.ZodString>;
106
+ }, "strip", z.ZodTypeAny, {
107
+ id: string;
108
+ granted: boolean;
109
+ pattern?: string | undefined;
110
+ }, {
111
+ id: string;
112
+ granted: boolean;
113
+ pattern?: string | undefined;
114
+ }>;
115
+ };
116
+ export declare const SystemPayloads: {
117
+ auth: z.ZodObject<{
118
+ token: z.ZodString;
119
+ clientId: z.ZodString;
120
+ capabilities: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
121
+ }, "strip", z.ZodTypeAny, {
122
+ token: string;
123
+ clientId: string;
124
+ capabilities?: string[] | undefined;
125
+ }, {
126
+ token: string;
127
+ clientId: string;
128
+ capabilities?: string[] | undefined;
129
+ }>;
130
+ health: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
131
+ };
132
+ export interface ConnectedClient {
133
+ id: string;
134
+ socket: WebSocket;
135
+ authenticated: boolean;
136
+ capabilities: string[];
137
+ subscriptions: Set<string>;
138
+ connectedAt: number;
139
+ }
140
+ export declare const GatewayInfo: z.ZodObject<{
141
+ pid: z.ZodNumber;
142
+ port: z.ZodNumber;
143
+ token: z.ZodString;
144
+ projectDir: z.ZodString;
145
+ startedAt: z.ZodNumber;
146
+ }, "strip", z.ZodTypeAny, {
147
+ token: string;
148
+ pid: number;
149
+ port: number;
150
+ projectDir: string;
151
+ startedAt: number;
152
+ }, {
153
+ token: string;
154
+ pid: number;
155
+ port: number;
156
+ projectDir: string;
157
+ startedAt: number;
158
+ }>;
159
+ export type GatewayInfo = z.infer<typeof GatewayInfo>;
@@ -0,0 +1,7 @@
1
+ import type { PorterMessage, ConnectedClient } from "./protocol";
2
+ export declare namespace Router {
3
+ /**
4
+ * Enruta un mensaje al handler apropiado
5
+ */
6
+ function handle(msg: PorterMessage, client: ConnectedClient): Promise<PorterMessage | void>;
7
+ }
@@ -0,0 +1,24 @@
1
+ import { type PorterMessage, type ConnectedClient, type GatewayInfo } from "./protocol";
2
+ export declare namespace Gateway {
3
+ /**
4
+ * Inicia el Gateway Server
5
+ * Encuentra un puerto dinamico y guarda la info en gateway.json
6
+ */
7
+ function start(): Promise<GatewayInfo>;
8
+ /**
9
+ * Detiene el Gateway Server
10
+ */
11
+ function stop(): void;
12
+ /**
13
+ * Envia un mensaje a todos los clientes autenticados
14
+ */
15
+ function broadcast(msg: PorterMessage): void;
16
+ /**
17
+ * Envia un mensaje a un cliente especifico
18
+ */
19
+ function send(clientId: string, msg: PorterMessage): void;
20
+ /**
21
+ * Obtiene la lista de clientes conectados
22
+ */
23
+ function getClients(): ConnectedClient[];
24
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Helper function to resolve home directory paths (~/...)
3
+ * Works cross-platform (Windows, macOS, Linux)
4
+ */
5
+ export declare function resolveHomePath(filepath: string): string;
6
+ /**
7
+ * Get platform-specific config directory for a command
8
+ * - Windows: %APPDATA%\<commandName>
9
+ * - macOS: ~/Library/Application Support/<commandName>
10
+ * - Linux: ~/.config/<commandName>
11
+ */
12
+ export declare function getConfigDir(commandName: string): string;
13
+ export declare namespace Global {
14
+ const Path: {
15
+ readonly home: string;
16
+ readonly data: string;
17
+ readonly bin: string;
18
+ readonly log: string;
19
+ readonly cache: string;
20
+ readonly config: string;
21
+ readonly state: string;
22
+ };
23
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from "./types";
2
+ export { Permission, type PermissionMode } from "./permission";
@@ -0,0 +1,172 @@
1
+ import z from "zod";
2
+ import type { PermissionRequest, PermissionResponse, ToolPermissions } from "./types";
3
+ export type PermissionMode = "auto" | "ask" | "plan";
4
+ export declare namespace Permission {
5
+ /**
6
+ * Load allowed patterns from config file
7
+ */
8
+ function loadPatterns(): Promise<void>;
9
+ /**
10
+ * Set the current permission mode
11
+ * Clears session-scoped remembered permissions but keeps permanent ones
12
+ */
13
+ function setMode(mode: PermissionMode): void;
14
+ /**
15
+ * Get the current permission mode
16
+ */
17
+ function getMode(): PermissionMode;
18
+ /**
19
+ * Permission events
20
+ */
21
+ const Event: {
22
+ Request: {
23
+ type: "permission.request";
24
+ properties: z.ZodObject<{
25
+ request: z.ZodType<{
26
+ id: string;
27
+ tool: string;
28
+ action: string;
29
+ description: string;
30
+ risk: "low" | "medium" | "high";
31
+ details?: Record<string, any> | undefined;
32
+ }, z.ZodTypeDef, {
33
+ id: string;
34
+ tool: string;
35
+ action: string;
36
+ description: string;
37
+ risk: "low" | "medium" | "high";
38
+ details?: Record<string, any> | undefined;
39
+ }>;
40
+ }, "strip", z.ZodTypeAny, {
41
+ request: {
42
+ id: string;
43
+ tool: string;
44
+ action: string;
45
+ description: string;
46
+ risk: "low" | "medium" | "high";
47
+ details?: Record<string, any> | undefined;
48
+ };
49
+ }, {
50
+ request: {
51
+ id: string;
52
+ tool: string;
53
+ action: string;
54
+ description: string;
55
+ risk: "low" | "medium" | "high";
56
+ details?: Record<string, any> | undefined;
57
+ };
58
+ }>;
59
+ };
60
+ Response: {
61
+ type: "permission.response";
62
+ properties: z.ZodObject<{
63
+ response: z.ZodType<{
64
+ id: string;
65
+ granted: boolean;
66
+ remember: boolean;
67
+ }, z.ZodTypeDef, {
68
+ id: string;
69
+ granted: boolean;
70
+ remember: boolean;
71
+ }>;
72
+ }, "strip", z.ZodTypeAny, {
73
+ response: {
74
+ id: string;
75
+ granted: boolean;
76
+ remember: boolean;
77
+ };
78
+ }, {
79
+ response: {
80
+ id: string;
81
+ granted: boolean;
82
+ remember: boolean;
83
+ };
84
+ }>;
85
+ };
86
+ };
87
+ /**
88
+ * Get effective permissions based on current mode and config
89
+ */
90
+ function getPermissions(): Promise<ToolPermissions>;
91
+ /**
92
+ * Check if a file path is within the project directory
93
+ */
94
+ function isInProject(filepath: string): boolean;
95
+ /**
96
+ * Check permission for file edit
97
+ */
98
+ function checkEdit(filepath: string): Promise<boolean>;
99
+ /**
100
+ * Check permission for file write
101
+ */
102
+ function checkWrite(filepath: string): Promise<boolean>;
103
+ /**
104
+ * Check permission for bash command
105
+ *
106
+ * Bash commands are ALWAYS validated against stored patterns,
107
+ * regardless of permission mode. This ensures security even in auto mode.
108
+ */
109
+ function checkBash(command: string): Promise<boolean>;
110
+ /**
111
+ * Check permission for web fetch
112
+ */
113
+ function checkWebFetch(url: string): Promise<boolean>;
114
+ /**
115
+ * Respond to a permission request (called by UI)
116
+ */
117
+ function respond(response: PermissionResponse): void;
118
+ /**
119
+ * Grant a pending permission request
120
+ */
121
+ function grant(id: string, remember?: boolean): void;
122
+ /**
123
+ * Deny a pending permission request
124
+ */
125
+ function deny(id: string, remember?: boolean): void;
126
+ /**
127
+ * Clear remembered permissions
128
+ */
129
+ function clearRemembered(): void;
130
+ /**
131
+ * Clear all permissions (remembered and permanent)
132
+ * Also resets the patterns loaded flag for testing
133
+ */
134
+ function clearAll(): void;
135
+ /**
136
+ * Get all pending permission requests
137
+ */
138
+ function getPending(): PermissionRequest[];
139
+ /**
140
+ * Get all permanent permissions (allowed patterns)
141
+ */
142
+ function getPermanentPermissions(): string[];
143
+ /**
144
+ * Grant a permission permanently for a pattern
145
+ * Saves the pattern to the project config file
146
+ */
147
+ function grantPermanent(id: string, pattern: string): void;
148
+ /**
149
+ * Deny a permission permanently for a pattern
150
+ * Saves the pattern to the project config file
151
+ */
152
+ function denyPermanent(id: string, pattern: string): void;
153
+ /**
154
+ * Match a permission key against a pattern
155
+ * Supports wildcards: * matches one segment, ** matches any depth
156
+ */
157
+ function matchPermissionPattern(key: string, pattern: string): boolean;
158
+ /**
159
+ * Generate a permission key for a tool and target
160
+ */
161
+ function generatePermissionKey(tool: string, target: string): string;
162
+ /**
163
+ * Infer a pattern from a tool and target
164
+ * Returns a reasonable pattern that could be used for "allow always"
165
+ */
166
+ function inferPattern(tool: string, target: string): string;
167
+ /**
168
+ * Suggest possible patterns for a tool and target
169
+ * Returns patterns from most specific to least specific
170
+ */
171
+ function suggestPatterns(tool: string, target: string): string[];
172
+ }
@@ -0,0 +1,109 @@
1
+ import z from "zod";
2
+ /**
3
+ * Permission System Types
4
+ *
5
+ * Defines permission levels and rules for tool execution.
6
+ */
7
+ /**
8
+ * Permission level for an action
9
+ */
10
+ export declare const PermissionLevel: z.ZodEnum<["allow", "ask", "deny"]>;
11
+ export type PermissionLevel = z.infer<typeof PermissionLevel>;
12
+ /**
13
+ * Permission rule with optional pattern matching
14
+ */
15
+ export declare const PermissionRule: z.ZodObject<{
16
+ pattern: z.ZodString;
17
+ level: z.ZodEnum<["allow", "ask", "deny"]>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ pattern: string;
20
+ level: "ask" | "allow" | "deny";
21
+ }, {
22
+ pattern: string;
23
+ level: "ask" | "allow" | "deny";
24
+ }>;
25
+ export type PermissionRule = z.infer<typeof PermissionRule>;
26
+ /**
27
+ * Tool-specific permissions
28
+ */
29
+ export declare const ToolPermissions: z.ZodObject<{
30
+ edit: z.ZodDefault<z.ZodEnum<["allow", "ask", "deny"]>>;
31
+ write: z.ZodDefault<z.ZodEnum<["allow", "ask", "deny"]>>;
32
+ bash: z.ZodDefault<z.ZodUnion<[z.ZodEnum<["allow", "ask", "deny"]>, z.ZodRecord<z.ZodString, z.ZodEnum<["allow", "ask", "deny"]>>]>>;
33
+ webfetch: z.ZodDefault<z.ZodEnum<["allow", "ask", "deny"]>>;
34
+ externalDirectory: z.ZodDefault<z.ZodEnum<["allow", "ask", "deny"]>>;
35
+ }, "strip", z.ZodTypeAny, {
36
+ write: "ask" | "allow" | "deny";
37
+ bash: "ask" | "allow" | "deny" | Record<string, "ask" | "allow" | "deny">;
38
+ edit: "ask" | "allow" | "deny";
39
+ webfetch: "ask" | "allow" | "deny";
40
+ externalDirectory: "ask" | "allow" | "deny";
41
+ }, {
42
+ write?: "ask" | "allow" | "deny" | undefined;
43
+ bash?: "ask" | "allow" | "deny" | Record<string, "ask" | "allow" | "deny"> | undefined;
44
+ edit?: "ask" | "allow" | "deny" | undefined;
45
+ webfetch?: "ask" | "allow" | "deny" | undefined;
46
+ externalDirectory?: "ask" | "allow" | "deny" | undefined;
47
+ }>;
48
+ export type ToolPermissions = z.infer<typeof ToolPermissions>;
49
+ /**
50
+ * Stored allowed patterns for bash commands
51
+ * Persisted to project-level config file
52
+ */
53
+ export declare const AllowedPatterns: z.ZodObject<{
54
+ bash: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
55
+ edit: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
56
+ write: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
57
+ }, "strip", z.ZodTypeAny, {
58
+ write: string[];
59
+ bash: string[];
60
+ edit: string[];
61
+ }, {
62
+ write?: string[] | undefined;
63
+ bash?: string[] | undefined;
64
+ edit?: string[] | undefined;
65
+ }>;
66
+ export type AllowedPatterns = z.infer<typeof AllowedPatterns>;
67
+ /**
68
+ * Permission request for user confirmation
69
+ */
70
+ export declare const PermissionRequest: z.ZodObject<{
71
+ id: z.ZodString;
72
+ tool: z.ZodString;
73
+ action: z.ZodString;
74
+ description: z.ZodString;
75
+ risk: z.ZodDefault<z.ZodEnum<["low", "medium", "high"]>>;
76
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
77
+ }, "strip", z.ZodTypeAny, {
78
+ id: string;
79
+ tool: string;
80
+ action: string;
81
+ description: string;
82
+ risk: "low" | "medium" | "high";
83
+ details?: Record<string, any> | undefined;
84
+ }, {
85
+ id: string;
86
+ tool: string;
87
+ action: string;
88
+ description: string;
89
+ risk?: "low" | "medium" | "high" | undefined;
90
+ details?: Record<string, any> | undefined;
91
+ }>;
92
+ export type PermissionRequest = z.infer<typeof PermissionRequest>;
93
+ /**
94
+ * Permission response from user
95
+ */
96
+ export declare const PermissionResponse: z.ZodObject<{
97
+ id: z.ZodString;
98
+ granted: z.ZodBoolean;
99
+ remember: z.ZodDefault<z.ZodBoolean>;
100
+ }, "strip", z.ZodTypeAny, {
101
+ id: string;
102
+ granted: boolean;
103
+ remember: boolean;
104
+ }, {
105
+ id: string;
106
+ granted: boolean;
107
+ remember?: boolean | undefined;
108
+ }>;
109
+ export type PermissionResponse = z.infer<typeof PermissionResponse>;
@@ -0,0 +1,3 @@
1
+ export * from "./project";
2
+ export * from "./instance";
3
+ export * from "./state";
@@ -0,0 +1,33 @@
1
+ import { Project } from "./project";
2
+ export declare const Instance: {
3
+ /**
4
+ * Provide an instance context for a given directory
5
+ * Supports two signatures:
6
+ * 1. { directory, init?, fn } - auto-detects project
7
+ * 2. { project, directory, worktree }, fn - explicit context (for testing)
8
+ */
9
+ provide<R>(input: {
10
+ directory: string;
11
+ init?: () => Promise<any>;
12
+ fn: () => R;
13
+ } | {
14
+ project: Project.Info;
15
+ directory: string;
16
+ worktree: string;
17
+ }, fn?: () => R): Promise<R>;
18
+ readonly directory: string;
19
+ readonly worktree: string;
20
+ readonly project: {
21
+ id: string;
22
+ worktree: string;
23
+ time: {
24
+ created: number;
25
+ updated: number;
26
+ };
27
+ vcs?: "git" | undefined;
28
+ name?: string | undefined;
29
+ };
30
+ state<S>(init: () => S, dispose?: (state: Awaited<S>) => Promise<void>): () => S;
31
+ dispose(): Promise<void>;
32
+ disposeAll(): Promise<void>;
33
+ };
@@ -0,0 +1,82 @@
1
+ import z from "zod";
2
+ export declare namespace Project {
3
+ const Info: z.ZodObject<{
4
+ id: z.ZodString;
5
+ worktree: z.ZodString;
6
+ vcs: z.ZodOptional<z.ZodLiteral<"git">>;
7
+ name: z.ZodOptional<z.ZodString>;
8
+ time: z.ZodObject<{
9
+ created: z.ZodNumber;
10
+ updated: z.ZodNumber;
11
+ }, "strip", z.ZodTypeAny, {
12
+ created: number;
13
+ updated: number;
14
+ }, {
15
+ created: number;
16
+ updated: number;
17
+ }>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ id: string;
20
+ worktree: string;
21
+ time: {
22
+ created: number;
23
+ updated: number;
24
+ };
25
+ vcs?: "git" | undefined;
26
+ name?: string | undefined;
27
+ }, {
28
+ id: string;
29
+ worktree: string;
30
+ time: {
31
+ created: number;
32
+ updated: number;
33
+ };
34
+ vcs?: "git" | undefined;
35
+ name?: string | undefined;
36
+ }>;
37
+ type Info = z.infer<typeof Info>;
38
+ const Event: {
39
+ Updated: {
40
+ type: "project.updated";
41
+ properties: z.ZodObject<{
42
+ id: z.ZodString;
43
+ worktree: z.ZodString;
44
+ vcs: z.ZodOptional<z.ZodLiteral<"git">>;
45
+ name: z.ZodOptional<z.ZodString>;
46
+ time: z.ZodObject<{
47
+ created: z.ZodNumber;
48
+ updated: z.ZodNumber;
49
+ }, "strip", z.ZodTypeAny, {
50
+ created: number;
51
+ updated: number;
52
+ }, {
53
+ created: number;
54
+ updated: number;
55
+ }>;
56
+ }, "strip", z.ZodTypeAny, {
57
+ id: string;
58
+ worktree: string;
59
+ time: {
60
+ created: number;
61
+ updated: number;
62
+ };
63
+ vcs?: "git" | undefined;
64
+ name?: string | undefined;
65
+ }, {
66
+ id: string;
67
+ worktree: string;
68
+ time: {
69
+ created: number;
70
+ updated: number;
71
+ };
72
+ vcs?: "git" | undefined;
73
+ name?: string | undefined;
74
+ }>;
75
+ };
76
+ };
77
+ function fromDirectory(directory: string): Promise<Info>;
78
+ /**
79
+ * Alias for fromDirectory for compatibility
80
+ */
81
+ const detect: typeof fromDirectory;
82
+ }
@@ -0,0 +1,4 @@
1
+ export declare namespace State {
2
+ function create<S>(root: () => string, init: () => S, dispose?: (state: Awaited<S>) => Promise<void>): () => S;
3
+ function dispose(key: string): Promise<void>;
4
+ }
@@ -0,0 +1,5 @@
1
+ export { SystemPrompt, type OperationMode } from "./system";
2
+ export { default as PROMPT_TITLE } from "./title.txt";
3
+ export { default as PROMPT_SUMMARY } from "./summary.txt";
4
+ export { default as PROMPT_CONTEXT_OPTIMIZATION } from "./context-optimization.txt";
5
+ export { default as PROMPT_EXPLORE } from "./explore.txt";
@@ -0,0 +1,29 @@
1
+ /**
2
+ * System Prompt Management
3
+ *
4
+ * Assembles system prompts from templates, environment info, and custom rules.
5
+ * Different prompts are used based on the model provider for optimal behavior.
6
+ */
7
+ export type OperationMode = "ask" | "auto" | "plan";
8
+ export declare namespace SystemPrompt {
9
+ /**
10
+ * Get planning mode prompt
11
+ */
12
+ function forPlanMode(): string[];
13
+ /**
14
+ * Get provider-specific prompt template
15
+ */
16
+ function forModel(modelId: string): string[];
17
+ /**
18
+ * Get environment context information
19
+ */
20
+ function environment(): Promise<string[]>;
21
+ /**
22
+ * Load custom rules from PORTER.md files
23
+ */
24
+ function customRules(): Promise<string[]>;
25
+ /**
26
+ * Assemble complete system prompt for a model
27
+ */
28
+ function assemble(modelId: string, mode?: OperationMode): Promise<string[]>;
29
+ }