vibe-haptic 1.0.2 → 1.0.3
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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/dist/bin/haptic-hook.js +2 -2
- package/dist/bin/haptic.js +1 -1
- package/dist/chunk-cx3pfsgs.js +188 -0
- package/dist/chunk-cx3pfsgs.js.map +12 -0
- package/dist/chunk-swn5qjzx.js +26 -0
- package/dist/chunk-swn5qjzx.js.map +10 -0
- package/dist/chunk-zjqyb6rz.js +57 -0
- package/dist/chunk-zjqyb6rz.js.map +10 -0
- package/dist/claude/index.js +2 -2
- package/dist/index.js +2 -2
- package/dist/opencode/index.js +2 -2
- package/dist/src/config.d.ts.map +1 -1
- package/hooks/haptic-hook.js +239 -0
- package/hooks/hooks.json +2 -2
- package/package.json +2 -4
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
{
|
|
11
11
|
"name": "vibe-haptic",
|
|
12
12
|
"description": "Feel tactile feedback when tasks complete or when input is needed through your MacBook's Force Touch trackpad",
|
|
13
|
-
"version": "
|
|
13
|
+
"version": "1.0.3",
|
|
14
14
|
"author": {
|
|
15
15
|
"name": "Jeon Suyeol",
|
|
16
16
|
"url": "https://github.com/devxoul"
|
package/dist/bin/haptic-hook.js
CHANGED
package/dist/bin/haptic.js
CHANGED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// src/haptic.ts
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
// src/config.ts
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
var DEFAULT_CONFIG = {
|
|
10
|
+
patterns: {},
|
|
11
|
+
events: {
|
|
12
|
+
stop: "vibe",
|
|
13
|
+
prompt: "alert"
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
function getConfigPath(agent, scope) {
|
|
17
|
+
const home = homedir();
|
|
18
|
+
if (scope === "global") {
|
|
19
|
+
return agent === "claude" ? `${home}/.claude/vibe-haptic.json` : `${home}/.config/opencode/vibe-haptic.json`;
|
|
20
|
+
}
|
|
21
|
+
return agent === "claude" ? ".claude/vibe-haptic.json" : ".opencode/vibe-haptic.json";
|
|
22
|
+
}
|
|
23
|
+
function mergeConfig(base, override) {
|
|
24
|
+
return {
|
|
25
|
+
patterns: { ...base.patterns, ...override.patterns },
|
|
26
|
+
events: { ...base.events, ...override.events }
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function loadConfig(agent = "claude") {
|
|
30
|
+
let config = { ...DEFAULT_CONFIG };
|
|
31
|
+
const globalPath = getConfigPath(agent, "global");
|
|
32
|
+
if (existsSync(globalPath)) {
|
|
33
|
+
try {
|
|
34
|
+
const globalData = JSON.parse(readFileSync(globalPath, "utf-8"));
|
|
35
|
+
config = mergeConfig(config, globalData);
|
|
36
|
+
} catch {}
|
|
37
|
+
}
|
|
38
|
+
const localPath = getConfigPath(agent, "local");
|
|
39
|
+
if (existsSync(localPath)) {
|
|
40
|
+
try {
|
|
41
|
+
const localData = JSON.parse(readFileSync(localPath, "utf-8"));
|
|
42
|
+
config = mergeConfig(config, localData);
|
|
43
|
+
} catch {}
|
|
44
|
+
}
|
|
45
|
+
return config;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/patterns.ts
|
|
49
|
+
var DEFAULT_INTENSITY = 1;
|
|
50
|
+
var DEFAULT_PATTERNS = {
|
|
51
|
+
vibe: { beat: "6/0.8 3/1.0 6/1.0" },
|
|
52
|
+
alert: { beat: "6/0.5 6/1.0 6/0.5" },
|
|
53
|
+
dopamine: { beat: "6666666 5/1.0 4/1.0 3/1.0", intensity: 0.1 },
|
|
54
|
+
noise: { beat: "6543654365436543" }
|
|
55
|
+
};
|
|
56
|
+
function resolvePattern(nameOrBeat, patterns) {
|
|
57
|
+
const isInlineBeat = /^[3-6/.\s]+$/.test(nameOrBeat);
|
|
58
|
+
if (isInlineBeat) {
|
|
59
|
+
return { beat: nameOrBeat };
|
|
60
|
+
}
|
|
61
|
+
const userPattern = patterns?.[nameOrBeat];
|
|
62
|
+
if (userPattern) {
|
|
63
|
+
if (typeof userPattern === "string") {
|
|
64
|
+
return { beat: userPattern };
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
beat: userPattern.beat,
|
|
68
|
+
intensity: userPattern.intensity
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const defaultPattern = DEFAULT_PATTERNS[nameOrBeat];
|
|
72
|
+
if (defaultPattern) {
|
|
73
|
+
return {
|
|
74
|
+
beat: defaultPattern.beat,
|
|
75
|
+
intensity: defaultPattern.intensity
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/haptic.ts
|
|
82
|
+
var PAUSE_DELAY_MS = 100;
|
|
83
|
+
function parseBeat(beat, defaultIntensity) {
|
|
84
|
+
const tokens = [];
|
|
85
|
+
let i = 0;
|
|
86
|
+
while (i < beat.length) {
|
|
87
|
+
const char = beat[i];
|
|
88
|
+
if (char === " ") {
|
|
89
|
+
let pauseCount = 0;
|
|
90
|
+
while (i < beat.length && beat[i] === " ") {
|
|
91
|
+
pauseCount++;
|
|
92
|
+
i++;
|
|
93
|
+
}
|
|
94
|
+
tokens.push({ type: "pause", pauseCount });
|
|
95
|
+
} else if (char >= "3" && char <= "6") {
|
|
96
|
+
const actuation = Number(char);
|
|
97
|
+
i++;
|
|
98
|
+
if (i < beat.length && beat[i] === "/") {
|
|
99
|
+
i++;
|
|
100
|
+
let intensityStr = "";
|
|
101
|
+
while (i < beat.length && beat[i] !== " ") {
|
|
102
|
+
intensityStr += beat[i];
|
|
103
|
+
i++;
|
|
104
|
+
}
|
|
105
|
+
const intensity = intensityStr ? Math.min(2, Math.max(0, parseFloat(intensityStr))) : defaultIntensity;
|
|
106
|
+
tokens.push({ type: "tap", actuation, intensity });
|
|
107
|
+
} else {
|
|
108
|
+
tokens.push({ type: "tap", actuation, intensity: defaultIntensity });
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
i++;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return tokens;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
class HapticEngine {
|
|
118
|
+
config;
|
|
119
|
+
nativeModule = null;
|
|
120
|
+
constructor(config, options) {
|
|
121
|
+
this.config = config;
|
|
122
|
+
if (options?.nativeModule !== undefined) {
|
|
123
|
+
this.nativeModule = options.nativeModule;
|
|
124
|
+
} else {
|
|
125
|
+
this.loadNativeModule();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
loadNativeModule() {
|
|
129
|
+
if (process.platform !== "darwin") {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
134
|
+
const nativePath = join(currentDir, "..", "native", "vibe-haptic-native.node");
|
|
135
|
+
const require2 = createRequire(import.meta.url);
|
|
136
|
+
this.nativeModule = require2(nativePath);
|
|
137
|
+
} catch {}
|
|
138
|
+
}
|
|
139
|
+
playBeat(pattern) {
|
|
140
|
+
return new Promise((resolve) => {
|
|
141
|
+
if (!this.nativeModule) {
|
|
142
|
+
resolve();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const { beat, intensity } = pattern;
|
|
146
|
+
const tokens = parseBeat(beat, intensity ?? DEFAULT_INTENSITY);
|
|
147
|
+
const module = this.nativeModule;
|
|
148
|
+
let i = 0;
|
|
149
|
+
const playNext = () => {
|
|
150
|
+
if (i >= tokens.length) {
|
|
151
|
+
resolve();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const token = tokens[i];
|
|
155
|
+
i++;
|
|
156
|
+
if (token.type === "pause") {
|
|
157
|
+
setTimeout(playNext, (token.pauseCount ?? 1) * PAUSE_DELAY_MS);
|
|
158
|
+
} else {
|
|
159
|
+
module.actuate(token.actuation, token.intensity);
|
|
160
|
+
playNext();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
playNext();
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
trigger(patternName) {
|
|
167
|
+
const pattern = resolvePattern(patternName, this.config.patterns);
|
|
168
|
+
if (pattern) {
|
|
169
|
+
return this.playBeat(pattern);
|
|
170
|
+
}
|
|
171
|
+
return Promise.resolve();
|
|
172
|
+
}
|
|
173
|
+
triggerForEvent(event) {
|
|
174
|
+
const patternName = this.config.events?.[event];
|
|
175
|
+
if (patternName) {
|
|
176
|
+
return this.trigger(patternName);
|
|
177
|
+
}
|
|
178
|
+
return Promise.resolve();
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function createHapticEngine(agent) {
|
|
182
|
+
return new HapticEngine(loadConfig(agent));
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export { createHapticEngine };
|
|
186
|
+
|
|
187
|
+
//# debugId=C38CA7FB2803AE3864756E2164756E21
|
|
188
|
+
//# sourceMappingURL=chunk-cx3pfsgs.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/haptic.ts", "../src/config.ts", "../src/patterns.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { createRequire } from 'node:module'\nimport { dirname, join } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { loadConfig } from './config'\nimport { DEFAULT_INTENSITY, resolvePattern } from './patterns'\nimport type { HapticConfig, HapticEvent, ResolvedPattern } from './types'\n\nconst PAUSE_DELAY_MS = 100\n\nexport interface BeatToken {\n type: 'tap' | 'pause'\n actuation?: number\n intensity?: number\n pauseCount?: number\n}\nexport function parseBeat(beat: string, defaultIntensity: number): BeatToken[] {\n const tokens: BeatToken[] = []\n let i = 0\n\n while (i < beat.length) {\n const char = beat[i]\n\n if (char === ' ') {\n let pauseCount = 0\n while (i < beat.length && beat[i] === ' ') {\n pauseCount++\n i++\n }\n tokens.push({ type: 'pause', pauseCount })\n } else if (char >= '3' && char <= '6') {\n const actuation = Number(char)\n i++\n\n if (i < beat.length && beat[i] === '/') {\n i++\n let intensityStr = ''\n while (i < beat.length && beat[i] !== ' ') {\n intensityStr += beat[i]\n i++\n }\n const intensity = intensityStr ? Math.min(2, Math.max(0, parseFloat(intensityStr))) : defaultIntensity\n tokens.push({ type: 'tap', actuation, intensity })\n } else {\n tokens.push({ type: 'tap', actuation, intensity: defaultIntensity })\n }\n } else {\n i++\n }\n }\n\n return tokens\n}\n\nexport type NativeModule = { actuate: (actuation: number, intensity: number) => void }\n\nexport interface HapticEngineOptions {\n nativeModule?: NativeModule | null\n}\n\nexport class HapticEngine {\n private config: HapticConfig\n private nativeModule: NativeModule | null = null\n\n constructor(config: HapticConfig, options?: HapticEngineOptions) {\n this.config = config\n if (options?.nativeModule !== undefined) {\n this.nativeModule = options.nativeModule\n } else {\n this.loadNativeModule()\n }\n }\n\n private loadNativeModule() {\n if (process.platform !== 'darwin') {\n return\n }\n\n try {\n // Use import.meta.url to resolve path at runtime, not build time\n const currentDir = dirname(fileURLToPath(import.meta.url))\n const nativePath = join(currentDir, '..', 'native', 'vibe-haptic-native.node')\n const require = createRequire(import.meta.url)\n this.nativeModule = require(nativePath)\n } catch {}\n }\n\n playBeat(pattern: ResolvedPattern): Promise<void> {\n return new Promise((resolve) => {\n if (!this.nativeModule) {\n resolve()\n return\n }\n\n const { beat, intensity } = pattern\n const tokens = parseBeat(beat, intensity ?? DEFAULT_INTENSITY)\n const module = this.nativeModule\n let i = 0\n\n const playNext = () => {\n if (i >= tokens.length) {\n resolve()\n return\n }\n\n const token = tokens[i]\n i++\n\n if (token.type === 'pause') {\n setTimeout(playNext, (token.pauseCount ?? 1) * PAUSE_DELAY_MS)\n } else {\n module.actuate(token.actuation!, token.intensity!)\n playNext()\n }\n }\n\n playNext()\n })\n }\n\n trigger(patternName: string): Promise<void> {\n const pattern = resolvePattern(patternName, this.config.patterns)\n\n if (pattern) {\n return this.playBeat(pattern)\n }\n return Promise.resolve()\n }\n\n triggerForEvent(event: HapticEvent): Promise<void> {\n const patternName = this.config.events?.[event]\n if (patternName) {\n return this.trigger(patternName)\n }\n return Promise.resolve()\n }\n}\n\nexport function createHapticEngine(agent?: 'claude' | 'opencode'): HapticEngine {\n return new HapticEngine(loadConfig(agent))\n}\n",
|
|
6
|
+
"import { existsSync, readFileSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport type { HapticConfig, PatternConfig } from './types'\n\nexport const DEFAULT_CONFIG: HapticConfig = {\n patterns: {},\n events: {\n stop: 'vibe',\n prompt: 'alert',\n },\n}\n\nexport function getConfigPath(agent: 'claude' | 'opencode', scope: 'local' | 'global'): string {\n const home = homedir()\n\n if (scope === 'global') {\n return agent === 'claude' ? `${home}/.claude/vibe-haptic.json` : `${home}/.config/opencode/vibe-haptic.json`\n }\n return agent === 'claude' ? '.claude/vibe-haptic.json' : '.opencode/vibe-haptic.json'\n}\n\nfunction mergeConfig(base: HapticConfig, override: Partial<HapticConfig>): HapticConfig {\n return {\n patterns: { ...base.patterns, ...(override.patterns as Record<string, string | PatternConfig>) },\n events: { ...base.events, ...override.events },\n }\n}\n\nexport function loadConfig(agent: 'claude' | 'opencode' = 'claude'): HapticConfig {\n let config: HapticConfig = { ...DEFAULT_CONFIG }\n\n const globalPath = getConfigPath(agent, 'global')\n if (existsSync(globalPath)) {\n try {\n const globalData = JSON.parse(readFileSync(globalPath, 'utf-8'))\n config = mergeConfig(config, globalData)\n } catch {}\n }\n\n const localPath = getConfigPath(agent, 'local')\n if (existsSync(localPath)) {\n try {\n const localData = JSON.parse(readFileSync(localPath, 'utf-8'))\n config = mergeConfig(config, localData)\n } catch {}\n }\n\n return config\n}\n",
|
|
7
|
+
"import type { PatternConfig, ResolvedPattern } from './types'\n\nexport const DEFAULT_INTENSITY = 1.0\n\nexport const DEFAULT_PATTERNS: Record<string, PatternConfig> = {\n vibe: { beat: '6/0.8 3/1.0 6/1.0' },\n alert: { beat: '6/0.5 6/1.0 6/0.5' },\n dopamine: { beat: '6666666 5/1.0 4/1.0 3/1.0', intensity: 0.1 },\n noise: { beat: '6543654365436543' },\n}\n\nexport function resolvePattern(\n nameOrBeat: string,\n patterns: Record<string, string | PatternConfig> | undefined,\n): ResolvedPattern | null {\n const isInlineBeat = /^[3-6/.\\s]+$/.test(nameOrBeat)\n if (isInlineBeat) {\n return { beat: nameOrBeat }\n }\n\n const userPattern = patterns?.[nameOrBeat]\n if (userPattern) {\n if (typeof userPattern === 'string') {\n return { beat: userPattern }\n }\n return {\n beat: userPattern.beat,\n intensity: userPattern.intensity,\n }\n }\n\n const defaultPattern = DEFAULT_PATTERNS[nameOrBeat]\n if (defaultPattern) {\n return {\n beat: defaultPattern.beat,\n intensity: defaultPattern.intensity,\n }\n }\n\n return null\n}\n"
|
|
8
|
+
],
|
|
9
|
+
"mappings": ";AAAA;AACA;AACA;;;ACFA;AACA;AAGO,IAAM,iBAA+B;AAAA,EAC1C,UAAU,CAAC;AAAA,EACX,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,QAAQ;AAAA,EACV;AACF;AAEO,SAAS,aAAa,CAAC,OAA8B,OAAmC;AAAA,EAC7F,MAAM,OAAO,QAAQ;AAAA,EAErB,IAAI,UAAU,UAAU;AAAA,IACtB,OAAO,UAAU,WAAW,GAAG,kCAAkC,GAAG;AAAA,EACtE;AAAA,EACA,OAAO,UAAU,WAAW,6BAA6B;AAAA;AAG3D,SAAS,WAAW,CAAC,MAAoB,UAA+C;AAAA,EACtF,OAAO;AAAA,IACL,UAAU,KAAK,KAAK,aAAc,SAAS,SAAoD;AAAA,IAC/F,QAAQ,KAAK,KAAK,WAAW,SAAS,OAAO;AAAA,EAC/C;AAAA;AAGK,SAAS,UAAU,CAAC,QAA+B,UAAwB;AAAA,EAChF,IAAI,S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AGzB,eAAe,CAAC,OAAmC;AAAA,IACjD,MAAM,cAAc,KAAK,OAAO,SAAS;AAAA,IACzC,IAAI,aAAa;AAAA,MACf,OAAO,KAAK,QAAQ,WAAW;AAAA,IACjC;AAAA,IACA,OAAO,QAAQ,QAAQ;AAAA;AAE3B;AAEO,SAAS,kBAAkB,CAAC,OAA6C;AAAA,EAC9E,OAAO,IAAI,aAAa,WAAW,KAAK,CAAC;AAAA;",
|
|
10
|
+
"debugId": "C38CA7FB2803AE3864756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHapticEngine
|
|
3
|
+
} from "./chunk-cx3pfsgs.js";
|
|
4
|
+
|
|
5
|
+
// src/opencode/plugin.ts
|
|
6
|
+
var vibeHapticPlugin = async (_ctx) => {
|
|
7
|
+
const engine = createHapticEngine("opencode");
|
|
8
|
+
return {
|
|
9
|
+
event: async (input) => {
|
|
10
|
+
const { event } = input;
|
|
11
|
+
if (event.type === "session.status") {
|
|
12
|
+
const statusObj = event.properties.status;
|
|
13
|
+
if (statusObj.type === "idle") {
|
|
14
|
+
engine.triggerForEvent("stop");
|
|
15
|
+
}
|
|
16
|
+
} else if (event.type === "permission.updated" || event.type === "question.asked") {
|
|
17
|
+
engine.triggerForEvent("prompt");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { vibeHapticPlugin };
|
|
24
|
+
|
|
25
|
+
//# debugId=893E3FE8395299E564756E2164756E21
|
|
26
|
+
//# sourceMappingURL=chunk-swn5qjzx.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/opencode/plugin.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { createHapticEngine } from '../haptic'\n\ntype SessionStatusType = 'idle' | 'busy' | 'retry'\n\ntype SessionStatusEvent = {\n type: 'session.status'\n properties: { sessionID: string; status: { type: SessionStatusType } }\n}\n\ntype PermissionUpdatedEvent = {\n type: 'permission.updated'\n properties: Record<string, unknown>\n}\n\ntype OpenCodeEvent = SessionStatusEvent | PermissionUpdatedEvent | { type: string; properties?: unknown }\n\ntype PluginInput = {\n client: unknown\n project: unknown\n directory: string\n worktree: string\n serverUrl: URL\n $: unknown\n}\n\nexport const vibeHapticPlugin = async (_ctx: PluginInput) => {\n const engine = createHapticEngine('opencode')\n\n return {\n event: async (input: { event: OpenCodeEvent }): Promise<void> => {\n const { event } = input\n\n if (event.type === 'session.status') {\n const statusObj = (event as SessionStatusEvent).properties.status\n if (statusObj.type === 'idle') {\n engine.triggerForEvent('stop')\n }\n } else if (event.type === 'permission.updated' || event.type === 'question.asked') {\n engine.triggerForEvent('prompt')\n }\n },\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;AAyBO,IAAM,mBAAmB,OAAO,SAAsB;AAAA,EAC3D,MAAM,SAAS,mBAAmB,UAAU;AAAA,EAE5C,OAAO;AAAA,IACL,OAAO,OAAO,UAAmD;AAAA,MAC/D,QAAQ,UAAU;AAAA,MAElB,IAAI,MAAM,SAAS,kBAAkB;AAAA,QACnC,MAAM,YAAa,MAA6B,WAAW;AAAA,QAC3D,IAAI,UAAU,SAAS,QAAQ;AAAA,UAC7B,OAAO,gBAAgB,MAAM;AAAA,QAC/B;AAAA,MACF,EAAO,SAAI,MAAM,SAAS,wBAAwB,MAAM,SAAS,kBAAkB;AAAA,QACjF,OAAO,gBAAgB,QAAQ;AAAA,MACjC;AAAA;AAAA,EAEJ;AAAA;",
|
|
8
|
+
"debugId": "893E3FE8395299E564756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHapticEngine
|
|
3
|
+
} from "./chunk-cx3pfsgs.js";
|
|
4
|
+
|
|
5
|
+
// src/claude/hook.ts
|
|
6
|
+
import { appendFileSync } from "node:fs";
|
|
7
|
+
import { homedir } from "node:os";
|
|
8
|
+
var DEBUG = process.env.VIBE_HAPTIC_DEBUG === "1";
|
|
9
|
+
function debug(message, data) {
|
|
10
|
+
if (!DEBUG)
|
|
11
|
+
return;
|
|
12
|
+
const logPath = `${homedir()}/.vibe-haptic-debug.log`;
|
|
13
|
+
const timestamp = new Date().toISOString();
|
|
14
|
+
const logLine = data ? `[${timestamp}] ${message}: ${JSON.stringify(data, null, 2)}
|
|
15
|
+
` : `[${timestamp}] ${message}
|
|
16
|
+
`;
|
|
17
|
+
appendFileSync(logPath, logLine);
|
|
18
|
+
}
|
|
19
|
+
async function handleHookEvent(input) {
|
|
20
|
+
debug("handleHookEvent called", input);
|
|
21
|
+
const engine = createHapticEngine("claude");
|
|
22
|
+
if (input.hook_event_name === "Stop") {
|
|
23
|
+
debug("Triggering stop event");
|
|
24
|
+
await engine.triggerForEvent("stop");
|
|
25
|
+
} else if (input.hook_event_name === "Notification") {
|
|
26
|
+
debug("Triggering prompt event for notification", { notification_type: input.notification_type });
|
|
27
|
+
await engine.triggerForEvent("prompt");
|
|
28
|
+
} else {
|
|
29
|
+
debug("Unknown hook event", { hook_event_name: input.hook_event_name });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function readStdin() {
|
|
33
|
+
if (typeof Bun !== "undefined") {
|
|
34
|
+
return Bun.stdin.text();
|
|
35
|
+
}
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const chunks = [];
|
|
38
|
+
process.stdin.on("data", (chunk) => chunks.push(chunk));
|
|
39
|
+
process.stdin.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")));
|
|
40
|
+
process.stdin.on("error", reject);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async function main() {
|
|
44
|
+
try {
|
|
45
|
+
const input = await readStdin();
|
|
46
|
+
const hookInput = JSON.parse(input);
|
|
47
|
+
await handleHookEvent(hookInput);
|
|
48
|
+
process.exit(0);
|
|
49
|
+
} catch {
|
|
50
|
+
process.exit(0);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { handleHookEvent, main };
|
|
55
|
+
|
|
56
|
+
//# debugId=EFA5EE4A014C749B64756E2164756E21
|
|
57
|
+
//# sourceMappingURL=chunk-zjqyb6rz.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/claude/hook.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { appendFileSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { createHapticEngine } from '../haptic'\n\nconst DEBUG = process.env.VIBE_HAPTIC_DEBUG === '1'\n\nfunction debug(message: string, data?: unknown) {\n if (!DEBUG) return\n const logPath = `${homedir()}/.vibe-haptic-debug.log`\n const timestamp = new Date().toISOString()\n const logLine = data ? `[${timestamp}] ${message}: ${JSON.stringify(data, null, 2)}\\n` : `[${timestamp}] ${message}\\n`\n appendFileSync(logPath, logLine)\n}\n\ninterface ClaudeHookInput {\n session_id: string\n transcript_path: string\n cwd: string\n hook_event_name: string\n notification_type?: string\n}\n\nexport async function handleHookEvent(input: ClaudeHookInput): Promise<void> {\n debug('handleHookEvent called', input)\n\n const engine = createHapticEngine('claude')\n\n if (input.hook_event_name === 'Stop') {\n debug('Triggering stop event')\n await engine.triggerForEvent('stop')\n } else if (input.hook_event_name === 'Notification') {\n debug('Triggering prompt event for notification', { notification_type: input.notification_type })\n await engine.triggerForEvent('prompt')\n } else {\n debug('Unknown hook event', { hook_event_name: input.hook_event_name })\n }\n}\n\nasync function readStdin(): Promise<string> {\n if (typeof Bun !== 'undefined') {\n return Bun.stdin.text()\n }\n\n return new Promise((resolve, reject) => {\n const chunks: Uint8Array[] = []\n process.stdin.on('data', (chunk: Uint8Array) => chunks.push(chunk))\n process.stdin.on('end', () => resolve(Buffer.concat(chunks).toString('utf-8')))\n process.stdin.on('error', reject)\n })\n}\n\nexport async function main() {\n try {\n const input = await readStdin()\n const hookInput = JSON.parse(input) as ClaudeHookInput\n await handleHookEvent(hookInput)\n process.exit(0)\n } catch {\n process.exit(0)\n }\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": ";;;;;AAAA;AACA;AAGA,IAAM,QAAQ,QAAQ,IAAI,sBAAsB;AAEhD,SAAS,KAAK,CAAC,SAAiB,MAAgB;AAAA,EAC9C,IAAI,CAAC;AAAA,IAAO;AAAA,EACZ,MAAM,UAAU,GAAG,QAAQ;AAAA,EAC3B,MAAM,YAAY,IAAI,KAAK,EAAE,YAAY;AAAA,EACzC,MAAM,UAAU,OAAO,IAAI,cAAc,YAAY,KAAK,UAAU,MAAM,MAAM,CAAC;AAAA,IAAQ,IAAI,cAAc;AAAA;AAAA,EAC3G,eAAe,SAAS,OAAO;AAAA;AAWjC,eAAsB,eAAe,CAAC,OAAuC;AAAA,EAC3E,MAAM,0BAA0B,KAAK;AAAA,EAErC,MAAM,SAAS,mBAAmB,QAAQ;AAAA,EAE1C,IAAI,MAAM,oBAAoB,QAAQ;AAAA,IACpC,MAAM,uBAAuB;AAAA,IAC7B,MAAM,OAAO,gBAAgB,MAAM;AAAA,EACrC,EAAO,SAAI,MAAM,oBAAoB,gBAAgB;AAAA,IACnD,MAAM,4CAA4C,EAAE,mBAAmB,MAAM,kBAAkB,CAAC;AAAA,IAChG,MAAM,OAAO,gBAAgB,QAAQ;AAAA,EACvC,EAAO;AAAA,IACL,MAAM,sBAAsB,EAAE,iBAAiB,MAAM,gBAAgB,CAAC;AAAA;AAAA;AAI1E,eAAe,SAAS,GAAoB;AAAA,EAC1C,IAAI,OAAO,QAAQ,aAAa;AAAA,IAC9B,OAAO,IAAI,MAAM,KAAK;AAAA,EACxB;AAAA,EAEA,OAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AAAA,IACtC,MAAM,SAAuB,CAAC;AAAA,IAC9B,QAAQ,MAAM,GAAG,QAAQ,CAAC,UAAsB,OAAO,KAAK,KAAK,CAAC;AAAA,IAClE,QAAQ,MAAM,GAAG,OAAO,MAAM,QAAQ,OAAO,OAAO,MAAM,EAAE,SAAS,OAAO,CAAC,CAAC;AAAA,IAC9E,QAAQ,MAAM,GAAG,SAAS,MAAM;AAAA,GACjC;AAAA;AAGH,eAAsB,IAAI,GAAG;AAAA,EAC3B,IAAI;AAAA,IACF,MAAM,QAAQ,MAAM,UAAU;AAAA,IAC9B,MAAM,YAAY,KAAK,MAAM,KAAK;AAAA,IAClC,MAAM,gBAAgB,SAAS;AAAA,IAC/B,QAAQ,KAAK,CAAC;AAAA,IACd,MAAM;AAAA,IACN,QAAQ,KAAK,CAAC;AAAA;AAAA;",
|
|
8
|
+
"debugId": "EFA5EE4A014C749B64756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/dist/claude/index.js
CHANGED
package/dist/index.js
CHANGED
package/dist/opencode/index.js
CHANGED
package/dist/src/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,SAAS,CAAA;AAE1D,eAAO,MAAM,cAAc,EAAE,YAM5B,CAAA;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,EAAE,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAO7F;AASD,wBAAgB,UAAU,CAAC,KAAK,GAAE,QAAQ,GAAG,UAAqB,GAAG,YAAY,CAoBhF"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/claude/hook.ts
|
|
4
|
+
import { appendFileSync } from "node:fs";
|
|
5
|
+
import { homedir as homedir2 } from "node:os";
|
|
6
|
+
|
|
7
|
+
// src/haptic.ts
|
|
8
|
+
import { createRequire } from "node:module";
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
// src/config.ts
|
|
13
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
var DEFAULT_CONFIG = {
|
|
16
|
+
patterns: {},
|
|
17
|
+
events: {
|
|
18
|
+
stop: "vibe",
|
|
19
|
+
prompt: "alert"
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
function getConfigPath(agent, scope) {
|
|
23
|
+
const home = homedir();
|
|
24
|
+
if (scope === "global") {
|
|
25
|
+
return agent === "claude" ? `${home}/.claude/vibe-haptic.json` : `${home}/.config/opencode/vibe-haptic.json`;
|
|
26
|
+
}
|
|
27
|
+
return agent === "claude" ? ".claude/vibe-haptic.json" : ".opencode/vibe-haptic.json";
|
|
28
|
+
}
|
|
29
|
+
function mergeConfig(base, override) {
|
|
30
|
+
return {
|
|
31
|
+
patterns: { ...base.patterns, ...override.patterns },
|
|
32
|
+
events: { ...base.events, ...override.events }
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function loadConfig(agent = "claude") {
|
|
36
|
+
let config = { ...DEFAULT_CONFIG };
|
|
37
|
+
const globalPath = getConfigPath(agent, "global");
|
|
38
|
+
if (existsSync(globalPath)) {
|
|
39
|
+
try {
|
|
40
|
+
const globalData = JSON.parse(readFileSync(globalPath, "utf-8"));
|
|
41
|
+
config = mergeConfig(config, globalData);
|
|
42
|
+
} catch {}
|
|
43
|
+
}
|
|
44
|
+
const localPath = getConfigPath(agent, "local");
|
|
45
|
+
if (existsSync(localPath)) {
|
|
46
|
+
try {
|
|
47
|
+
const localData = JSON.parse(readFileSync(localPath, "utf-8"));
|
|
48
|
+
config = mergeConfig(config, localData);
|
|
49
|
+
} catch {}
|
|
50
|
+
}
|
|
51
|
+
return config;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/patterns.ts
|
|
55
|
+
var DEFAULT_INTENSITY = 1;
|
|
56
|
+
var DEFAULT_PATTERNS = {
|
|
57
|
+
vibe: { beat: "6/0.8 3/1.0 6/1.0" },
|
|
58
|
+
alert: { beat: "6/0.5 6/1.0 6/0.5" },
|
|
59
|
+
dopamine: { beat: "6666666 5/1.0 4/1.0 3/1.0", intensity: 0.1 },
|
|
60
|
+
noise: { beat: "6543654365436543" }
|
|
61
|
+
};
|
|
62
|
+
function resolvePattern(nameOrBeat, patterns) {
|
|
63
|
+
const isInlineBeat = /^[3-6/.\s]+$/.test(nameOrBeat);
|
|
64
|
+
if (isInlineBeat) {
|
|
65
|
+
return { beat: nameOrBeat };
|
|
66
|
+
}
|
|
67
|
+
const userPattern = patterns?.[nameOrBeat];
|
|
68
|
+
if (userPattern) {
|
|
69
|
+
if (typeof userPattern === "string") {
|
|
70
|
+
return { beat: userPattern };
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
beat: userPattern.beat,
|
|
74
|
+
intensity: userPattern.intensity
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const defaultPattern = DEFAULT_PATTERNS[nameOrBeat];
|
|
78
|
+
if (defaultPattern) {
|
|
79
|
+
return {
|
|
80
|
+
beat: defaultPattern.beat,
|
|
81
|
+
intensity: defaultPattern.intensity
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/haptic.ts
|
|
88
|
+
var PAUSE_DELAY_MS = 100;
|
|
89
|
+
function parseBeat(beat, defaultIntensity) {
|
|
90
|
+
const tokens = [];
|
|
91
|
+
let i = 0;
|
|
92
|
+
while (i < beat.length) {
|
|
93
|
+
const char = beat[i];
|
|
94
|
+
if (char === " ") {
|
|
95
|
+
let pauseCount = 0;
|
|
96
|
+
while (i < beat.length && beat[i] === " ") {
|
|
97
|
+
pauseCount++;
|
|
98
|
+
i++;
|
|
99
|
+
}
|
|
100
|
+
tokens.push({ type: "pause", pauseCount });
|
|
101
|
+
} else if (char >= "3" && char <= "6") {
|
|
102
|
+
const actuation = Number(char);
|
|
103
|
+
i++;
|
|
104
|
+
if (i < beat.length && beat[i] === "/") {
|
|
105
|
+
i++;
|
|
106
|
+
let intensityStr = "";
|
|
107
|
+
while (i < beat.length && beat[i] !== " ") {
|
|
108
|
+
intensityStr += beat[i];
|
|
109
|
+
i++;
|
|
110
|
+
}
|
|
111
|
+
const intensity = intensityStr ? Math.min(2, Math.max(0, parseFloat(intensityStr))) : defaultIntensity;
|
|
112
|
+
tokens.push({ type: "tap", actuation, intensity });
|
|
113
|
+
} else {
|
|
114
|
+
tokens.push({ type: "tap", actuation, intensity: defaultIntensity });
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
i++;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return tokens;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
class HapticEngine {
|
|
124
|
+
config;
|
|
125
|
+
nativeModule = null;
|
|
126
|
+
constructor(config, options) {
|
|
127
|
+
this.config = config;
|
|
128
|
+
if (options?.nativeModule !== undefined) {
|
|
129
|
+
this.nativeModule = options.nativeModule;
|
|
130
|
+
} else {
|
|
131
|
+
this.loadNativeModule();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
loadNativeModule() {
|
|
135
|
+
if (process.platform !== "darwin") {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
try {
|
|
139
|
+
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
140
|
+
const nativePath = join(currentDir, "..", "native", "vibe-haptic-native.node");
|
|
141
|
+
const require2 = createRequire(import.meta.url);
|
|
142
|
+
this.nativeModule = require2(nativePath);
|
|
143
|
+
} catch {}
|
|
144
|
+
}
|
|
145
|
+
playBeat(pattern) {
|
|
146
|
+
return new Promise((resolve) => {
|
|
147
|
+
if (!this.nativeModule) {
|
|
148
|
+
resolve();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const { beat, intensity } = pattern;
|
|
152
|
+
const tokens = parseBeat(beat, intensity ?? DEFAULT_INTENSITY);
|
|
153
|
+
const module = this.nativeModule;
|
|
154
|
+
let i = 0;
|
|
155
|
+
const playNext = () => {
|
|
156
|
+
if (i >= tokens.length) {
|
|
157
|
+
resolve();
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const token = tokens[i];
|
|
161
|
+
i++;
|
|
162
|
+
if (token.type === "pause") {
|
|
163
|
+
setTimeout(playNext, (token.pauseCount ?? 1) * PAUSE_DELAY_MS);
|
|
164
|
+
} else {
|
|
165
|
+
module.actuate(token.actuation, token.intensity);
|
|
166
|
+
playNext();
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
playNext();
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
trigger(patternName) {
|
|
173
|
+
const pattern = resolvePattern(patternName, this.config.patterns);
|
|
174
|
+
if (pattern) {
|
|
175
|
+
return this.playBeat(pattern);
|
|
176
|
+
}
|
|
177
|
+
return Promise.resolve();
|
|
178
|
+
}
|
|
179
|
+
triggerForEvent(event) {
|
|
180
|
+
const patternName = this.config.events?.[event];
|
|
181
|
+
if (patternName) {
|
|
182
|
+
return this.trigger(patternName);
|
|
183
|
+
}
|
|
184
|
+
return Promise.resolve();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function createHapticEngine(agent) {
|
|
188
|
+
return new HapticEngine(loadConfig(agent));
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// src/claude/hook.ts
|
|
192
|
+
var DEBUG = process.env.VIBE_HAPTIC_DEBUG === "1";
|
|
193
|
+
function debug(message, data) {
|
|
194
|
+
if (!DEBUG)
|
|
195
|
+
return;
|
|
196
|
+
const logPath = `${homedir2()}/.vibe-haptic-debug.log`;
|
|
197
|
+
const timestamp = new Date().toISOString();
|
|
198
|
+
const logLine = data ? `[${timestamp}] ${message}: ${JSON.stringify(data, null, 2)}
|
|
199
|
+
` : `[${timestamp}] ${message}
|
|
200
|
+
`;
|
|
201
|
+
appendFileSync(logPath, logLine);
|
|
202
|
+
}
|
|
203
|
+
async function handleHookEvent(input) {
|
|
204
|
+
debug("handleHookEvent called", input);
|
|
205
|
+
const engine = createHapticEngine("claude");
|
|
206
|
+
if (input.hook_event_name === "Stop") {
|
|
207
|
+
debug("Triggering stop event");
|
|
208
|
+
await engine.triggerForEvent("stop");
|
|
209
|
+
} else if (input.hook_event_name === "Notification") {
|
|
210
|
+
debug("Triggering prompt event for notification", { notification_type: input.notification_type });
|
|
211
|
+
await engine.triggerForEvent("prompt");
|
|
212
|
+
} else {
|
|
213
|
+
debug("Unknown hook event", { hook_event_name: input.hook_event_name });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
async function readStdin() {
|
|
217
|
+
if (typeof Bun !== "undefined") {
|
|
218
|
+
return Bun.stdin.text();
|
|
219
|
+
}
|
|
220
|
+
return new Promise((resolve, reject) => {
|
|
221
|
+
const chunks = [];
|
|
222
|
+
process.stdin.on("data", (chunk) => chunks.push(chunk));
|
|
223
|
+
process.stdin.on("end", () => resolve(Buffer.concat(chunks).toString("utf-8")));
|
|
224
|
+
process.stdin.on("error", reject);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
async function main() {
|
|
228
|
+
try {
|
|
229
|
+
const input = await readStdin();
|
|
230
|
+
const hookInput = JSON.parse(input);
|
|
231
|
+
await handleHookEvent(hookInput);
|
|
232
|
+
process.exit(0);
|
|
233
|
+
} catch {
|
|
234
|
+
process.exit(0);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/bin/haptic-hook.ts
|
|
239
|
+
main();
|
package/hooks/hooks.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"hooks": [
|
|
6
6
|
{
|
|
7
7
|
"type": "command",
|
|
8
|
-
"command": "node ${CLAUDE_PLUGIN_ROOT}/
|
|
8
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/haptic-hook.js",
|
|
9
9
|
"timeout": 5000
|
|
10
10
|
}
|
|
11
11
|
]
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"hooks": [
|
|
18
18
|
{
|
|
19
19
|
"type": "command",
|
|
20
|
-
"command": "node ${CLAUDE_PLUGIN_ROOT}/
|
|
20
|
+
"command": "node ${CLAUDE_PLUGIN_ROOT}/hooks/haptic-hook.js",
|
|
21
21
|
"timeout": 5000
|
|
22
22
|
}
|
|
23
23
|
]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vibe-haptic",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"author": "Jeon Suyeol",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -28,9 +28,7 @@
|
|
|
28
28
|
"play": "bun run src/bin/haptic.ts",
|
|
29
29
|
"prepublishOnly": "bun run build"
|
|
30
30
|
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"zod": "^4.0.0"
|
|
33
|
-
},
|
|
31
|
+
"dependencies": {},
|
|
34
32
|
"devDependencies": {
|
|
35
33
|
"@biomejs/biome": "2.3.11",
|
|
36
34
|
"@napi-rs/cli": "^2.16",
|