@fermindi/pwn-cli 0.6.0 → 0.8.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.
package/cli/notify.js DELETED
@@ -1,135 +0,0 @@
1
- #!/usr/bin/env node
2
- import * as notifications from '../src/services/notification-service.js';
3
-
4
- export default async function notifyCommand(args = []) {
5
- const subcommand = args[0];
6
- const restArgs = args.slice(1);
7
-
8
- switch (subcommand) {
9
- case 'test':
10
- await testNotification(restArgs);
11
- break;
12
-
13
- case 'send':
14
- await sendNotification(restArgs);
15
- break;
16
-
17
- case 'config':
18
- showConfig();
19
- break;
20
-
21
- default:
22
- showHelp();
23
- }
24
- }
25
-
26
- /**
27
- * Test notification channel
28
- */
29
- async function testNotification(args) {
30
- const channel = args[0] || 'desktop';
31
-
32
- console.log(`šŸ”” Testing ${channel} notifications...\n`);
33
-
34
- const result = await notifications.test(channel);
35
-
36
- if (result.success) {
37
- console.log(`āœ… ${channel} notification sent successfully!`);
38
- } else {
39
- console.log(`āŒ ${channel} notification failed: ${result.error}`);
40
-
41
- if (channel === 'ntfy' && result.error.includes('not configured')) {
42
- console.log('\nšŸ’” To configure ntfy:');
43
- console.log(' 1. Edit .ai/config/notifications.json');
44
- console.log(' 2. Set channels.ntfy.enabled = true');
45
- console.log(' 3. Set channels.ntfy.topic = "your-unique-topic"');
46
- console.log(' 4. Subscribe to your topic at https://ntfy.sh/your-unique-topic');
47
- }
48
- }
49
- }
50
-
51
- /**
52
- * Send custom notification
53
- */
54
- async function sendNotification(args) {
55
- if (args.length === 0) {
56
- console.log('āŒ Message required');
57
- console.log(' Usage: pwn notify send "Your message" [--title "Title"] [--channel desktop]');
58
- process.exit(1);
59
- }
60
-
61
- // Parse args
62
- let message = '';
63
- let title = 'PWN Notification';
64
- let channel = undefined;
65
-
66
- for (let i = 0; i < args.length; i++) {
67
- if (args[i] === '--title' || args[i] === '-t') {
68
- title = args[++i];
69
- } else if (args[i] === '--channel' || args[i] === '-c') {
70
- channel = args[++i];
71
- } else if (!message) {
72
- message = args[i];
73
- }
74
- }
75
-
76
- if (!message) {
77
- console.log('āŒ Message required');
78
- process.exit(1);
79
- }
80
-
81
- console.log(`šŸ”” Sending notification...\n`);
82
-
83
- const result = await notifications.send({ title, message }, { channel });
84
-
85
- if (result.success) {
86
- console.log(`āœ… Notification sent via ${result.channel}`);
87
- } else {
88
- console.log(`āŒ Failed: ${result.error}`);
89
- process.exit(1);
90
- }
91
- }
92
-
93
- /**
94
- * Show current configuration
95
- */
96
- function showConfig() {
97
- const config = notifications.loadConfig();
98
-
99
- console.log('šŸ”” Notification Configuration\n');
100
- console.log(` Enabled: ${config.enabled ? 'Yes' : 'No'}`);
101
- console.log(` Default Channel: ${config.defaultChannel}\n`);
102
- console.log(' Channels:');
103
-
104
- for (const [name, channelConfig] of Object.entries(config.channels)) {
105
- const status = channelConfig.enabled ? 'āœ“' : 'āœ—';
106
- console.log(` ${status} ${name}`);
107
-
108
- if (name === 'ntfy' && channelConfig.enabled) {
109
- console.log(` Server: ${channelConfig.server}`);
110
- console.log(` Topic: ${channelConfig.topic || '(not set)'}`);
111
- }
112
- }
113
-
114
- console.log('\nšŸ“ Config file: .ai/config/notifications.json');
115
- }
116
-
117
- /**
118
- * Show help
119
- */
120
- function showHelp() {
121
- console.log('šŸ”” PWN Notifications\n');
122
- console.log('Usage: pwn notify <command> [options]\n');
123
- console.log('Commands:');
124
- console.log(' test [channel] Test notifications (default: desktop)');
125
- console.log(' send "message" [options] Send a notification');
126
- console.log(' config Show current configuration\n');
127
- console.log('Options for send:');
128
- console.log(' --title, -t "Title" Set notification title');
129
- console.log(' --channel, -c <name> Use specific channel (desktop, ntfy, pushover)\n');
130
- console.log('Examples:');
131
- console.log(' pwn notify test');
132
- console.log(' pwn notify test ntfy');
133
- console.log(' pwn notify send "Build complete!"');
134
- console.log(' pwn notify send "Deploy done" --title "Production" --channel ntfy');
135
- }
@@ -1,342 +0,0 @@
1
- /**
2
- * PWN Notification Service
3
- *
4
- * Multi-channel notification system for task completion alerts.
5
- * Supports: ntfy.sh, desktop notifications, and extensible channels.
6
- */
7
-
8
- import { existsSync, readFileSync } from 'fs';
9
- import { join } from 'path';
10
-
11
- /**
12
- * @typedef {Object} NotificationConfig
13
- * @property {boolean} enabled - Global enable/disable
14
- * @property {string} defaultChannel - Default channel to use
15
- * @property {Object} channels - Channel-specific configurations
16
- */
17
-
18
- /**
19
- * @typedef {Object} NotificationPayload
20
- * @property {string} title - Notification title
21
- * @property {string} message - Notification body
22
- * @property {string} [priority] - Priority level (low, default, high, urgent)
23
- * @property {string[]} [tags] - Tags/emojis for the notification
24
- * @property {string} [url] - Click action URL
25
- */
26
-
27
- /**
28
- * Default configuration
29
- */
30
- const DEFAULT_CONFIG = {
31
- enabled: true,
32
- defaultChannel: 'desktop',
33
- channels: {
34
- ntfy: {
35
- enabled: false,
36
- server: 'https://ntfy.sh',
37
- topic: '',
38
- priority: 'default'
39
- },
40
- desktop: {
41
- enabled: true
42
- },
43
- pushover: {
44
- enabled: false,
45
- userKey: '',
46
- apiToken: ''
47
- }
48
- }
49
- };
50
-
51
- /**
52
- * Load notification configuration from workspace
53
- * @param {string} cwd - Working directory
54
- * @returns {NotificationConfig}
55
- */
56
- export function loadConfig(cwd = process.cwd()) {
57
- const configPath = join(cwd, '.ai', 'config', 'notifications.json');
58
-
59
- if (!existsSync(configPath)) {
60
- return DEFAULT_CONFIG;
61
- }
62
-
63
- try {
64
- const content = readFileSync(configPath, 'utf8');
65
- const userConfig = JSON.parse(content);
66
-
67
- // Merge with defaults
68
- return {
69
- ...DEFAULT_CONFIG,
70
- ...userConfig,
71
- channels: {
72
- ...DEFAULT_CONFIG.channels,
73
- ...userConfig.channels
74
- }
75
- };
76
- } catch {
77
- return DEFAULT_CONFIG;
78
- }
79
- }
80
-
81
- /**
82
- * Send notification through configured channels
83
- * @param {NotificationPayload} payload - Notification data
84
- * @param {Object} options - Send options
85
- * @param {string} [options.channel] - Specific channel to use
86
- * @param {string} [options.cwd] - Working directory
87
- * @returns {Promise<{success: boolean, channel: string, error?: string}>}
88
- */
89
- export async function send(payload, options = {}) {
90
- const { channel: specificChannel, cwd = process.cwd() } = options;
91
- const config = loadConfig(cwd);
92
-
93
- if (!config.enabled) {
94
- return { success: false, channel: 'none', error: 'Notifications disabled' };
95
- }
96
-
97
- const channelName = specificChannel || config.defaultChannel;
98
- const channelConfig = config.channels[channelName];
99
-
100
- if (!channelConfig) {
101
- return { success: false, channel: channelName, error: `Unknown channel: ${channelName}` };
102
- }
103
-
104
- if (!channelConfig.enabled) {
105
- return { success: false, channel: channelName, error: `Channel ${channelName} is disabled` };
106
- }
107
-
108
- try {
109
- switch (channelName) {
110
- case 'ntfy':
111
- return await sendNtfy(payload, channelConfig);
112
- case 'desktop':
113
- return await sendDesktop(payload, channelConfig);
114
- case 'pushover':
115
- return await sendPushover(payload, channelConfig);
116
- default:
117
- return { success: false, channel: channelName, error: `No handler for channel: ${channelName}` };
118
- }
119
- } catch (error) {
120
- return { success: false, channel: channelName, error: error.message };
121
- }
122
- }
123
-
124
- /**
125
- * Send notification via ntfy.sh
126
- * @param {NotificationPayload} payload
127
- * @param {Object} config
128
- */
129
- async function sendNtfy(payload, config) {
130
- const { server = 'https://ntfy.sh', topic, priority = 'default' } = config;
131
-
132
- if (!topic) {
133
- return { success: false, channel: 'ntfy', error: 'ntfy topic not configured' };
134
- }
135
-
136
- const url = `${server}/${topic}`;
137
-
138
- const headers = {
139
- 'Title': payload.title,
140
- 'Priority': payload.priority || priority,
141
- };
142
-
143
- if (payload.tags && payload.tags.length > 0) {
144
- headers['Tags'] = payload.tags.join(',');
145
- }
146
-
147
- if (payload.url) {
148
- headers['Click'] = payload.url;
149
- }
150
-
151
- const response = await fetch(url, {
152
- method: 'POST',
153
- headers,
154
- body: payload.message
155
- });
156
-
157
- if (!response.ok) {
158
- return { success: false, channel: 'ntfy', error: `HTTP ${response.status}` };
159
- }
160
-
161
- return { success: true, channel: 'ntfy' };
162
- }
163
-
164
- /**
165
- * Send desktop notification
166
- * Uses native OS notifications via child process
167
- * @param {NotificationPayload} payload
168
- * @param {Object} config
169
- */
170
- async function sendDesktop(payload, config) {
171
- const { title, message } = payload;
172
-
173
- // Use PowerShell on Windows for native toast notifications
174
- if (process.platform === 'win32') {
175
- const { exec } = await import('child_process');
176
- const { promisify } = await import('util');
177
- const execAsync = promisify(exec);
178
-
179
- // Escape quotes in message
180
- const escapedTitle = title.replace(/"/g, '`"');
181
- const escapedMessage = message.replace(/"/g, '`"');
182
-
183
- const script = `
184
- [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
185
- [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
186
- $template = @"
187
- <toast>
188
- <visual>
189
- <binding template="ToastText02">
190
- <text id="1">${escapedTitle}</text>
191
- <text id="2">${escapedMessage}</text>
192
- </binding>
193
- </visual>
194
- </toast>
195
- "@
196
- $xml = New-Object Windows.Data.Xml.Dom.XmlDocument
197
- $xml.LoadXml($template)
198
- $toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
199
- [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("PWN").Show($toast)
200
- `;
201
-
202
- try {
203
- await execAsync(`powershell -Command "${script.replace(/\n/g, ' ')}"`, {
204
- windowsHide: true
205
- });
206
- return { success: true, channel: 'desktop' };
207
- } catch (error) {
208
- // Fallback to simple msg command
209
- try {
210
- await execAsync(`msg %username% "${escapedTitle}: ${escapedMessage}"`, {
211
- windowsHide: true
212
- });
213
- return { success: true, channel: 'desktop' };
214
- } catch {
215
- return { success: false, channel: 'desktop', error: 'Desktop notifications not available' };
216
- }
217
- }
218
- }
219
-
220
- // macOS
221
- if (process.platform === 'darwin') {
222
- const { exec } = await import('child_process');
223
- const { promisify } = await import('util');
224
- const execAsync = promisify(exec);
225
-
226
- const escapedTitle = title.replace(/"/g, '\\"');
227
- const escapedMessage = message.replace(/"/g, '\\"');
228
-
229
- try {
230
- await execAsync(`osascript -e 'display notification "${escapedMessage}" with title "${escapedTitle}"'`);
231
- return { success: true, channel: 'desktop' };
232
- } catch (error) {
233
- return { success: false, channel: 'desktop', error: error.message };
234
- }
235
- }
236
-
237
- // Linux (notify-send)
238
- if (process.platform === 'linux') {
239
- const { exec } = await import('child_process');
240
- const { promisify } = await import('util');
241
- const execAsync = promisify(exec);
242
-
243
- try {
244
- await execAsync(`notify-send "${title}" "${message}"`);
245
- return { success: true, channel: 'desktop' };
246
- } catch (error) {
247
- return { success: false, channel: 'desktop', error: 'notify-send not available' };
248
- }
249
- }
250
-
251
- return { success: false, channel: 'desktop', error: `Unsupported platform: ${process.platform}` };
252
- }
253
-
254
- /**
255
- * Send notification via Pushover
256
- * @param {NotificationPayload} payload
257
- * @param {Object} config
258
- */
259
- async function sendPushover(payload, config) {
260
- const { userKey, apiToken } = config;
261
-
262
- if (!userKey || !apiToken) {
263
- return { success: false, channel: 'pushover', error: 'Pushover credentials not configured' };
264
- }
265
-
266
- const priorityMap = {
267
- 'low': -1,
268
- 'default': 0,
269
- 'high': 1,
270
- 'urgent': 2
271
- };
272
-
273
- const body = new URLSearchParams({
274
- token: apiToken,
275
- user: userKey,
276
- title: payload.title,
277
- message: payload.message,
278
- priority: priorityMap[payload.priority || 'default'] || 0
279
- });
280
-
281
- if (payload.url) {
282
- body.append('url', payload.url);
283
- }
284
-
285
- const response = await fetch('https://api.pushover.net/1/messages.json', {
286
- method: 'POST',
287
- body
288
- });
289
-
290
- if (!response.ok) {
291
- const data = await response.json().catch(() => ({}));
292
- return { success: false, channel: 'pushover', error: data.errors?.join(', ') || `HTTP ${response.status}` };
293
- }
294
-
295
- return { success: true, channel: 'pushover' };
296
- }
297
-
298
- /**
299
- * Test notification configuration
300
- * @param {string} channel - Channel to test
301
- * @param {string} cwd - Working directory
302
- * @returns {Promise<{success: boolean, channel: string, error?: string}>}
303
- */
304
- export async function test(channel, cwd = process.cwd()) {
305
- return send({
306
- title: 'PWN Test Notification',
307
- message: 'If you see this, notifications are working!',
308
- tags: ['white_check_mark', 'robot']
309
- }, { channel, cwd });
310
- }
311
-
312
- /**
313
- * Send task completion notification
314
- * @param {string} taskId - Task identifier
315
- * @param {string} taskName - Task description
316
- * @param {Object} options - Additional options
317
- */
318
- export async function notifyTaskComplete(taskId, taskName, options = {}) {
319
- return send({
320
- title: 'Task Completed',
321
- message: `${taskId}: ${taskName}`,
322
- tags: ['white_check_mark'],
323
- priority: 'default',
324
- ...options
325
- }, options);
326
- }
327
-
328
- /**
329
- * Send error notification
330
- * @param {string} title - Error title
331
- * @param {string} message - Error details
332
- * @param {Object} options - Additional options
333
- */
334
- export async function notifyError(title, message, options = {}) {
335
- return send({
336
- title,
337
- message,
338
- tags: ['x', 'warning'],
339
- priority: 'high',
340
- ...options
341
- }, options);
342
- }
@@ -1,52 +0,0 @@
1
- {
2
- "name": "PWN Development Environment",
3
- "image": "mcr.microsoft.com/devcontainers/javascript-node:22",
4
-
5
- "features": {
6
- "ghcr.io/devcontainers/features/github-cli:1": {},
7
- "ghcr.io/devcontainers/features/git:1": {}
8
- },
9
-
10
- "customizations": {
11
- "vscode": {
12
- "settings": {
13
- "terminal.integrated.defaultProfile.linux": "bash",
14
- "editor.formatOnSave": true,
15
- "editor.tabSize": 2,
16
- "files.trimTrailingWhitespace": true,
17
- "files.insertFinalNewline": true,
18
- "javascript.preferences.importModuleSpecifierEnding": "js",
19
- "typescript.preferences.importModuleSpecifierEnding": "js"
20
- },
21
- "extensions": [
22
- "dbaeumer.vscode-eslint",
23
- "esbenp.prettier-vscode",
24
- "bradlc.vscode-tailwindcss",
25
- "formulahendry.auto-rename-tag",
26
- "christian-kohler.path-intellisense",
27
- "usernamehw.errorlens",
28
- "eamodio.gitlens",
29
- "github.copilot",
30
- "anthropics.claude-code"
31
- ]
32
- }
33
- },
34
-
35
- "postCreateCommand": "bash .devcontainer/setup.sh",
36
- "postStartCommand": "echo 'šŸš€ Development environment ready!'",
37
-
38
- "forwardPorts": [3000, 5173, 8080],
39
-
40
- "portsAttributes": {
41
- "3000": { "label": "App", "onAutoForward": "notify" },
42
- "5173": { "label": "Vite", "onAutoForward": "notify" },
43
- "8080": { "label": "Server", "onAutoForward": "notify" }
44
- },
45
-
46
- "remoteUser": "node",
47
-
48
- "containerEnv": {
49
- "PWN_CODESPACE": "true",
50
- "NODE_ENV": "development"
51
- }
52
- }
@@ -1,70 +0,0 @@
1
- #!/bin/bash
2
- # PWN Codespace Setup Script
3
- # Runs automatically when codespace is created
4
-
5
- set -e
6
-
7
- echo "=========================================="
8
- echo " Setting up development environment"
9
- echo "=========================================="
10
-
11
- # Colors
12
- GREEN='\033[0;32m'
13
- BLUE='\033[0;34m'
14
- NC='\033[0m'
15
-
16
- print_step() { echo -e "${BLUE}>>>${NC} $1"; }
17
- print_ok() { echo -e "${GREEN}[OK]${NC} $1"; }
18
-
19
- # 1. Install dependencies
20
- print_step "Installing dependencies..."
21
- if [ -f "pnpm-lock.yaml" ]; then
22
- npm install -g pnpm 2>/dev/null || true
23
- pnpm install
24
- elif [ -f "package-lock.json" ]; then
25
- npm ci
26
- elif [ -f "yarn.lock" ]; then
27
- npm install -g yarn 2>/dev/null || true
28
- yarn install --frozen-lockfile
29
- elif [ -f "package.json" ]; then
30
- npm install
31
- fi
32
- print_ok "Dependencies installed"
33
-
34
- # 2. Setup PWN if available
35
- if command -v pwn &> /dev/null; then
36
- print_step "Initializing PWN workspace..."
37
- if [ ! -d ".ai" ]; then
38
- pwn inject
39
- fi
40
- pwn knowledge sync 2>/dev/null || true
41
- print_ok "PWN workspace ready"
42
- fi
43
-
44
- # 3. Configure git
45
- print_step "Configuring git..."
46
- if [ -n "$GITHUB_USER" ]; then
47
- git config --global user.name "${GITHUB_USER}" 2>/dev/null || true
48
- git config --global user.email "${GITHUB_USER}@users.noreply.github.com" 2>/dev/null || true
49
- fi
50
- print_ok "Git configured"
51
-
52
- # 4. Setup aliases
53
- cat >> ~/.bashrc << 'ALIASES'
54
-
55
- # Quick aliases
56
- alias dev='npm run dev'
57
- alias build='npm run build'
58
- alias test='npm test'
59
- alias gs='git status'
60
- alias gd='git diff'
61
- alias gc='git commit'
62
- alias gp='git push'
63
- ALIASES
64
- print_ok "Aliases configured"
65
-
66
- echo ""
67
- echo "=========================================="
68
- echo -e "${GREEN} Setup complete!${NC}"
69
- echo "=========================================="
70
- echo ""
@@ -1,20 +0,0 @@
1
- {
2
- "enabled": true,
3
- "defaultChannel": "desktop",
4
- "channels": {
5
- "ntfy": {
6
- "enabled": false,
7
- "server": "https://ntfy.sh",
8
- "topic": "your-unique-topic-here",
9
- "priority": "default"
10
- },
11
- "desktop": {
12
- "enabled": true
13
- },
14
- "pushover": {
15
- "enabled": false,
16
- "userKey": "",
17
- "apiToken": ""
18
- }
19
- }
20
- }