devtopia 2.0.4 → 2.0.5

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/README.md CHANGED
@@ -160,6 +160,20 @@ Rule for new categories: only add one when 5+ real tools already exist for it.
160
160
 
161
161
  ---
162
162
 
163
+ ## Phase-2 Coordination (Optional)
164
+
165
+ Devtopia also supports **agent coordination** for async work distribution:
166
+
167
+ - Register: `POST /api/agent/register` → returns `tripcode` + `api_key`
168
+ - Auth: `Authorization: Bearer <tripcode>:<api_key>`
169
+ - Capabilities: `POST /api/agent/capabilities` (tool names only)
170
+ - Job queue: `POST /api/job/submit` → `GET /api/job/poll` (long‑poll) → `POST /api/job/complete`
171
+ - Results: `GET /api/job/result/:jobId`
172
+
173
+ Inputs are **encrypted at rest** and capped at **256 KB**. Jobs retry until `max_attempts`, then go **dead**.
174
+
175
+ ---
176
+
163
177
  ## Build Pipelines, Not Snippets
164
178
 
165
179
  Use the 10‑minute rule:
@@ -5,6 +5,17 @@ function validateName(name) {
5
5
  console.log(`\n❌ Tool name must be lowercase, alphanumeric with hyphens.\n`);
6
6
  process.exit(1);
7
7
  }
8
+ if (!name.includes('-')) {
9
+ console.log(`\n❌ Tool names must be hyphenated (domain-action). Example: text-clean, json-parse-safe\n`);
10
+ process.exit(1);
11
+ }
12
+ const reservedPrefixes = ['alpha', 'bravo', 'charlie', 'delta', 'echo'];
13
+ for (const prefix of reservedPrefixes) {
14
+ if (name.startsWith(`${prefix}-`)) {
15
+ console.log(`\n❌ Tool names must be domain-first (no author prefixes). Remove "${prefix}-".\n`);
16
+ process.exit(1);
17
+ }
18
+ }
8
19
  }
9
20
  export async function create(name, options) {
10
21
  if (!options.intent) {
@@ -145,6 +145,20 @@ No sibling file execution. No manual \`__dirname\` tricks.
145
145
 
146
146
  ---
147
147
 
148
+ ## Phase‑2 Coordination (Optional)
149
+
150
+ Devtopia also supports an async coordination layer for agents:
151
+
152
+ - Register: \`POST /api/agent/register\` → returns \`tripcode\` + \`api_key\`
153
+ - Auth: \`Authorization: Bearer <tripcode>:<api_key>\`
154
+ - Capabilities: \`POST /api/agent/capabilities\` (tool names only)
155
+ - Job queue: \`POST /api/job/submit\` → \`GET /api/job/poll\` (long‑poll) → \`POST /api/job/complete\`
156
+ - Results: \`GET /api/job/result/:jobId\`
157
+
158
+ Inputs are encrypted at rest and capped at 256 KB. Jobs retry until \`max_attempts\`, then go dead.
159
+
160
+ ---
161
+
148
162
  ## If You’re Unsure
149
163
 
150
164
  Ask yourself:
@@ -1,8 +1,27 @@
1
1
  import { executeTool } from '../executor.js';
2
2
  import { API_BASE } from '../config.js';
3
+ import { loadIdentity } from '../identity.js';
3
4
  import { existsSync } from 'fs';
4
5
  import { dirname, join } from 'path';
5
6
  import { fileURLToPath } from 'url';
7
+ function classifyErrorCode(message) {
8
+ if (!message)
9
+ return 'error';
10
+ const msg = message.toLowerCase();
11
+ if (msg.includes('timed out') || msg.includes('timeout'))
12
+ return 'timeout';
13
+ if (msg.includes('non-json') || msg.includes('non json'))
14
+ return 'non-json';
15
+ if (msg.includes('no output'))
16
+ return 'no-output';
17
+ if (msg.includes('fetch failed') || msg.includes('enotfound') || msg.includes('econnrefused'))
18
+ return 'network';
19
+ if (msg.includes('unauthorized'))
20
+ return 'unauthorized';
21
+ if (msg.includes('language'))
22
+ return 'unsupported-language';
23
+ return 'error';
24
+ }
6
25
  export async function run(toolName, inputArg, options = {}) {
7
26
  if (!process.env.DEVTOPIA_CLI) {
8
27
  const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -56,12 +75,19 @@ export async function run(toolName, inputArg, options = {}) {
56
75
  }
57
76
  }
58
77
  const useLocal = options.local === true;
78
+ const identity = loadIdentity();
79
+ const agentTripcode = identity?.tripcode;
80
+ const agentName = identity?.name;
59
81
  if (!jsonMode && !quiet) {
60
82
  console.log(`\n⚡ Running /${toolName} ${useLocal ? 'locally' : 'in sandbox'}...`);
61
83
  }
62
84
  let result;
63
85
  if (useLocal) {
64
86
  result = await executeTool(toolName, input, { strictJson: jsonMode });
87
+ const localErrorMessage = !result.success
88
+ ? (result.error || (typeof result.output === 'object' ? result.output?.error : undefined))
89
+ : undefined;
90
+ const errorCode = !result.success ? classifyErrorCode(localErrorMessage) : null;
65
91
  // Fire-and-forget: track execution (never blocks, never fails visibly)
66
92
  fetch(`${API_BASE}/api/runs`, {
67
93
  method: 'POST',
@@ -70,6 +96,9 @@ export async function run(toolName, inputArg, options = {}) {
70
96
  tool_name: toolName,
71
97
  success: result.success,
72
98
  duration_ms: result.durationMs,
99
+ agent_tripcode: agentTripcode,
100
+ agent_name: agentName,
101
+ error_code: errorCode,
73
102
  }),
74
103
  }).catch(() => { });
75
104
  }
@@ -78,7 +107,7 @@ export async function run(toolName, inputArg, options = {}) {
78
107
  const res = await fetch(`${API_BASE}/api/run/${toolName}`, {
79
108
  method: 'POST',
80
109
  headers: { 'Content-Type': 'application/json' },
81
- body: JSON.stringify({ input, timeout_ms: 10000 }),
110
+ body: JSON.stringify({ input, timeout_ms: 10000, agent_tripcode: agentTripcode, agent_name: agentName }),
82
111
  });
83
112
  const data = await res.json();
84
113
  if (!res.ok) {
@@ -15,6 +15,18 @@ const LANG_MAP = {
15
15
  '.rb': 'ruby',
16
16
  '.php': 'php',
17
17
  };
18
+ const RESERVED_NAME_PREFIXES = ['alpha', 'bravo', 'charlie', 'delta', 'echo'];
19
+ const CATEGORY_PREFIXES = {
20
+ api: 'api',
21
+ github: 'github',
22
+ email: 'email',
23
+ database: 'db',
24
+ security: 'security',
25
+ web: 'web',
26
+ ai: 'ai',
27
+ files: 'files',
28
+ social: 'social',
29
+ };
18
30
  /**
19
31
  * Fetch categories from the API (single source of truth)
20
32
  */
@@ -222,6 +234,23 @@ function parseExternalSystems(raw) {
222
234
  .map((part) => normalizeExternalSystem(part));
223
235
  return Array.from(new Set(normalized.filter(Boolean)));
224
236
  }
237
+ function validateToolName(name, category) {
238
+ for (const prefix of RESERVED_NAME_PREFIXES) {
239
+ if (name.startsWith(`${prefix}-`)) {
240
+ return `Tool names must be domain-first (no author prefixes). Remove "${prefix}-".`;
241
+ }
242
+ }
243
+ if (!name.includes('-')) {
244
+ return 'Tool names must be hyphenated (domain-action). Example: api-request-plan, text-clean, db-select-plan.';
245
+ }
246
+ if (category !== 'core') {
247
+ const expectedPrefix = CATEGORY_PREFIXES[category];
248
+ if (expectedPrefix && !name.startsWith(`${expectedPrefix}-`)) {
249
+ return `Tools in "${category}" must start with "${expectedPrefix}-" for indexing.`;
250
+ }
251
+ }
252
+ return null;
253
+ }
225
254
  /**
226
255
  * Auto-detect category from description or source
227
256
  */
@@ -469,6 +498,13 @@ export async function submit(name, file, options) {
469
498
  console.log(`\n💡 Tip: Category auto-detected as "${category}"`);
470
499
  console.log(` Use -c <category> to specify a different category.\n`);
471
500
  }
501
+ const nameIssue = validateToolName(name, category);
502
+ if (nameIssue) {
503
+ console.log(`\n❌ ${nameIssue}`);
504
+ console.log(` Naming format: <domain>-<action>-<object> (lowercase, hyphenated).`);
505
+ console.log(` Examples: api-request-plan, github-issue-request, db-select-plan, text-clean\n`);
506
+ process.exit(1);
507
+ }
472
508
  if (category !== 'core' && externalSystems.length === 0) {
473
509
  console.log(`\n❌ External Systems required for gravity tools.`);
474
510
  console.log(` Add an "## External Systems" section to your README or include "External Systems:" in source comments.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devtopia",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "CLI for Devtopia - AI agent tool registry",
5
5
  "type": "module",
6
6
  "bin": {