@canonmsg/claude-code-plugin 0.9.1 → 0.9.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,2 @@
1
+ export declare function isDirectExecution(moduleUrl: string): boolean;
2
+ export declare function runCli(moduleUrl: string, main: () => void | Promise<void>, onError: (error: unknown) => void): void;
@@ -0,0 +1,16 @@
1
+ import { resolve } from 'node:path';
2
+ import { pathToFileURL } from 'node:url';
3
+ export function isDirectExecution(moduleUrl) {
4
+ const entry = process.argv[1];
5
+ if (!entry)
6
+ return false;
7
+ return pathToFileURL(resolve(entry)).href === moduleUrl;
8
+ }
9
+ export function runCli(moduleUrl, main, onError) {
10
+ if (!isDirectExecution(moduleUrl)) {
11
+ return;
12
+ }
13
+ Promise.resolve()
14
+ .then(() => main())
15
+ .catch(onError);
16
+ }
package/dist/host.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ export declare function main(): Promise<void>;
package/dist/host.js CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  import { setDefaultResultOrder } from 'node:dns';
3
- setDefaultResultOrder('ipv4first');
4
3
  /**
5
4
  * Canon Agent SDK host wrapper — multi-session.
6
5
  *
@@ -29,6 +28,7 @@ import { buildConfiguredWorkspaceOptions, buildConversationEnvironmentKey, build
29
28
  import { buildCanonHostPrompt, buildHydratedInboundContext, createConversationMetadataLoader, loadHostSessionConfig, publishHostAgentRuntime, renderCanonHostInboundContent, resolveHostWorkspaceCwd, } from './host-runtime.js';
30
29
  import { buildInboundContextLines, decideAutoReply, } from './inbound-policy.js';
31
30
  import { createStreamingBuffer } from './streaming-buffer.js';
31
+ import { runCli } from './cli-entry.js';
32
32
  let workingDir = process.cwd();
33
33
  let workspaceOptions = [];
34
34
  let runtimeModels = [];
@@ -666,7 +666,8 @@ function createSession(conversationId, environment, agentId, client, onSessionEn
666
666
  return session;
667
667
  }
668
668
  // ── Main ────────────────────────────────────────────────────────────
669
- async function main() {
669
+ export async function main() {
670
+ setDefaultResultOrder('ipv4first');
670
671
  const { values: args } = parseArgs({
671
672
  options: {
672
673
  cwd: { type: 'string' },
@@ -1156,7 +1157,7 @@ async function main() {
1156
1157
  await new Promise(() => { });
1157
1158
  }
1158
1159
  // ── Entry ───────────────────────────────────────────────────────────
1159
- main().catch((err) => {
1160
+ runCli(import.meta.url, main, (err) => {
1160
1161
  console.error('[canon-host] Fatal error:', err);
1161
1162
  const ap = getActiveProfile();
1162
1163
  if (ap)
@@ -0,0 +1,4 @@
1
+ export { main as serverMain } from './server.js';
2
+ export { main as hostMain } from './host.js';
3
+ export { main as registerMain } from './register.js';
4
+ export { main as setupMain } from './setup.js';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { main as serverMain } from './server.js';
2
+ export { main as hostMain } from './host.js';
3
+ export { main as registerMain } from './register.js';
4
+ export { main as setupMain } from './setup.js';
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ export declare function main(): Promise<void>;
package/dist/register.js CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  import { setDefaultResultOrder } from 'node:dns';
3
- setDefaultResultOrder('ipv4first');
4
3
  /**
5
4
  * CLI script for Canon agent registration.
6
5
  * Invoked by the /canon-register skill.
@@ -15,80 +14,88 @@ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
15
14
  import { join } from 'node:path';
16
15
  import { homedir } from 'node:os';
17
16
  import { parseArgs } from 'node:util';
17
+ import { runCli } from './cli-entry.js';
18
18
  const CANON_DIR = join(homedir(), '.canon');
19
19
  const AGENTS_PATH = join(CANON_DIR, 'agents.json');
20
- const { values } = parseArgs({
21
- options: {
22
- name: { type: 'string' },
23
- description: { type: 'string' },
24
- phone: { type: 'string' },
25
- profile: { type: 'string' },
26
- 'base-url': { type: 'string' },
27
- },
28
- strict: true,
29
- });
30
- if (!values.name || !values.description || !values.phone) {
31
- console.error('Usage: node register.js --name "Agent Name" --description "Description" --phone "+15551234567" [--profile "my-agent"]');
32
- process.exit(1);
33
- }
34
- // Default profile name: sanitized agent name
35
- const profileName = values.profile || values.name.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/-+/g, '-');
36
- let existingAgentId;
37
- try {
38
- const profiles = JSON.parse(readFileSync(AGENTS_PATH, 'utf-8'));
39
- existingAgentId = profiles[profileName]?.agentId;
40
- }
41
- catch {
42
- // File doesn't exist yet
43
- }
44
- console.log(`Registering agent "${values.name}" (profile: ${profileName})...`);
45
- const result = await registerAndWaitForApproval({
46
- name: values.name,
47
- description: values.description,
48
- ownerPhone: values.phone,
49
- developerInfo: 'Claude Code plugin',
50
- clientType: 'claude-code',
51
- baseUrl: values['base-url'],
52
- requestedAgentId: existingAgentId,
53
- }, {
54
- onSubmitted: (requestId) => {
55
- console.log(`Registration submitted (request ID: ${requestId}).`);
56
- console.log('Waiting for approval in Canon app...');
57
- },
58
- onPollUpdate: () => {
59
- process.stdout.write('.');
60
- },
61
- });
62
- console.log(''); // newline after dots
63
- switch (result.status) {
64
- case 'approved': {
65
- // Save to ~/.canon/agents.json
66
- mkdirSync(CANON_DIR, { recursive: true });
67
- let profiles = {};
68
- try {
69
- profiles = JSON.parse(readFileSync(AGENTS_PATH, 'utf-8'));
70
- }
71
- catch {
72
- // File doesn't exist yet
20
+ export async function main() {
21
+ setDefaultResultOrder('ipv4first');
22
+ const { values } = parseArgs({
23
+ options: {
24
+ name: { type: 'string' },
25
+ description: { type: 'string' },
26
+ phone: { type: 'string' },
27
+ profile: { type: 'string' },
28
+ 'base-url': { type: 'string' },
29
+ },
30
+ strict: true,
31
+ });
32
+ if (!values.name || !values.description || !values.phone) {
33
+ console.error('Usage: node register.js --name "Agent Name" --description "Description" --phone "+15551234567" [--profile "my-agent"]');
34
+ process.exit(1);
35
+ }
36
+ // Default profile name: sanitized agent name
37
+ const profileName = values.profile || values.name.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/-+/g, '-');
38
+ let existingAgentId;
39
+ try {
40
+ const profiles = JSON.parse(readFileSync(AGENTS_PATH, 'utf-8'));
41
+ existingAgentId = profiles[profileName]?.agentId;
42
+ }
43
+ catch {
44
+ // File doesn't exist yet
45
+ }
46
+ console.log(`Registering agent "${values.name}" (profile: ${profileName})...`);
47
+ const result = await registerAndWaitForApproval({
48
+ name: values.name,
49
+ description: values.description,
50
+ ownerPhone: values.phone,
51
+ developerInfo: 'Claude Code plugin',
52
+ clientType: 'claude-code',
53
+ baseUrl: values['base-url'],
54
+ requestedAgentId: existingAgentId,
55
+ }, {
56
+ onSubmitted: (requestId) => {
57
+ console.log(`Registration submitted (request ID: ${requestId}).`);
58
+ console.log('Waiting for approval in Canon app...');
59
+ },
60
+ onPollUpdate: () => {
61
+ process.stdout.write('.');
62
+ },
63
+ });
64
+ console.log(''); // newline after dots
65
+ switch (result.status) {
66
+ case 'approved': {
67
+ // Save to ~/.canon/agents.json
68
+ mkdirSync(CANON_DIR, { recursive: true });
69
+ let profiles = {};
70
+ try {
71
+ profiles = JSON.parse(readFileSync(AGENTS_PATH, 'utf-8'));
72
+ }
73
+ catch {
74
+ // File doesn't exist yet
75
+ }
76
+ profiles[profileName] = {
77
+ apiKey: result.apiKey,
78
+ agentId: result.agentId,
79
+ agentName: result.agentName,
80
+ registeredAt: new Date().toISOString(),
81
+ };
82
+ writeFileSync(AGENTS_PATH, JSON.stringify(profiles, null, 2));
83
+ console.log(`Approved! Agent: ${result.agentName} (${result.agentId})`);
84
+ console.log(`Saved as profile "${profileName}" in ~/.canon/agents.json`);
85
+ console.log('Restart Claude Code to connect.');
86
+ break;
73
87
  }
74
- profiles[profileName] = {
75
- apiKey: result.apiKey,
76
- agentId: result.agentId,
77
- agentName: result.agentName,
78
- registeredAt: new Date().toISOString(),
79
- };
80
- writeFileSync(AGENTS_PATH, JSON.stringify(profiles, null, 2));
81
- console.log(`Approved! Agent: ${result.agentName} (${result.agentId})`);
82
- console.log(`Saved as profile "${profileName}" in ~/.canon/agents.json`);
83
- console.log('Restart Claude Code to connect.');
84
- break;
88
+ case 'rejected':
89
+ console.log('Registration was rejected.');
90
+ process.exit(1);
91
+ break;
92
+ case 'timeout':
93
+ console.log('Registration timed out (5 minutes). Try again later.');
94
+ process.exit(1);
95
+ break;
85
96
  }
86
- case 'rejected':
87
- console.log('Registration was rejected.');
88
- process.exit(1);
89
- break;
90
- case 'timeout':
91
- console.log('Registration timed out (5 minutes). Try again later.');
92
- process.exit(1);
93
- break;
94
97
  }
98
+ runCli(import.meta.url, main, (error) => {
99
+ console.error('[canon-register] Fatal error:', error);
100
+ process.exit(1);
101
+ });
package/dist/server.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ export declare function main(): Promise<void>;
package/dist/server.js CHANGED
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
  import { setDefaultResultOrder } from 'node:dns';
3
- setDefaultResultOrder('ipv4first');
4
3
  /**
5
4
  * Canon channel MCP server for Claude Code.
6
5
  *
@@ -13,6 +12,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
13
12
  import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
14
13
  import { CanonClient, CanonStream, ApprovalManager, loadProfiles, isProfileLocked, resolveCanonAgent, getActiveProfile, releaseLock, initRTDBAuth, writeSessionState, clearSessionState, } from '@canonmsg/core';
15
14
  import { ApprovalHttpServer } from './approval-server.js';
15
+ import { runCli } from './cli-entry.js';
16
16
  // ── MCP server ─────────────────────────────────────────────────────────
17
17
  const server = new Server({ name: 'canon-channel', version: '0.1.0' }, {
18
18
  capabilities: {
@@ -593,7 +593,8 @@ async function startChannel() {
593
593
  }
594
594
  }
595
595
  // ── Main ───────────────────────────────────────────────────────────────
596
- async function main() {
596
+ export async function main() {
597
+ setDefaultResultOrder('ipv4first');
597
598
  const transport = new StdioServerTransport();
598
599
  await server.connect(transport);
599
600
  // Start the Canon channel after MCP connection is established
@@ -617,7 +618,7 @@ async function main() {
617
618
  process.on('SIGINT', shutdown);
618
619
  process.on('SIGTERM', shutdown);
619
620
  }
620
- main().catch((err) => {
621
+ runCli(import.meta.url, main, (err) => {
621
622
  console.error('[canon] Fatal error:', err);
622
623
  process.exit(1);
623
624
  });
package/dist/setup.d.ts CHANGED
@@ -6,4 +6,4 @@
6
6
  * 1. Install the /canon-register and /canon-configure skills
7
7
  * 2. Show the user how to add the MCP server to their .mcp.json
8
8
  */
9
- export {};
9
+ export declare function main(): void;
package/dist/setup.js CHANGED
@@ -9,6 +9,7 @@
9
9
  import { mkdirSync, writeFileSync, existsSync, readFileSync } from 'node:fs';
10
10
  import { join, dirname } from 'node:path';
11
11
  import { fileURLToPath } from 'node:url';
12
+ import { runCli } from './cli-entry.js';
12
13
  const __dirname = dirname(fileURLToPath(import.meta.url));
13
14
  const home = process.env.HOME || process.env.USERPROFILE || '';
14
15
  const skillsDir = join(home, '.claude', 'skills');
@@ -55,12 +56,18 @@ Then start Claude Code with:
55
56
  `);
56
57
  }
57
58
  // ── Main ───────────────────────────────────────────────────────────────
58
- console.log('Canon Claude Code Plugin Setup');
59
- console.log('==============================\n');
60
- console.log('Installing skills...');
61
- installSkills();
62
- console.log('\nRegistering your agent...');
63
- console.log(' Run /canon-register in Claude Code to register a new agent');
64
- console.log(' Run /canon-configure if you already have an API key\n');
65
- console.log('MCP server configuration:');
66
- showMcpInstructions();
59
+ export function main() {
60
+ console.log('Canon Claude Code Plugin Setup');
61
+ console.log('==============================\n');
62
+ console.log('Installing skills...');
63
+ installSkills();
64
+ console.log('\nRegistering your agent...');
65
+ console.log(' Run /canon-register in Claude Code to register a new agent');
66
+ console.log(' Run /canon-configure if you already have an API key\n');
67
+ console.log('MCP server configuration:');
68
+ showMcpInstructions();
69
+ }
70
+ runCli(import.meta.url, main, (error) => {
71
+ console.error('[canon-setup] Fatal error:', error);
72
+ process.exit(1);
73
+ });
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "@canonmsg/claude-code-plugin",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "Canon channel plugin for Claude Code — messaging where AI agents are first-class citizens",
5
5
  "type": "module",
6
- "main": "dist/server.js",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
7
14
  "bin": {
8
15
  "canon-channel-server": "dist/server.js",
9
16
  "canon-claude": "dist/host.js",