@cluesmith/codev-core 3.2.0 → 3.2.1

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,44 @@
1
+ /**
2
+ * Architect-name utilities shared across packages (Spec 755 / 786).
3
+ *
4
+ * Lives in codev-core so the VS Code extension and the agent-farm server can
5
+ * both validate architect names with identical semantics — the extension's
6
+ * "Add Architect" InputBox (Issue 841) reuses the same rule Tower enforces
7
+ * server-side, instead of duplicating the regex.
8
+ *
9
+ * These functions are pure — they don't read process state or Tower; the caller
10
+ * is responsible for sourcing the existing-names set. Keeping them pure makes
11
+ * them trivially unit-testable. (`currentArchitectName`, which reads the
12
+ * process env, stays in the agent-farm package.)
13
+ */
14
+ export declare const ARCHITECT_NAME_PATTERN: RegExp;
15
+ export declare const MAX_ARCHITECT_NAME_LENGTH = 64;
16
+ /** Reserved default for the singleton case. */
17
+ export declare const DEFAULT_ARCHITECT_NAME = "main";
18
+ /**
19
+ * Validate an architect name. Returns `null` if valid, or a human-readable
20
+ * error message otherwise. Callers should treat a non-null return as "reject
21
+ * with this message" — the text is intentionally operator-facing.
22
+ *
23
+ * Spec 786: the name `main` is reserved for the workspace's default architect
24
+ * and is rejected here. Pre-#786, `main` was rejected only by collision check
25
+ * at the add-architect call site (which depended on a race-free in-memory map);
26
+ * rejecting in the pure validator is more robust.
27
+ */
28
+ export declare function validateArchitectName(name: string): string | null;
29
+ /**
30
+ * Compute the next auto-numbered architect name, given the set of names
31
+ * already in use. Uses "smallest unused integer ≥ 2" semantics:
32
+ *
33
+ * - {} → 'architect-2'
34
+ * - {'main'} → 'architect-2'
35
+ * - {'main', 'architect-2'} → 'architect-3'
36
+ * - {'main', 'architect-3'} → 'architect-2' (fills the gap)
37
+ * - {'main', 'architect-2', 'architect-3'} → 'architect-4'
38
+ * - {'main', 'sibling'} → 'architect-2' (custom names don't shift numbering)
39
+ *
40
+ * Custom names (anything not matching `architect-<N>` exactly) are ignored
41
+ * by the numbering loop — they're not part of the auto-numbered sequence.
42
+ */
43
+ export declare function autoNumberArchitectName(existingNames: Iterable<string>): string;
44
+ //# sourceMappingURL=architect-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"architect-name.d.ts","sourceRoot":"","sources":["../src/architect-name.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,sBAAsB,QAAsB,CAAC;AAC1D,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,+CAA+C;AAC/C,eAAO,MAAM,sBAAsB,SAAS,CAAC;AAE7C;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAcjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,CAc/E"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Architect-name utilities shared across packages (Spec 755 / 786).
3
+ *
4
+ * Lives in codev-core so the VS Code extension and the agent-farm server can
5
+ * both validate architect names with identical semantics — the extension's
6
+ * "Add Architect" InputBox (Issue 841) reuses the same rule Tower enforces
7
+ * server-side, instead of duplicating the regex.
8
+ *
9
+ * These functions are pure — they don't read process state or Tower; the caller
10
+ * is responsible for sourcing the existing-names set. Keeping them pure makes
11
+ * them trivially unit-testable. (`currentArchitectName`, which reads the
12
+ * process env, stays in the agent-farm package.)
13
+ */
14
+ export const ARCHITECT_NAME_PATTERN = /^[a-z][a-z0-9-]*$/;
15
+ export const MAX_ARCHITECT_NAME_LENGTH = 64;
16
+ /** Reserved default for the singleton case. */
17
+ export const DEFAULT_ARCHITECT_NAME = 'main';
18
+ /**
19
+ * Validate an architect name. Returns `null` if valid, or a human-readable
20
+ * error message otherwise. Callers should treat a non-null return as "reject
21
+ * with this message" — the text is intentionally operator-facing.
22
+ *
23
+ * Spec 786: the name `main` is reserved for the workspace's default architect
24
+ * and is rejected here. Pre-#786, `main` was rejected only by collision check
25
+ * at the add-architect call site (which depended on a race-free in-memory map);
26
+ * rejecting in the pure validator is more robust.
27
+ */
28
+ export function validateArchitectName(name) {
29
+ if (!name) {
30
+ return 'Architect name cannot be empty.';
31
+ }
32
+ if (name === DEFAULT_ARCHITECT_NAME) {
33
+ return `Architect name '${DEFAULT_ARCHITECT_NAME}' is reserved for the workspace's default architect.`;
34
+ }
35
+ if (name.length > MAX_ARCHITECT_NAME_LENGTH) {
36
+ return `Architect name must be at most ${MAX_ARCHITECT_NAME_LENGTH} characters (got ${name.length}).`;
37
+ }
38
+ if (!ARCHITECT_NAME_PATTERN.test(name)) {
39
+ return `Architect name '${name}' is invalid. Names must match [a-z][a-z0-9-]* (lowercase letter, then lowercase letters / digits / dashes).`;
40
+ }
41
+ return null;
42
+ }
43
+ /**
44
+ * Compute the next auto-numbered architect name, given the set of names
45
+ * already in use. Uses "smallest unused integer ≥ 2" semantics:
46
+ *
47
+ * - {} → 'architect-2'
48
+ * - {'main'} → 'architect-2'
49
+ * - {'main', 'architect-2'} → 'architect-3'
50
+ * - {'main', 'architect-3'} → 'architect-2' (fills the gap)
51
+ * - {'main', 'architect-2', 'architect-3'} → 'architect-4'
52
+ * - {'main', 'sibling'} → 'architect-2' (custom names don't shift numbering)
53
+ *
54
+ * Custom names (anything not matching `architect-<N>` exactly) are ignored
55
+ * by the numbering loop — they're not part of the auto-numbered sequence.
56
+ */
57
+ export function autoNumberArchitectName(existingNames) {
58
+ const usedNumbers = new Set();
59
+ for (const name of existingNames) {
60
+ const match = /^architect-(\d+)$/.exec(name);
61
+ if (match) {
62
+ const n = Number.parseInt(match[1], 10);
63
+ if (Number.isFinite(n) && n >= 2) {
64
+ usedNumbers.add(n);
65
+ }
66
+ }
67
+ }
68
+ let n = 2;
69
+ while (usedNumbers.has(n))
70
+ n++;
71
+ return `architect-${n}`;
72
+ }
73
+ //# sourceMappingURL=architect-name.js.map
@@ -0,0 +1 @@
1
+ {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WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YACrB,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;QAAE,CAAC,EAAE,CAAC;IAC/B,OAAO,aAAa,CAAC,EAAE,CAAC;AAC1B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cluesmith/codev-core",
3
- "version": "3.2.0",
3
+ "version": "3.2.1",
4
4
  "description": "Core runtime utilities for Codev — Tower client, auth, workspace helpers, escape buffer",
5
5
  "type": "module",
6
6
  "exports": {
@@ -32,6 +32,10 @@
32
32
  "types": "./dist/agent-names.d.ts",
33
33
  "default": "./dist/agent-names.js"
34
34
  },
35
+ "./architect-name": {
36
+ "types": "./dist/architect-name.d.ts",
37
+ "default": "./dist/architect-name.js"
38
+ },
35
39
  "./builder-helpers": {
36
40
  "types": "./dist/builder-helpers.d.ts",
37
41
  "default": "./dist/builder-helpers.js"
@@ -56,7 +60,7 @@
56
60
  "@types/node": "22.x",
57
61
  "typescript": "^5.7.0",
58
62
  "vitest": "^4.0.15",
59
- "@cluesmith/codev-types": "3.2.0"
63
+ "@cluesmith/codev-types": "3.2.1"
60
64
  },
61
65
  "license": "Apache-2.0",
62
66
  "scripts": {