portercode 0.1.0 → 0.1.2

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.
@@ -1,4 +1,4 @@
1
- export { SystemPrompt } from "./system";
1
+ export { SystemPrompt, type OperationMode } from "./system";
2
2
  export { default as PROMPT_TITLE } from "./title.txt";
3
3
  export { default as PROMPT_SUMMARY } from "./summary.txt";
4
4
  export { default as PROMPT_CONTEXT_OPTIMIZATION } from "./context-optimization.txt";
@@ -4,7 +4,12 @@
4
4
  * Assembles system prompts from templates, environment info, and custom rules.
5
5
  * Different prompts are used based on the model provider for optimal behavior.
6
6
  */
7
+ export type OperationMode = "ask" | "auto" | "plan";
7
8
  export declare namespace SystemPrompt {
9
+ /**
10
+ * Get planning mode prompt
11
+ */
12
+ function forPlanMode(): string[];
8
13
  /**
9
14
  * Get provider-specific prompt template
10
15
  */
@@ -20,5 +25,5 @@ export declare namespace SystemPrompt {
20
25
  /**
21
26
  * Assemble complete system prompt for a model
22
27
  */
23
- function assemble(modelId: string): Promise<string[]>;
28
+ function assemble(modelId: string, mode?: OperationMode): Promise<string[]>;
24
29
  }
@@ -0,0 +1,21 @@
1
+ export interface ServerInfo {
2
+ port: number;
3
+ projectDir: string;
4
+ startedAt: number;
5
+ }
6
+ /**
7
+ * Start the HTTP server
8
+ */
9
+ export declare function startServer(port?: number): Promise<ServerInfo>;
10
+ /**
11
+ * Stop the HTTP server
12
+ */
13
+ export declare function stopServer(): void;
14
+ /**
15
+ * Get current server info
16
+ */
17
+ export declare function getServerInfo(): ServerInfo | null;
18
+ /**
19
+ * Get the SSE emitter for broadcasting events
20
+ */
21
+ export { SSEEmitter } from "./sse/emitter";
@@ -0,0 +1,2 @@
1
+ import { Hono } from "hono";
2
+ export declare const apiRoutes: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,2 @@
1
+ import { Hono } from "hono";
2
+ export declare const eventsRoutes: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,2 @@
1
+ import { Hono } from "hono";
2
+ export declare const healthRoutes: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,2 @@
1
+ import { Hono } from "hono";
2
+ export declare const sessionsRoutes: Hono<import("hono/types").BlankEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Agent Service
3
+ *
4
+ * Handles LLM invocation and streaming for the HTTP API.
5
+ * Extracted from TUI REPL for reuse.
6
+ */
7
+ export type AgentMode = "ask" | "auto" | "plan";
8
+ export declare namespace AgentService {
9
+ interface ImageAttachment {
10
+ data: string;
11
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
12
+ filename?: string;
13
+ }
14
+ interface RunOptions {
15
+ sessionId: string;
16
+ content: string;
17
+ requestId: string;
18
+ images?: ImageAttachment[];
19
+ mode?: AgentMode;
20
+ }
21
+ /**
22
+ * Run the agent for a prompt
23
+ */
24
+ function run(options: RunOptions): Promise<void>;
25
+ /**
26
+ * Cancel an active generation
27
+ */
28
+ function cancel(sessionId: string): boolean;
29
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Permission Service
3
+ *
4
+ * Manages permission requests for tool execution in "ask" mode.
5
+ * Tools wait for user approval before executing.
6
+ */
7
+ export type PermissionResponse = "allow" | "allow_always" | "deny" | "deny_with_message";
8
+ export interface PermissionRequest {
9
+ id: string;
10
+ sessionId: string;
11
+ requestId: string;
12
+ toolName: string;
13
+ toolCallId: string;
14
+ args: Record<string, unknown>;
15
+ description?: string;
16
+ createdAt: number;
17
+ }
18
+ export declare namespace PermissionService {
19
+ /**
20
+ * Request permission for a tool execution
21
+ * Returns a promise that resolves when the user responds
22
+ */
23
+ function request(sessionId: string, requestId: string, toolName: string, toolCallId: string, args: Record<string, unknown>, description?: string): Promise<{
24
+ allowed: boolean;
25
+ message?: string;
26
+ }>;
27
+ /**
28
+ * Respond to a pending permission request
29
+ */
30
+ function respond(permissionId: string, response: PermissionResponse, message?: string): boolean;
31
+ /**
32
+ * Cancel a pending permission request
33
+ */
34
+ function cancel(permissionId: string): boolean;
35
+ /**
36
+ * Cancel all pending permissions for a session
37
+ */
38
+ function cancelSession(sessionId: string): number;
39
+ /**
40
+ * Get all pending permissions for a session
41
+ */
42
+ function getPending(sessionId: string): PermissionRequest[];
43
+ }
@@ -0,0 +1,57 @@
1
+ export interface SSEClient {
2
+ id: string;
3
+ controller: ReadableStreamDefaultController<Uint8Array>;
4
+ connectedAt: number;
5
+ }
6
+ export interface SSEEvent {
7
+ type: string;
8
+ data: unknown;
9
+ id?: string;
10
+ }
11
+ declare class SSEEmitterClass {
12
+ private clients;
13
+ private heartbeatInterval;
14
+ private encoder;
15
+ /**
16
+ * Start heartbeat to keep connections alive
17
+ */
18
+ startHeartbeat(intervalMs?: number): void;
19
+ /**
20
+ * Stop heartbeat
21
+ */
22
+ stopHeartbeat(): void;
23
+ /**
24
+ * Add a new SSE client
25
+ */
26
+ addClient(id: string, controller: ReadableStreamDefaultController<Uint8Array>): void;
27
+ /**
28
+ * Remove an SSE client
29
+ */
30
+ removeClient(id: string): void;
31
+ /**
32
+ * Send event to a specific client
33
+ */
34
+ sendToClient(clientId: string, event: SSEEvent): void;
35
+ /**
36
+ * Broadcast event to all connected clients
37
+ */
38
+ broadcast(event: SSEEvent): void;
39
+ /**
40
+ * Format event for SSE protocol
41
+ */
42
+ private formatSSE;
43
+ /**
44
+ * Get connected client count
45
+ */
46
+ get clientCount(): number;
47
+ /**
48
+ * Get all client IDs
49
+ */
50
+ getClientIds(): string[];
51
+ /**
52
+ * Reset emitter state (for testing)
53
+ */
54
+ reset(): void;
55
+ }
56
+ export declare const SSEEmitter: SSEEmitterClass;
57
+ export {};
@@ -2,3 +2,4 @@ export * from "./types";
2
2
  export { Session } from "./session";
3
3
  export { LLM } from "./llm";
4
4
  export { ContextOptimization } from "./context-optimization";
5
+ export { TitleGenerator } from "./title-generator";
@@ -1,4 +1,5 @@
1
1
  import { streamText, type ModelMessage, type Tool } from "ai";
2
+ import { type OperationMode } from "../prompt";
2
3
  import type { ModelInfo } from "../provider/types";
3
4
  export declare namespace LLM {
4
5
  interface StreamOptions {
@@ -10,6 +11,7 @@ export declare namespace LLM {
10
11
  temperature?: number;
11
12
  maxTokens?: number;
12
13
  signal?: AbortSignal;
14
+ mode?: OperationMode;
13
15
  }
14
16
  interface StreamResult {
15
17
  stream: AsyncIterable<any>;
@@ -226,6 +226,14 @@ export declare namespace Session {
226
226
  input?: Record<string, any> | undefined;
227
227
  toolName?: string | undefined;
228
228
  metadata?: Record<string, any> | undefined;
229
+ } | {
230
+ type: "image";
231
+ id: string;
232
+ sessionId: string;
233
+ messageId: string;
234
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
235
+ data: string;
236
+ filename?: string | undefined;
229
237
  }, z.ZodTypeDef, {
230
238
  type: "text";
231
239
  id: string;
@@ -257,6 +265,14 @@ export declare namespace Session {
257
265
  input?: Record<string, any> | undefined;
258
266
  toolName?: string | undefined;
259
267
  metadata?: Record<string, any> | undefined;
268
+ } | {
269
+ type: "image";
270
+ id: string;
271
+ sessionId: string;
272
+ messageId: string;
273
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
274
+ data: string;
275
+ filename?: string | undefined;
260
276
  }>;
261
277
  delta: z.ZodOptional<z.ZodString>;
262
278
  }, "strip", z.ZodTypeAny, {
@@ -291,6 +307,14 @@ export declare namespace Session {
291
307
  input?: Record<string, any> | undefined;
292
308
  toolName?: string | undefined;
293
309
  metadata?: Record<string, any> | undefined;
310
+ } | {
311
+ type: "image";
312
+ id: string;
313
+ sessionId: string;
314
+ messageId: string;
315
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
316
+ data: string;
317
+ filename?: string | undefined;
294
318
  };
295
319
  delta?: string | undefined;
296
320
  }, {
@@ -325,6 +349,14 @@ export declare namespace Session {
325
349
  input?: Record<string, any> | undefined;
326
350
  toolName?: string | undefined;
327
351
  metadata?: Record<string, any> | undefined;
352
+ } | {
353
+ type: "image";
354
+ id: string;
355
+ sessionId: string;
356
+ messageId: string;
357
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
358
+ data: string;
359
+ filename?: string | undefined;
328
360
  };
329
361
  delta?: string | undefined;
330
362
  }>;
@@ -366,7 +398,7 @@ export declare namespace Session {
366
398
  */
367
399
  function touch(sessionId: string): Promise<void>;
368
400
  /**
369
- * List all sessions for current project
401
+ * List all sessions for current project, sorted by updatedAt (most recent first)
370
402
  */
371
403
  function list(): Promise<SessionInfo[]>;
372
404
  /**
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Title Generator
3
+ *
4
+ * Generates session titles from the first 5 words of the user's message.
5
+ */
6
+ export declare namespace TitleGenerator {
7
+ /**
8
+ * Generate a title from the first 5 words of the message
9
+ */
10
+ function generateTitle(message: string): string;
11
+ }
@@ -155,6 +155,35 @@ export declare const ToolResultPart: z.ZodObject<{
155
155
  metadata?: Record<string, any> | undefined;
156
156
  }>;
157
157
  export type ToolResultPart = z.infer<typeof ToolResultPart>;
158
+ /**
159
+ * Image content part (for vision models)
160
+ */
161
+ export declare const ImagePart: z.ZodObject<{
162
+ type: z.ZodLiteral<"image">;
163
+ id: z.ZodString;
164
+ messageId: z.ZodString;
165
+ sessionId: z.ZodString;
166
+ mimeType: z.ZodEnum<["image/png", "image/jpeg", "image/gif", "image/webp"]>;
167
+ data: z.ZodString;
168
+ filename: z.ZodOptional<z.ZodString>;
169
+ }, "strip", z.ZodTypeAny, {
170
+ type: "image";
171
+ id: string;
172
+ sessionId: string;
173
+ messageId: string;
174
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
175
+ data: string;
176
+ filename?: string | undefined;
177
+ }, {
178
+ type: "image";
179
+ id: string;
180
+ sessionId: string;
181
+ messageId: string;
182
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
183
+ data: string;
184
+ filename?: string | undefined;
185
+ }>;
186
+ export type ImagePart = z.infer<typeof ImagePart>;
158
187
  /**
159
188
  * All message part types
160
189
  */
@@ -251,6 +280,30 @@ export declare const MessagePart: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
251
280
  input?: Record<string, any> | undefined;
252
281
  toolName?: string | undefined;
253
282
  metadata?: Record<string, any> | undefined;
283
+ }>, z.ZodObject<{
284
+ type: z.ZodLiteral<"image">;
285
+ id: z.ZodString;
286
+ messageId: z.ZodString;
287
+ sessionId: z.ZodString;
288
+ mimeType: z.ZodEnum<["image/png", "image/jpeg", "image/gif", "image/webp"]>;
289
+ data: z.ZodString;
290
+ filename: z.ZodOptional<z.ZodString>;
291
+ }, "strip", z.ZodTypeAny, {
292
+ type: "image";
293
+ id: string;
294
+ sessionId: string;
295
+ messageId: string;
296
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
297
+ data: string;
298
+ filename?: string | undefined;
299
+ }, {
300
+ type: "image";
301
+ id: string;
302
+ sessionId: string;
303
+ messageId: string;
304
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
305
+ data: string;
306
+ filename?: string | undefined;
254
307
  }>]>;
255
308
  export type MessagePart = z.infer<typeof MessagePart>;
256
309
  /**
@@ -398,6 +451,30 @@ export declare const MessageWithParts: z.ZodObject<{
398
451
  input?: Record<string, any> | undefined;
399
452
  toolName?: string | undefined;
400
453
  metadata?: Record<string, any> | undefined;
454
+ }>, z.ZodObject<{
455
+ type: z.ZodLiteral<"image">;
456
+ id: z.ZodString;
457
+ messageId: z.ZodString;
458
+ sessionId: z.ZodString;
459
+ mimeType: z.ZodEnum<["image/png", "image/jpeg", "image/gif", "image/webp"]>;
460
+ data: z.ZodString;
461
+ filename: z.ZodOptional<z.ZodString>;
462
+ }, "strip", z.ZodTypeAny, {
463
+ type: "image";
464
+ id: string;
465
+ sessionId: string;
466
+ messageId: string;
467
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
468
+ data: string;
469
+ filename?: string | undefined;
470
+ }, {
471
+ type: "image";
472
+ id: string;
473
+ sessionId: string;
474
+ messageId: string;
475
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
476
+ data: string;
477
+ filename?: string | undefined;
401
478
  }>]>, "many">;
402
479
  }, "strip", z.ZodTypeAny, {
403
480
  info: {
@@ -439,6 +516,14 @@ export declare const MessageWithParts: z.ZodObject<{
439
516
  input?: Record<string, any> | undefined;
440
517
  toolName?: string | undefined;
441
518
  metadata?: Record<string, any> | undefined;
519
+ } | {
520
+ type: "image";
521
+ id: string;
522
+ sessionId: string;
523
+ messageId: string;
524
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
525
+ data: string;
526
+ filename?: string | undefined;
442
527
  })[];
443
528
  }, {
444
529
  info: {
@@ -480,6 +565,14 @@ export declare const MessageWithParts: z.ZodObject<{
480
565
  input?: Record<string, any> | undefined;
481
566
  toolName?: string | undefined;
482
567
  metadata?: Record<string, any> | undefined;
568
+ } | {
569
+ type: "image";
570
+ id: string;
571
+ sessionId: string;
572
+ messageId: string;
573
+ mimeType: "image/png" | "image/jpeg" | "image/gif" | "image/webp";
574
+ data: string;
575
+ filename?: string | undefined;
483
576
  })[];
484
577
  }>;
485
578
  export type MessageWithParts = z.infer<typeof MessageWithParts>;
@@ -6,13 +6,13 @@ export declare const ImageTool: Tool.Info<z.ZodObject<{
6
6
  directory: z.ZodOptional<z.ZodString>;
7
7
  aspectRatio: z.ZodOptional<z.ZodEnum<["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3", "5:4", "4:5", "21:9"]>>;
8
8
  }, "strip", z.ZodTypeAny, {
9
- prompt: string;
10
9
  filename: string;
10
+ prompt: string;
11
11
  directory?: string | undefined;
12
12
  aspectRatio?: "1:1" | "16:9" | "9:16" | "4:3" | "3:4" | "3:2" | "2:3" | "5:4" | "4:5" | "21:9" | undefined;
13
13
  }, {
14
- prompt: string;
15
14
  filename: string;
15
+ prompt: string;
16
16
  directory?: string | undefined;
17
17
  aspectRatio?: "1:1" | "16:9" | "9:16" | "4:3" | "3:4" | "3:2" | "2:3" | "5:4" | "4:5" | "21:9" | undefined;
18
18
  }>, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "portercode",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "description": "AI-powered coding assistant CLI",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
@@ -28,8 +28,13 @@
28
28
  "test": "bun test",
29
29
  "typecheck": "tsc --noEmit"
30
30
  },
31
- "keywords": ["cli", "ai", "coding-assistant", "llm"],
32
- "author": "Porter Metrics Inc. <alexis@portermetrics.com>",
31
+ "keywords": [
32
+ "cli",
33
+ "ai",
34
+ "coding-assistant",
35
+ "llm"
36
+ ],
37
+ "author": "Carlos Alexis Gomez Ruiz <alexisg.0207@gmail.com>",
33
38
  "license": "SEE LICENSE IN LICENSE",
34
39
  "devDependencies": {
35
40
  "@tsconfig/bun": "^1.0.7",
@@ -55,6 +60,7 @@
55
60
  "diff": "^7.0.0",
56
61
  "figures": "^6.0.1",
57
62
  "gray-matter": "^4.0.3",
63
+ "hono": "^4.11.3",
58
64
  "ignore": "^7.0.5",
59
65
  "ink": "^5.0.1",
60
66
  "jsonc-parser": "^3.3.1",