@lgcyaxi/oh-my-claude 1.0.1 → 1.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.
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/hooks/task-notification.ts
4
+ import { readFileSync, existsSync, writeFileSync, mkdirSync } from "node:fs";
5
+ import { join, dirname } from "node:path";
6
+ import { homedir } from "node:os";
7
+ var NOTIFIED_FILE_PATH = join(homedir(), ".claude", "oh-my-claude", "notified-tasks.json");
8
+ function loadNotifiedTasks() {
9
+ try {
10
+ if (!existsSync(NOTIFIED_FILE_PATH)) {
11
+ return new Set;
12
+ }
13
+ const content = readFileSync(NOTIFIED_FILE_PATH, "utf-8");
14
+ const data = JSON.parse(content);
15
+ const oneHourAgo = Date.now() - 60 * 60 * 1000;
16
+ const filtered = Object.entries(data).filter(([_, timestamp]) => timestamp > oneHourAgo).map(([id]) => id);
17
+ return new Set(filtered);
18
+ } catch {
19
+ return new Set;
20
+ }
21
+ }
22
+ function saveNotifiedTask(taskId) {
23
+ try {
24
+ const dir = dirname(NOTIFIED_FILE_PATH);
25
+ if (!existsSync(dir)) {
26
+ mkdirSync(dir, { recursive: true });
27
+ }
28
+ let data = {};
29
+ if (existsSync(NOTIFIED_FILE_PATH)) {
30
+ try {
31
+ data = JSON.parse(readFileSync(NOTIFIED_FILE_PATH, "utf-8"));
32
+ } catch {
33
+ data = {};
34
+ }
35
+ }
36
+ const oneHourAgo = Date.now() - 60 * 60 * 1000;
37
+ for (const [id, timestamp] of Object.entries(data)) {
38
+ if (timestamp < oneHourAgo) {
39
+ delete data[id];
40
+ }
41
+ }
42
+ data[taskId] = Date.now();
43
+ writeFileSync(NOTIFIED_FILE_PATH, JSON.stringify(data));
44
+ } catch {}
45
+ }
46
+ function formatDuration(ms) {
47
+ const seconds = Math.floor(ms / 1000);
48
+ if (seconds < 60) {
49
+ return `${seconds}s`;
50
+ }
51
+ const minutes = Math.floor(seconds / 60);
52
+ const remainingSeconds = seconds % 60;
53
+ return `${minutes}m ${remainingSeconds}s`;
54
+ }
55
+ async function main() {
56
+ let inputData = "";
57
+ try {
58
+ inputData = readFileSync(0, "utf-8");
59
+ } catch {
60
+ console.log(JSON.stringify({ decision: "approve" }));
61
+ return;
62
+ }
63
+ if (!inputData.trim()) {
64
+ console.log(JSON.stringify({ decision: "approve" }));
65
+ return;
66
+ }
67
+ let toolInput;
68
+ try {
69
+ toolInput = JSON.parse(inputData);
70
+ } catch {
71
+ console.log(JSON.stringify({ decision: "approve" }));
72
+ return;
73
+ }
74
+ if (!toolInput.tool?.includes("oh-my-claude-background")) {
75
+ console.log(JSON.stringify({ decision: "approve" }));
76
+ return;
77
+ }
78
+ const toolOutput = toolInput.tool_output;
79
+ if (!toolOutput) {
80
+ console.log(JSON.stringify({ decision: "approve" }));
81
+ return;
82
+ }
83
+ try {
84
+ const output = JSON.parse(toolOutput);
85
+ const notifiedTasks = loadNotifiedTasks();
86
+ const notifications = [];
87
+ if (output.status === "completed" && toolInput.tool?.includes("poll_task")) {
88
+ console.log(JSON.stringify({ decision: "approve" }));
89
+ return;
90
+ }
91
+ if (output.tasks && Array.isArray(output.tasks)) {
92
+ for (const task of output.tasks) {
93
+ if ((task.status === "completed" || task.status === "failed") && task.id && !notifiedTasks.has(task.id)) {
94
+ let durationStr = "";
95
+ if (task.created && task.completed) {
96
+ const created = new Date(task.created).getTime();
97
+ const completed = new Date(task.completed).getTime();
98
+ durationStr = ` (${formatDuration(completed - created)})`;
99
+ }
100
+ const statusIcon = task.status === "completed" ? "+" : "!";
101
+ const agentName = task.agent || "unknown";
102
+ notifications.push(`[${statusIcon}] ${agentName}: ${task.status}${durationStr}`);
103
+ saveNotifiedTask(task.id);
104
+ }
105
+ }
106
+ }
107
+ if (notifications.length > 0) {
108
+ const response = {
109
+ decision: "approve",
110
+ hookSpecificOutput: {
111
+ hookEventName: "PostToolUse",
112
+ additionalContext: `
113
+ [omc] ${notifications.join(" | ")}`
114
+ }
115
+ };
116
+ console.log(JSON.stringify(response));
117
+ return;
118
+ }
119
+ } catch {}
120
+ console.log(JSON.stringify({ decision: "approve" }));
121
+ }
122
+ main().catch(() => {
123
+ console.log(JSON.stringify({ decision: "approve" }));
124
+ });
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/hooks/task-tracker.ts
4
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
5
+ import { join, dirname } from "node:path";
6
+ import { homedir } from "node:os";
7
+ var STATUS_FILE_PATH = join(homedir(), ".claude", "oh-my-claude", "status.json");
8
+ var TASK_AGENTS_FILE = join(homedir(), ".claude", "oh-my-claude", "task-agents.json");
9
+ function loadTaskAgents() {
10
+ try {
11
+ if (!existsSync(TASK_AGENTS_FILE)) {
12
+ return { agents: [] };
13
+ }
14
+ const content = readFileSync(TASK_AGENTS_FILE, "utf-8");
15
+ return JSON.parse(content);
16
+ } catch {
17
+ return { agents: [] };
18
+ }
19
+ }
20
+ function saveTaskAgents(data) {
21
+ try {
22
+ const dir = dirname(TASK_AGENTS_FILE);
23
+ if (!existsSync(dir)) {
24
+ mkdirSync(dir, { recursive: true });
25
+ }
26
+ writeFileSync(TASK_AGENTS_FILE, JSON.stringify(data, null, 2));
27
+ } catch {}
28
+ }
29
+ function updateStatusFile() {
30
+ try {
31
+ let status = {
32
+ activeTasks: [],
33
+ providers: {},
34
+ updatedAt: new Date().toISOString()
35
+ };
36
+ if (existsSync(STATUS_FILE_PATH)) {
37
+ try {
38
+ status = JSON.parse(readFileSync(STATUS_FILE_PATH, "utf-8"));
39
+ } catch {}
40
+ }
41
+ const taskAgents = loadTaskAgents();
42
+ const taskAgentTasks = taskAgents.agents.map((agent) => ({
43
+ agent: `@${agent.type}`,
44
+ startedAt: agent.startedAt,
45
+ isTaskTool: true
46
+ }));
47
+ const thirtyMinutesAgo = Date.now() - 30 * 60 * 1000;
48
+ const activeTaskAgents = taskAgentTasks.filter((t) => t.startedAt > thirtyMinutesAgo);
49
+ const mcpTasks = (status.activeTasks || []).filter((t) => !t.isTaskTool);
50
+ status.activeTasks = [...mcpTasks, ...activeTaskAgents];
51
+ status.updatedAt = new Date().toISOString();
52
+ const dir = dirname(STATUS_FILE_PATH);
53
+ if (!existsSync(dir)) {
54
+ mkdirSync(dir, { recursive: true });
55
+ }
56
+ writeFileSync(STATUS_FILE_PATH, JSON.stringify(status, null, 2));
57
+ } catch {}
58
+ }
59
+ function generateId() {
60
+ return `task_${Date.now()}_${Math.random().toString(36).substring(2, 6)}`;
61
+ }
62
+ function getAgentDisplayName(subagentType) {
63
+ const mapping = {
64
+ Bash: "Bash",
65
+ Explore: "Scout",
66
+ Plan: "Planner",
67
+ "general-purpose": "General",
68
+ "claude-code-guide": "Guide"
69
+ };
70
+ return mapping[subagentType] || subagentType;
71
+ }
72
+ async function main() {
73
+ let inputData = "";
74
+ try {
75
+ inputData = readFileSync(0, "utf-8");
76
+ } catch {
77
+ console.log(JSON.stringify({ decision: "approve" }));
78
+ return;
79
+ }
80
+ if (!inputData.trim()) {
81
+ console.log(JSON.stringify({ decision: "approve" }));
82
+ return;
83
+ }
84
+ let toolInput;
85
+ try {
86
+ toolInput = JSON.parse(inputData);
87
+ } catch {
88
+ console.log(JSON.stringify({ decision: "approve" }));
89
+ return;
90
+ }
91
+ if (toolInput.tool !== "Task") {
92
+ console.log(JSON.stringify({ decision: "approve" }));
93
+ return;
94
+ }
95
+ const subagentType = toolInput.tool_input?.subagent_type || "unknown";
96
+ const description = toolInput.tool_input?.description || "";
97
+ const isPreToolUse = !toolInput.tool_output;
98
+ if (isPreToolUse) {
99
+ const taskAgents = loadTaskAgents();
100
+ const newAgent = {
101
+ id: generateId(),
102
+ type: getAgentDisplayName(subagentType),
103
+ description,
104
+ startedAt: Date.now()
105
+ };
106
+ taskAgents.agents.push(newAgent);
107
+ saveTaskAgents(taskAgents);
108
+ updateStatusFile();
109
+ const response = {
110
+ decision: "approve"
111
+ };
112
+ console.log(JSON.stringify(response));
113
+ } else {
114
+ const taskAgents = loadTaskAgents();
115
+ const displayName = getAgentDisplayName(subagentType);
116
+ const index = taskAgents.agents.findIndex((a) => a.type === displayName);
117
+ if (index !== -1) {
118
+ const removedArr = taskAgents.agents.splice(index, 1);
119
+ const removed = removedArr[0];
120
+ if (!removed) {
121
+ console.log(JSON.stringify({ decision: "approve" }));
122
+ return;
123
+ }
124
+ const duration = Math.floor((Date.now() - removed.startedAt) / 1000);
125
+ saveTaskAgents(taskAgents);
126
+ updateStatusFile();
127
+ const durationStr = duration < 60 ? `${duration}s` : `${Math.floor(duration / 60)}m`;
128
+ const response = {
129
+ decision: "approve",
130
+ hookSpecificOutput: {
131
+ hookEventName: "PostToolUse",
132
+ additionalContext: `
133
+ [@] ${displayName}: completed (${durationStr})`
134
+ }
135
+ };
136
+ console.log(JSON.stringify(response));
137
+ return;
138
+ }
139
+ console.log(JSON.stringify({ decision: "approve" }));
140
+ }
141
+ }
142
+ main().catch(() => {
143
+ console.log(JSON.stringify({ decision: "approve" }));
144
+ });