@specdest/devkit 0.4.13 → 0.4.14

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
+ /** Check project-owned entrypoints; Controller and Devkit are intentionally exempt. */
2
+ export declare function automationPolicyFindings(root: string, files: string[]): string[];
@@ -0,0 +1,30 @@
1
+ import { readFileSync, existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ const FORBIDDEN = /(?:\b(?:pnpm\s+exec|npx|npm\s+exec|yarn\s+exec|bunx)\s+(?:agent-device|agent-browser|jev-browser)\b|\bhost-cli\s+(?:agent-device|agent-browser|jev-browser)\b|\b(?:SPECDEST_AGENT_DEVICE_BIN|node_modules\/\.bin\/(?:agent-device|agent-browser|jev-browser))\b)/u;
4
+ const DIRECT = new Set(['agent-device', 'agent-browser', 'jev-browser']);
5
+ /** Check project-owned entrypoints; Controller and Devkit are intentionally exempt. */
6
+ export function automationPolicyFindings(root, files) {
7
+ const findings = [];
8
+ const manifestPath = join(root, 'package.json');
9
+ if (existsSync(manifestPath)) {
10
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
11
+ for (const field of ['dependencies', 'devDependencies', 'optionalDependencies']) {
12
+ for (const name of Object.keys(manifest[field] ?? {})) {
13
+ if (DIRECT.has(name))
14
+ findings.push(`package.json: ${name} must be accessed via Devkit`);
15
+ }
16
+ }
17
+ }
18
+ for (const file of files) {
19
+ if (!/^(?:scripts\/.*\.(?:sh|js|cjs|mjs|ts|py)|package-scripts\.yml)$/u.test(file))
20
+ continue;
21
+ if (/(?:^|\/)(?:test[^/]*|[^/]*\.test\.[^/]*)$/u.test(file))
22
+ continue;
23
+ const full = join(root, file);
24
+ if (!existsSync(full))
25
+ continue;
26
+ if (FORBIDDEN.test(readFileSync(full, 'utf8')))
27
+ findings.push(`${file}: invoke through specdest device/browser instead of direct host tools`);
28
+ }
29
+ return findings;
30
+ }
package/dist/npm/cli.js CHANGED
@@ -3,12 +3,16 @@ import { createFlowCommandHandler, runCli } from "./index.js";
3
3
  import { createCanonicalCommandHandlers } from "./canonical-project-operations.js";
4
4
  import { runSupabaseLocal } from "./supabase-local.js";
5
5
  import { sendSlackFiles } from "./slack.js";
6
+ import { runHostAutomation } from "./host-automation.js";
6
7
  try {
7
8
  const exitCode = await runCli(process.argv.slice(2), process, {
8
9
  ...createCanonicalCommandHandlers(),
9
10
  flow: createFlowCommandHandler(),
10
11
  supabase: async (args) => runSupabaseLocal(args),
11
12
  slack: async (args) => sendSlackFiles(args),
13
+ device: async (args) => runHostAutomation('device', args),
14
+ browser: async (args) => runHostAutomation('browser', args),
15
+ 'jev-browser': async (args) => runHostAutomation('jev-browser', args),
12
16
  });
13
17
  process.exitCode = exitCode;
14
18
  }
@@ -0,0 +1,9 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ declare const TOOLS: {
3
+ readonly device: "agent-device";
4
+ readonly browser: "agent-browser";
5
+ readonly 'jev-browser': "jev-browser";
6
+ };
7
+ /** Forward unchanged arguments through Controller's queue, or its trusted NPS host context. */
8
+ export declare function runHostAutomation(command: keyof typeof TOOLS, args: string[], cwd?: string, invoke?: typeof spawnSync, gatewayExists?: (path: string) => boolean, env?: Record<string, string | undefined>): number;
9
+ export {};
@@ -0,0 +1,52 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { existsSync } from 'node:fs';
3
+ import { projectFromCwd } from "./supabase-local.js";
4
+ const TOOLS = {
5
+ device: 'agent-device',
6
+ browser: 'agent-browser',
7
+ 'jev-browser': 'jev-browser',
8
+ };
9
+ const NPS_BIN_ENV = {
10
+ device: 'SPECDEST_DEVKIT_AGENT_DEVICE_BIN',
11
+ browser: 'SPECDEST_DEVKIT_AGENT_BROWSER_BIN',
12
+ 'jev-browser': 'SPECDEST_DEVKIT_JEV_BROWSER_BIN',
13
+ };
14
+ /** Forward unchanged arguments through Controller's queue, or its trusted NPS host context. */
15
+ export function runHostAutomation(command, args, cwd = process.cwd(), invoke = spawnSync, gatewayExists = existsSync, env = process.env) {
16
+ const project = projectFromCwd(cwd);
17
+ if (!project) {
18
+ process.stderr.write('Controller project registration required.\n');
19
+ return 2;
20
+ }
21
+ if (!args.length) {
22
+ process.stderr.write(`Usage: specdest ${command} <subcommand> [args...]\n`);
23
+ return 2;
24
+ }
25
+ // NPS executes inside the Mac gateway worker. Re-enqueuing to that worker
26
+ // would deadlock, so use the trusted host path injected by Controller.
27
+ if (env.SPECDEST_DEVKIT_GATEWAY_NPS === '1') {
28
+ const binary = env[NPS_BIN_ENV[command]];
29
+ if (!binary?.startsWith('/') || !gatewayExists(binary)) {
30
+ process.stderr.write('Controller did not authorize this host automation binary.\n');
31
+ return 1;
32
+ }
33
+ const result = invoke(binary, args, { stdio: 'inherit', shell: false });
34
+ if (result.error)
35
+ process.stderr.write(`${result.error.message}\n`);
36
+ return result.error ? 1 : (result.status ?? 1);
37
+ }
38
+ const client = '/usr/local/bin/host-cli';
39
+ if (!gatewayExists(client)) {
40
+ process.stderr.write('Controller gateway client unavailable.\n');
41
+ return 1;
42
+ }
43
+ const result = invoke(client, ['devkit-automation', project, TOOLS[command], ...args], {
44
+ stdio: 'inherit',
45
+ shell: false,
46
+ });
47
+ if (result.error) {
48
+ process.stderr.write(`${result.error.message}\n`);
49
+ return 1;
50
+ }
51
+ return result.status ?? 1;
52
+ }
package/dist/npm/index.js CHANGED
@@ -11,8 +11,11 @@ export const COMMAND_NAMES = [
11
11
  'flow',
12
12
  'supabase',
13
13
  'slack',
14
+ 'device',
15
+ 'browser',
16
+ 'jev-browser',
14
17
  ];
15
- const HELP = `Usage: specdest <command> [options]\n\nCommands:\n status [--refresh] [--json] Show canonical applicability/install status\n add <package> Adopt/install a predefined package\n sync Refresh catalog/cache and install/update applicable rules\n check [--refresh] [--json] [--details] [--staged | --files <path...>] Run canonical checks, optionally targeted\n rules [options] Load applicable rule guidance for AI/task context\n ai-instruction Print the minimal AI bootstrap instruction\n doctor Diagnose project/cache setup\n flow <command> Manage local resumable development flow state\n supabase <status|start|stop> Local Supabase through restricted Controller\n slack send <files...> Upload files to configured Slack channel\n`;
18
+ const HELP = `Usage: specdest <command> [options]\n\nCommands:\n status [--refresh] [--json] Show canonical applicability/install status\n add <package> Adopt/install a predefined package\n sync Refresh catalog/cache and install/update applicable rules\n check [--refresh] [--json] [--details] [--staged | --files <path...>] Run canonical checks, optionally targeted\n rules [options] Load applicable rule guidance for AI/task context\n ai-instruction Print the minimal AI bootstrap instruction\n doctor Diagnose project/cache setup\n flow <command> Manage local resumable development flow state\n supabase <status|start|stop> Local Supabase through restricted Controller\n slack send <files...> Upload files to configured Slack channel\n device <args...> Forward to Controller agent-device\n browser <args...> Forward to Controller agent-browser\n jev-browser <args...> Forward to Controller jev-browser (if configured)\n`;
16
19
  export async function runCli(argv, io = process, handlers = {}) {
17
20
  const [command, ...args] = argv;
18
21
  if (!command || command === 'help' || command === '--help' || command === '-h') {
@@ -1,4 +1,7 @@
1
1
  import { spawn } from 'node:child_process';
2
+ import { readdirSync } from 'node:fs';
3
+ import { automationPolicyFindings } from "./automation-policy.js";
4
+ import { projectFromCwd } from "./supabase-local.js";
2
5
  import { clientOnlyBoundaryViolations } from "./client-only-boundary.js";
3
6
  import { readRuleProfile } from "./project-context.js";
4
7
  import { loadCanonicalProjectContext, prepareCanonicalManifest } from "./project-runtime.js";
@@ -80,6 +83,20 @@ export async function canonicalCheck(projectRoot, source, options = {}) {
80
83
  }
81
84
  const normalizedTargetFiles = (targetFiles ?? []).map((file) => String(file).replaceAll('\\', '/'));
82
85
  let exitCode = 0;
86
+ if (projectFromCwd(projectRoot)) {
87
+ const scripts = readdirSync(`${projectRoot}/scripts`, { recursive: true, withFileTypes: true })
88
+ .filter((entry) => entry.isFile())
89
+ .map((entry) => `scripts/${entry.parentPath.replace(`${projectRoot}/scripts/`, '')}/${entry.name}`.replace('scripts//', 'scripts/'));
90
+ const violations = automationPolicyFindings(projectRoot, ['package-scripts.yml', ...scripts]);
91
+ results['automation-gateway'] = {
92
+ status: violations.length ? 'fail' : 'pass',
93
+ exitCode: violations.length ? 1 : 0,
94
+ stderr: violations.join('\n'),
95
+ diagnostics: violations.map((message) => ({ message })),
96
+ };
97
+ if (violations.length)
98
+ exitCode = 1;
99
+ }
83
100
  const profile = await readRuleProfile(projectRoot);
84
101
  if (profile.capabilities.includes('client-only')) {
85
102
  const findings = await clientOnlyBoundaryViolations(projectRoot);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@specdest/devkit",
3
- "version": "0.4.13",
3
+ "version": "0.4.14",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "specdest": "dist/npm/cli.js",