@betrue/openclaw-claude-code-plugin 1.0.0

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.
@@ -0,0 +1,33 @@
1
+ import { Type } from "@sinclair/typebox";
2
+ import { sessionManager, formatStats } from "../shared";
3
+
4
+ export function registerClaudeStatsTool(api: any): void {
5
+ api.registerTool(
6
+ {
7
+ name: "claude_stats",
8
+ description:
9
+ "Show Claude Code Plugin usage metrics: session counts by status, average duration, and notable sessions.",
10
+ parameters: Type.Object({}),
11
+ async execute(_id: string, _params: any) {
12
+ if (!sessionManager) {
13
+ return {
14
+ content: [
15
+ {
16
+ type: "text",
17
+ text: "Error: SessionManager not initialized. The claude-code service must be running.",
18
+ },
19
+ ],
20
+ };
21
+ }
22
+
23
+ const metrics = sessionManager.getMetrics();
24
+ const text = formatStats(metrics);
25
+
26
+ return {
27
+ content: [{ type: "text", text }],
28
+ };
29
+ },
30
+ },
31
+ { optional: false },
32
+ );
33
+ }
package/src/types.ts ADDED
@@ -0,0 +1,77 @@
1
+ // SDK types are imported from "@anthropic-ai/claude-agent-sdk"
2
+ // We define our own types for the plugin's internal state
3
+
4
+ export type SessionStatus = "starting" | "running" | "completed" | "failed" | "killed";
5
+
6
+ export type PermissionMode = "default" | "plan" | "acceptEdits" | "bypassPermissions";
7
+
8
+ export interface SessionConfig {
9
+ prompt: string;
10
+ workdir: string;
11
+ name?: string;
12
+ model?: string;
13
+ maxBudgetUsd: number;
14
+ foreground?: boolean;
15
+ systemPrompt?: string;
16
+ allowedTools?: string[];
17
+ originChannel?: string; // Channel that spawned this session (for background notifications)
18
+ permissionMode?: PermissionMode;
19
+
20
+ // Resume/fork support (Task 16)
21
+ resumeSessionId?: string; // Claude session ID to resume
22
+ forkSession?: boolean; // Fork instead of continuing when resuming
23
+
24
+ // Multi-turn support (Task 15)
25
+ multiTurn?: boolean; // If true, use AsyncIterable prompt for multi-turn conversations
26
+ }
27
+
28
+ export interface ClaudeSession {
29
+ id: string; // nanoid(8)
30
+ name: string; // human-readable kebab-case name
31
+ claudeSessionId?: string; // UUID from SDK init message
32
+
33
+ // Configuration
34
+ prompt: string;
35
+ workdir: string;
36
+ model?: string;
37
+ maxBudgetUsd: number;
38
+
39
+ // State
40
+ status: SessionStatus;
41
+ error?: string;
42
+
43
+ // Timing
44
+ startedAt: number;
45
+ completedAt?: number;
46
+
47
+ // Output
48
+ outputBuffer: string[]; // Last N lines of assistant text
49
+
50
+ // Result from SDK
51
+ result?: {
52
+ subtype: string;
53
+ duration_ms: number;
54
+ total_cost_usd: number;
55
+ num_turns: number;
56
+ result?: string;
57
+ is_error: boolean;
58
+ session_id: string;
59
+ };
60
+
61
+ // Cost tracking
62
+ costUsd: number;
63
+
64
+ // Foreground channels
65
+ foregroundChannels: Set<string>;
66
+ }
67
+
68
+ export interface PluginConfig {
69
+ maxSessions: number;
70
+ defaultBudgetUsd: number;
71
+ defaultModel?: string;
72
+ defaultWorkdir?: string;
73
+ idleTimeoutMinutes: number;
74
+ maxPersistedSessions: number;
75
+ fallbackChannel?: string;
76
+ permissionMode?: PermissionMode;
77
+ }