@specdest/devkit 0.4.18 → 0.4.19
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 +4 -2
- package/dist/npm/cli.js +2 -0
- package/dist/npm/commands.d.ts +1 -0
- package/dist/npm/commands.js +15 -9
- package/dist/npm/github-doppler-secrets.d.ts +8 -0
- package/dist/npm/github-doppler-secrets.js +156 -0
- package/dist/npm/host-automation.js +22 -1
- package/dist/npm/index.js +2 -1
- package/dist/npm/predefined-packages/abac.js +30 -7
- package/dist/npm/predefined-packages/admin-ui-templates/AdminAccessAssignments.tsx.template +67 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminMembershipManager.tsx.template +56 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPermissionMatrix.tsx.template +54 -0
- package/dist/npm/predefined-packages/admin-ui-templates/AdminRoleManager.tsx.template +81 -0
- package/dist/npm/predefined-packages/admin-ui.js +5 -1
- package/dist/npm/predefined-packages/auth-templates/README.md.template +9 -0
- package/dist/npm/predefined-packages/auth-templates/convex.ts.template +18 -0
- package/dist/npm/predefined-packages/auth-templates/identity.ts.template +2 -0
- package/dist/npm/predefined-packages/auth-templates/supabase.ts.template +36 -0
- package/dist/npm/predefined-packages/auth.js +22 -7
- package/dist/npm/predefined-packages/multi-tenancy.js +21 -5
- package/dist/npm/predefined-packages/security-templates/README.md.template +15 -0
- package/dist/npm/predefined-packages/security-templates/convex-authorization.ts.template +109 -0
- package/dist/npm/predefined-packages/security-templates/permissions.ts.template +40 -0
- package/dist/npm/predefined-packages/security-templates/supabase-admin-rpc.sql.template +54 -0
- package/dist/npm/predefined-packages/security-templates/supabase-authorization.sql.template +138 -0
- package/dist/npm/predefined-packages/security-templates/supabase-posts-example.sql.template +39 -0
- package/dist/npm/predefined-packages/tenant-templates/README.md.template +11 -0
- package/dist/npm/predefined-packages/tenant-templates/tenant-context.ts.template +22 -0
- package/dist/npm/project-check.d.ts +12 -0
- package/dist/npm/project-check.js +54 -1
- package/dist/npm/supabase-local.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ The root package API is intentionally small: `runCli`, `COMMAND_NAMES`, `createC
|
|
|
16
16
|
npx @specdest/devkit status
|
|
17
17
|
npx @specdest/devkit add vite
|
|
18
18
|
npx @specdest/devkit sync
|
|
19
|
-
npx @specdest/devkit check [--refresh] [--json]
|
|
19
|
+
npx @specdest/devkit check [--refresh] [--json] [--details]
|
|
20
20
|
npx @specdest/devkit check --staged
|
|
21
21
|
npx @specdest/devkit check --files src/path/file.ts
|
|
22
22
|
npx @specdest/devkit rules
|
|
@@ -33,7 +33,7 @@ npx @specdest/devkit flow complete
|
|
|
33
33
|
- `add <package>` applies or adopts a predefined package recipe. Package recipes use only three relationship primitives: `requires`, `conflicts`, and environment-selected `variants`. `requires` is evaluated against packages registered in Devkit state; conflicts and variant selection also consider packages physically detected in the project. Status/doctor report stale package state, while sync/check/rules refuse to run against invalid package metadata. The supported foundational packages are `vite`, `expo`, `supabase`, and `convex`. Additional predefined packages are `auth`, `multi-tenancy`, `abac`, `sentry`, `logging`, `payments`, `shadcn`, `tanstack-router`, `tanstack-query`, `tanstack-form`, `storybook`, `playwright`, `vitest`, `local-logging`, `firebase-hosting`, `zod`, `tailwind`, `husky`, `nps`, `oxlint`, `oxfmt`, and `stryker`. Create-or-adopt recipes include the foundations (`vite`, `expo`, `supabase`, `convex`) and deterministic self-contained tooling (`zod`, `vitest`, `oxlint`, `oxfmt`, `husky`, `nps`, `tanstack-form`, `playwright`, `stryker`). They create minimal local dependencies/configuration when absent, then run `pnpm install`; when an integration already exists they adopt it without rewriting project-owned application files. Runtime-wired or product-specific recipes remain adoption-only until Devkit has a deterministic, product-neutral installation contract. Recipes record the recipe version separately from any detected dependency version in `.spd/installed.json`; Devkit does not invent product-specific auth, tenancy, authorization, logging, or payment architecture. Generated/adopted application code remains project-owned. Package lifecycle is deliberately fire-and-forget: there is no package `remove` or `upgrade` command. Developers remove packages manually; to update a recipe, re-run `add <package>`. Re-adding applies only the current recipe and does not remove files/settings that existed only in an older recipe. See [`docs/package-model.md`](docs/package-model.md). Supabase creation also scaffolds the canonical guarded declarative production-release workflow; registering Supabase activates the corresponding database rule/checker for ongoing enforcement. When Devkit-created foundation packages resolve a supported stack, required canonical setup packages are installed automatically (for example Oxlint/Husky for React stack gates and NPS for Supabase database commands); adopted stacks remain non-invasive and report missing setup through canonical checks.
|
|
34
34
|
- `add admin-ui` adopts an established shared admin page system or creates project-owned shadcn-based admin source components without overwriting existing files. See [`docs/admin-ui.md`](docs/admin-ui.md).
|
|
35
35
|
- `sync` refreshes the canonical catalog, downloads only missing rule-cache entries, installs missing applicable rules, and updates outdated ones.
|
|
36
|
-
- `check` executes each distinct canonical checker implementation once from the local Devkit cache and projects that result onto every rule backed by that checker. Use `--refresh` to refresh the canonical catalog/checker cache first without reconciling project files. `--staged` resolves target paths/content from the Git index; `--files` supplies explicit project-relative paths. Repository-scoped checkers still run globally. Targeted checks are ephemeral and do not update `.spd/state.json`; only a full check records canonical project status.
|
|
36
|
+
- `check` executes each distinct canonical checker implementation once from the local Devkit cache and projects that result onto every rule backed by that checker. Default output stays concise. Use `--details` to print normalized checker diagnostics (including file/line/column when the checker emits them), and `--json` for structured results with `diagnostics[]`. Use `--refresh` to refresh the canonical catalog/checker cache first without reconciling project files. `--staged` resolves target paths/content from the Git index; `--files` supplies explicit project-relative paths. Repository-scoped checkers still run globally. Targeted checks are ephemeral and do not update `.spd/state.json`; only a full check records canonical project status.
|
|
37
37
|
- `rules` loads AI-facing guidance without dumping the whole catalog. Use `--id <rule>`, `--category <category>`, `--failed`, or `--json`; with no selector it returns only rules marked `ai.load = "always"`.
|
|
38
38
|
- `doctor` reports project-stack/cache setup problems.
|
|
39
39
|
- `flow` manages local, resumable development state under `.spd/`. Canonical workflows are fixed: Feature/Fix use `plan → implement → verify → complete`; Inspect uses `plan → complete`. Use `--task <id>` when multiple tasks exist and `--context-file flow-notes/<task>.md` only when rich working context is needed. `flow verify` runs the repository's existing `.husky/pre-push` gate when present, otherwise its package `check` script; completion requires a successful, still-current verification. Runtime state is local-only and removed on completion.
|
|
@@ -83,3 +83,5 @@ mode `0600` recommended). The Slack app needs `chat:write` and `files:write`
|
|
|
83
83
|
scopes and membership in the target channel. The command creates one parent
|
|
84
84
|
message and uploads the files as threaded attachments unless `--thread` is
|
|
85
85
|
provided. Missing configuration fails explicitly, with no channel prompt. See [`docs/slack-artifacts.md`](docs/slack-artifacts.md) for ownership boundaries, configuration, and retry semantics.
|
|
86
|
+
|
|
87
|
+
Snapshot migration design: [docs/supabase-masked-snapshot-migration.md](docs/supabase-masked-snapshot-migration.md). Production export remains disabled pending independent masking approval.
|
package/dist/npm/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { runSupabaseLocal } from "./supabase-local.js";
|
|
|
5
5
|
import { sendSlackFiles } from "./slack.js";
|
|
6
6
|
import { runHostAutomation } from "./host-automation.js";
|
|
7
7
|
import { runSnapshot } from "./snapshot-cli.js";
|
|
8
|
+
import { runGitHubDopplerSecrets } from "./github-doppler-secrets.js";
|
|
8
9
|
import { assertStandaloneDevkit } from "./project-install-guard.js";
|
|
9
10
|
try {
|
|
10
11
|
assertStandaloneDevkit();
|
|
@@ -17,6 +18,7 @@ try {
|
|
|
17
18
|
browser: async (args) => runHostAutomation('browser', args),
|
|
18
19
|
'jev-browser': async (args) => runHostAutomation('jev-browser', args),
|
|
19
20
|
snapshot: runSnapshot,
|
|
21
|
+
secrets: runGitHubDopplerSecrets,
|
|
20
22
|
});
|
|
21
23
|
process.exitCode = exitCode;
|
|
22
24
|
}
|
package/dist/npm/commands.d.ts
CHANGED
package/dist/npm/commands.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createCanonicalSource } from "./canonical-source.js";
|
|
2
|
-
import { canonicalCheck } from "./project-check.js";
|
|
2
|
+
import { canonicalCheck, formatCheckerDiagnostics } from "./project-check.js";
|
|
3
3
|
import { aiInstructionText, canonicalRules } from "./project-rules.js";
|
|
4
4
|
import { canonicalDoctor, canonicalStatus } from "./project-status.js";
|
|
5
5
|
import { addPredefinedPackage } from "./predefined-packages/index.js";
|
|
@@ -15,6 +15,7 @@ export function checkFlags(args) {
|
|
|
15
15
|
const result = {
|
|
16
16
|
refresh: false,
|
|
17
17
|
json: false,
|
|
18
|
+
details: false,
|
|
18
19
|
mode: 'full',
|
|
19
20
|
files: null,
|
|
20
21
|
};
|
|
@@ -24,6 +25,8 @@ export function checkFlags(args) {
|
|
|
24
25
|
result.refresh = true;
|
|
25
26
|
else if (arg === '--json')
|
|
26
27
|
result.json = true;
|
|
28
|
+
else if (arg === '--details')
|
|
29
|
+
result.details = true;
|
|
27
30
|
else
|
|
28
31
|
remaining.push(arg);
|
|
29
32
|
}
|
|
@@ -31,14 +34,14 @@ export function checkFlags(args) {
|
|
|
31
34
|
throw new Error('Use either --staged or --files, not both');
|
|
32
35
|
if (remaining.includes('--staged')) {
|
|
33
36
|
if (remaining.length !== 1)
|
|
34
|
-
throw new Error('Usage: specdest check [--refresh] [--json] [--staged | --files <path...>]');
|
|
37
|
+
throw new Error('Usage: specdest check [--refresh] [--json] [--details] [--staged | --files <path...>]');
|
|
35
38
|
result.mode = 'staged';
|
|
36
39
|
return result;
|
|
37
40
|
}
|
|
38
41
|
const filesIndex = remaining.indexOf('--files');
|
|
39
42
|
if (filesIndex >= 0) {
|
|
40
43
|
if (filesIndex !== 0 || remaining.length < 2)
|
|
41
|
-
throw new Error('Usage: specdest check [--refresh] [--json] [--staged | --files <path...>]');
|
|
44
|
+
throw new Error('Usage: specdest check [--refresh] [--json] [--details] [--staged | --files <path...>]');
|
|
42
45
|
result.mode = 'files';
|
|
43
46
|
result.files = remaining.slice(1);
|
|
44
47
|
return result;
|
|
@@ -140,12 +143,15 @@ export function createCanonicalCommandHandlers(projectRoot = process.cwd(), opti
|
|
|
140
143
|
for (const [id, check] of Object.entries(result.results)) {
|
|
141
144
|
io.stdout.write(`${check.status.toUpperCase()} ${id}\n`);
|
|
142
145
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
if (parsed.details) {
|
|
147
|
+
for (const execution of result.executions.filter((item) => item.exitCode !== 0)) {
|
|
148
|
+
io.stderr.write(`\nChecker failure (${execution.ids.join(', ')}):\n`);
|
|
149
|
+
const details = formatCheckerDiagnostics(execution.diagnostics);
|
|
150
|
+
if (details)
|
|
151
|
+
io.stderr.write(details);
|
|
152
|
+
else
|
|
153
|
+
io.stderr.write(' Checker failed without diagnostic output.\n');
|
|
154
|
+
}
|
|
149
155
|
}
|
|
150
156
|
return result.exitCode;
|
|
151
157
|
},
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type Runner = (binary: string, args: string[], input?: string) => {
|
|
2
|
+
status: number | null;
|
|
3
|
+
stdout: string;
|
|
4
|
+
error?: Error;
|
|
5
|
+
};
|
|
6
|
+
type Output = Pick<typeof process, 'stdout' | 'stderr'>;
|
|
7
|
+
export declare function runGitHubDopplerSecrets(args: string[], io?: Output, runner?: Runner): Promise<number>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
const realRunner = (binary, args, input) => {
|
|
3
|
+
const result = spawnSync(binary, args, {
|
|
4
|
+
encoding: 'utf8',
|
|
5
|
+
...(input !== undefined ? { input } : {}),
|
|
6
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
7
|
+
timeout: 30_000,
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
status: result.status,
|
|
11
|
+
stdout: result.stdout ?? '',
|
|
12
|
+
...(result.error ? { error: result.error } : {}),
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
const HELP = [
|
|
16
|
+
'Usage:',
|
|
17
|
+
' specdest secrets github check --repo OWNER/REPO --project PROJECT --config CONFIG (--name KEY ... | --all)',
|
|
18
|
+
' specdest secrets github push --repo OWNER/REPO --project PROJECT --config CONFIG (--name KEY ... | --all) [--apply] [--confirm-all]',
|
|
19
|
+
'',
|
|
20
|
+
'check compares names/presence only; GitHub never returns secret values.',
|
|
21
|
+
'push defaults to dry-run; --apply replaces selected GitHub Actions secrets from Doppler.',
|
|
22
|
+
'--all --apply requires --confirm-all. One-way Doppler to GitHub only; reverse sync is deliberately unsupported.',
|
|
23
|
+
].join('\n') + '\n';
|
|
24
|
+
function parse(args) {
|
|
25
|
+
const [provider, operation, ...rest] = args;
|
|
26
|
+
if (provider !== 'github' || (operation !== 'check' && operation !== 'push')) {
|
|
27
|
+
throw new Error(HELP);
|
|
28
|
+
}
|
|
29
|
+
const flags = new Map();
|
|
30
|
+
const names = [];
|
|
31
|
+
let all = false;
|
|
32
|
+
let apply = false;
|
|
33
|
+
let confirmAll = false;
|
|
34
|
+
for (let i = 0; i < rest.length; i++) {
|
|
35
|
+
const flag = rest[i];
|
|
36
|
+
if (flag === '--all')
|
|
37
|
+
all = true;
|
|
38
|
+
else if (flag === '--apply')
|
|
39
|
+
apply = true;
|
|
40
|
+
else if (flag === '--confirm-all')
|
|
41
|
+
confirmAll = true;
|
|
42
|
+
else if (['--repo', '--project', '--config', '--name'].includes(flag ?? '')) {
|
|
43
|
+
const value = rest[++i];
|
|
44
|
+
if (!value || value.startsWith('--'))
|
|
45
|
+
throw new Error('Missing value for ' + flag);
|
|
46
|
+
if (flag === '--name')
|
|
47
|
+
names.push(value);
|
|
48
|
+
else
|
|
49
|
+
flags.set(flag, value);
|
|
50
|
+
}
|
|
51
|
+
else
|
|
52
|
+
throw new Error('Unknown option: ' + flag);
|
|
53
|
+
}
|
|
54
|
+
const repo = flags.get('--repo') ?? '';
|
|
55
|
+
const project = flags.get('--project') ?? '';
|
|
56
|
+
const config = flags.get('--config') ?? '';
|
|
57
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(repo) ||
|
|
58
|
+
!/^[\w.-]+$/.test(project) ||
|
|
59
|
+
!/^[\w.-]+$/.test(config) ||
|
|
60
|
+
all === names.length > 0) {
|
|
61
|
+
throw new Error(HELP);
|
|
62
|
+
}
|
|
63
|
+
if (names.some((name) => !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name))) {
|
|
64
|
+
throw new Error('Invalid GitHub secret name.');
|
|
65
|
+
}
|
|
66
|
+
if (operation === 'check' && (apply || confirmAll))
|
|
67
|
+
throw new Error('check is read-only.');
|
|
68
|
+
if (confirmAll && (!all || !apply))
|
|
69
|
+
throw new Error('--confirm-all requires --all --apply.');
|
|
70
|
+
return { operation, repo, project, config, names: [...new Set(names)], all, apply, confirmAll };
|
|
71
|
+
}
|
|
72
|
+
function execute(runner, binary, args, input) {
|
|
73
|
+
const result = runner(binary, args, input);
|
|
74
|
+
if (result.status !== 0 || result.error) {
|
|
75
|
+
// Provider stderr can contain credential values or token-bearing URLs.
|
|
76
|
+
throw new Error(binary + ' failed. Check local authentication and permissions.');
|
|
77
|
+
}
|
|
78
|
+
return result.stdout;
|
|
79
|
+
}
|
|
80
|
+
export async function runGitHubDopplerSecrets(args, io = process, runner = realRunner) {
|
|
81
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
82
|
+
io.stdout.write(HELP);
|
|
83
|
+
return 0;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const options = parse(args);
|
|
87
|
+
if (options.operation === 'push' && options.all && options.apply && !options.confirmAll) {
|
|
88
|
+
throw new Error('Bulk overwrite requires --confirm-all.');
|
|
89
|
+
}
|
|
90
|
+
const rawNames = execute(runner, 'doppler', [
|
|
91
|
+
'secrets',
|
|
92
|
+
'--only-names',
|
|
93
|
+
'--json',
|
|
94
|
+
'--project',
|
|
95
|
+
options.project,
|
|
96
|
+
'--config',
|
|
97
|
+
options.config,
|
|
98
|
+
]);
|
|
99
|
+
const nameData = JSON.parse(rawNames);
|
|
100
|
+
if (typeof nameData !== 'object' || nameData === null || Array.isArray(nameData)) {
|
|
101
|
+
throw new Error('Unexpected Doppler secret names response.');
|
|
102
|
+
}
|
|
103
|
+
const names = Object.keys(nameData);
|
|
104
|
+
const selected = options.all ? names.sort() : options.names;
|
|
105
|
+
if (!selected.length || selected.some((key) => !names.includes(key))) {
|
|
106
|
+
throw new Error('Selected Doppler secret names are missing.');
|
|
107
|
+
}
|
|
108
|
+
const restricted = selected.find((key) => !/^[A-Za-z_][A-Za-z0-9_]*$/.test(key) || /^DOPPLER_/.test(key) || key === 'GITHUB_TOKEN');
|
|
109
|
+
if (restricted) {
|
|
110
|
+
throw new Error('Reserved or invalid GitHub secret name selected: ' + restricted);
|
|
111
|
+
}
|
|
112
|
+
const listing = execute(runner, 'gh', ['secret', 'list', '--repo', options.repo]);
|
|
113
|
+
const githubNames = new Set(listing
|
|
114
|
+
.split('\n')
|
|
115
|
+
.map((line) => line.trim().split(/\s+/)[0])
|
|
116
|
+
.filter(Boolean));
|
|
117
|
+
for (const key of selected) {
|
|
118
|
+
io.stdout.write(key + ': ' + (githubNames.has(key) ? 'present (value uncheckable)' : 'missing') + '\n');
|
|
119
|
+
}
|
|
120
|
+
if (options.operation === 'check')
|
|
121
|
+
return selected.every((key) => githubNames.has(key)) ? 0 : 1;
|
|
122
|
+
if (!options.apply) {
|
|
123
|
+
io.stdout.write('DRY RUN: no GitHub secrets changed. Add --apply to overwrite selected values.\n');
|
|
124
|
+
return 0;
|
|
125
|
+
}
|
|
126
|
+
// Retrieve values only for a caller-authorized write; never for check/dry-run.
|
|
127
|
+
const rawValues = execute(runner, 'doppler', [
|
|
128
|
+
'secrets',
|
|
129
|
+
'download',
|
|
130
|
+
'--no-file',
|
|
131
|
+
'--format',
|
|
132
|
+
'json',
|
|
133
|
+
'--project',
|
|
134
|
+
options.project,
|
|
135
|
+
'--config',
|
|
136
|
+
options.config,
|
|
137
|
+
]);
|
|
138
|
+
const valueData = JSON.parse(rawValues);
|
|
139
|
+
if (typeof valueData !== 'object' || valueData === null || Array.isArray(valueData)) {
|
|
140
|
+
throw new Error('Unexpected Doppler values response.');
|
|
141
|
+
}
|
|
142
|
+
const values = valueData;
|
|
143
|
+
if (selected.some((key) => typeof values[key] !== 'string')) {
|
|
144
|
+
throw new Error('Selected Doppler values are unavailable.');
|
|
145
|
+
}
|
|
146
|
+
for (const key of selected) {
|
|
147
|
+
execute(runner, 'gh', ['secret', 'set', key, '--repo', options.repo], values[key]);
|
|
148
|
+
io.stdout.write(key + ': updated\n');
|
|
149
|
+
}
|
|
150
|
+
return 0;
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
io.stderr.write((error instanceof Error ? error.message : 'Secret sync failed.') + '\n');
|
|
154
|
+
return 2;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -27,7 +27,28 @@ export function runHostAutomation(command, args, cwd = process.cwd(), invoke = s
|
|
|
27
27
|
return false;
|
|
28
28
|
}
|
|
29
29
|
})();
|
|
30
|
-
const
|
|
30
|
+
const agentManifest = resolve(cwd, 'agent/Cargo.toml');
|
|
31
|
+
const isWorkIntelligence = basename(resolve(cwd)) === 'work-intelligence-agent' &&
|
|
32
|
+
existsSync(agentManifest) &&
|
|
33
|
+
/^name\s*=\s*"work-intelligence-agent"\s*$/mu.test(readFileSync(agentManifest, 'utf8'));
|
|
34
|
+
const isCorporateSite = basename(resolve(cwd)) === 'specdest-lp' &&
|
|
35
|
+
existsSync(adminManifest) &&
|
|
36
|
+
(() => {
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(readFileSync(adminManifest, 'utf8')).name === 'specdest-corporate-site';
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
})();
|
|
44
|
+
const project = projectFromCwd(cwd) ??
|
|
45
|
+
(isAdmin
|
|
46
|
+
? 'mycone-admin'
|
|
47
|
+
: isWorkIntelligence
|
|
48
|
+
? 'work-intelligence-agent'
|
|
49
|
+
: isCorporateSite
|
|
50
|
+
? 'specdest-lp'
|
|
51
|
+
: undefined);
|
|
31
52
|
if (!project) {
|
|
32
53
|
process.stderr.write('Controller project registration required.\n');
|
|
33
54
|
return 2;
|
package/dist/npm/index.js
CHANGED
|
@@ -15,8 +15,9 @@ export const COMMAND_NAMES = [
|
|
|
15
15
|
'browser',
|
|
16
16
|
'jev-browser',
|
|
17
17
|
'snapshot',
|
|
18
|
+
'secrets',
|
|
18
19
|
];
|
|
19
|
-
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 snapshot verify <directory> Verify an offline snapshot bundle\n`;
|
|
20
|
+
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 snapshot verify <directory> Verify an offline snapshot bundle\n secrets github <check|push> Compare presence or explicitly sync Doppler secrets to GitHub\n`;
|
|
20
21
|
export async function runCli(argv, io = process, handlers = {}) {
|
|
21
22
|
const [command, ...args] = argv;
|
|
22
23
|
if (!command || command === 'help' || command === '--help' || command === '-h') {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { writeProjectFileIfMissing } from "./install.js";
|
|
1
3
|
import { detectAnyPath } from "./project-signals.js";
|
|
2
4
|
export const abacRecipe = {
|
|
3
5
|
id: 'abac',
|
|
4
|
-
recipeVersion: '1.
|
|
6
|
+
recipeVersion: '1.4.0',
|
|
5
7
|
role: 'feature',
|
|
6
8
|
requires: ['auth'],
|
|
7
9
|
variants: [
|
|
@@ -11,12 +13,33 @@ export const abacRecipe = {
|
|
|
11
13
|
async detect(projectRoot) {
|
|
12
14
|
return await detectAnyPath(projectRoot, ['src/lib/permissions.ts', 'src/permissions', 'src/policies', 'src/features/permissions'], 'ABAC policy integration was not detected');
|
|
13
15
|
},
|
|
14
|
-
async apply(
|
|
15
|
-
if (
|
|
16
|
-
|
|
16
|
+
async apply(root, detection, resolution) {
|
|
17
|
+
if (detection.present) {
|
|
18
|
+
if (!detection.compatible)
|
|
19
|
+
throw new Error(detection.reason ?? 'Existing ABAC integration is not compatible.');
|
|
20
|
+
return { source: 'adopted' };
|
|
17
21
|
}
|
|
18
|
-
if (!
|
|
19
|
-
throw new Error(
|
|
20
|
-
|
|
22
|
+
if (!resolution.variant)
|
|
23
|
+
throw new Error('ABAC requires an identified backend.');
|
|
24
|
+
const variantTemplate = resolution.variant === 'supabase'
|
|
25
|
+
? 'supabase-authorization.sql'
|
|
26
|
+
: 'convex-authorization.ts';
|
|
27
|
+
const files = [
|
|
28
|
+
{ source: 'permissions.ts', destination: 'src/lib/permissions.ts' },
|
|
29
|
+
{ source: variantTemplate, destination: resolution.variant === 'convex' ? 'convex/authorization.ts' : 'docs/security/' + variantTemplate },
|
|
30
|
+
...(resolution.variant === 'supabase' ? [
|
|
31
|
+
{ source: 'supabase-posts-example.sql', destination: 'docs/security/supabase-posts-example.sql' },
|
|
32
|
+
{ source: 'supabase-admin-rpc.sql', destination: 'docs/security/supabase-admin-rpc.sql' },
|
|
33
|
+
] : []),
|
|
34
|
+
{ source: 'README.md', destination: 'docs/security/README.md' },
|
|
35
|
+
];
|
|
36
|
+
// Templates are intentionally references until schema-specific backend enforcement is wired.
|
|
37
|
+
const content = await Promise.all(files.map(async (file) => ({
|
|
38
|
+
destination: file.destination,
|
|
39
|
+
text: await readFile(new URL('./security-templates/' + file.source + '.template', import.meta.url), 'utf8'),
|
|
40
|
+
})));
|
|
41
|
+
for (const file of content)
|
|
42
|
+
await writeProjectFileIfMissing(root, file.destination, file.text);
|
|
43
|
+
return { source: 'installed' };
|
|
21
44
|
},
|
|
22
45
|
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export type AccessSubject = { id: string; label: string };
|
|
4
|
+
export type AccessAssignment = {
|
|
5
|
+
subjectType: 'user' | 'group';
|
|
6
|
+
subjectId: string;
|
|
7
|
+
roleId: string;
|
|
8
|
+
tenantId: string | null;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type Props = {
|
|
12
|
+
users: readonly AccessSubject[];
|
|
13
|
+
groups: readonly AccessSubject[];
|
|
14
|
+
roles: readonly AccessSubject[];
|
|
15
|
+
assignments: readonly AccessAssignment[];
|
|
16
|
+
tenantId: string | null;
|
|
17
|
+
onAssign: (assignment: AccessAssignment) => void;
|
|
18
|
+
onRevoke: (assignment: AccessAssignment) => void;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Presentation-only role assignment editor. Authorization belongs in the mutation backend. */
|
|
23
|
+
export function AdminAccessAssignments({ users, groups, roles, assignments, tenantId, onAssign, onRevoke, disabled = false }: Props) {
|
|
24
|
+
const [subjectType, setSubjectType] = useState<'user' | 'group'>('user');
|
|
25
|
+
const [subjectId, setSubjectId] = useState('');
|
|
26
|
+
const [roleId, setRoleId] = useState('');
|
|
27
|
+
const [query, setQuery] = useState('');
|
|
28
|
+
const subjects = subjectType === 'user' ? users : groups;
|
|
29
|
+
const eligible = assignments.filter((entry) => entry.tenantId === tenantId);
|
|
30
|
+
const labelFor = (assignment: AccessAssignment) =>
|
|
31
|
+
(assignment.subjectType === 'user' ? users : groups).find((item) => item.id === assignment.subjectId)?.label ?? assignment.subjectId;
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<section aria-label="Role assignments" className="space-y-4">
|
|
35
|
+
<form className="flex flex-wrap gap-2" onSubmit={(event) => {
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
if (disabled || !subjectId || !roleId) return;
|
|
38
|
+
const assignment: AccessAssignment = { subjectType, subjectId, roleId, tenantId };
|
|
39
|
+
if (!eligible.some((entry) => entry.subjectType === subjectType && entry.subjectId === subjectId && entry.roleId === roleId)) onAssign(assignment);
|
|
40
|
+
}}>
|
|
41
|
+
<select aria-label="Subject type" className="rounded-md border p-2" value={subjectType}
|
|
42
|
+
onChange={(event) => { setSubjectType(event.target.value === 'group' ? 'group' : 'user'); setSubjectId(''); }} disabled={disabled}>
|
|
43
|
+
<option value="user">User</option><option value="group">Group</option>
|
|
44
|
+
</select>
|
|
45
|
+
<select aria-label="Subject" className="rounded-md border p-2" value={subjectId} required onChange={(event) => setSubjectId(event.target.value)} disabled={disabled}>
|
|
46
|
+
<option value="">Select subject</option>
|
|
47
|
+
{subjects.map((item) => <option key={item.id} value={item.id}>{item.label}</option>)}
|
|
48
|
+
</select>
|
|
49
|
+
<select aria-label="Role" className="rounded-md border p-2" value={roleId} required onChange={(event) => setRoleId(event.target.value)} disabled={disabled}>
|
|
50
|
+
<option value="">Select role</option>
|
|
51
|
+
{roles.map((item) => <option key={item.id} value={item.id}>{item.label}</option>)}
|
|
52
|
+
</select>
|
|
53
|
+
<button type="submit" className="rounded-md border px-3" disabled={disabled || !subjectId || !roleId}>Assign role</button>
|
|
54
|
+
</form>
|
|
55
|
+
<input aria-label="Filter assignments" className="rounded-md border p-2" value={query} onChange={(event) => setQuery(event.target.value)} />
|
|
56
|
+
<ul className="space-y-2">
|
|
57
|
+
{eligible.filter((entry) => `${labelFor(entry)} ${roles.find((role) => role.id === entry.roleId)?.label ?? entry.roleId}`.toLowerCase().includes(query.toLowerCase()))
|
|
58
|
+
.map((entry) => (
|
|
59
|
+
<li key={`${entry.subjectType}:${entry.subjectId}:${entry.roleId}`} className="flex flex-wrap items-center justify-between gap-2 rounded-md border p-2">
|
|
60
|
+
<span>{entry.subjectType}: {labelFor(entry)} — {roles.find((role) => role.id === entry.roleId)?.label ?? entry.roleId}</span>
|
|
61
|
+
<button type="button" className="rounded-md border px-3 py-1" disabled={disabled} onClick={() => onRevoke(entry)}>Revoke</button>
|
|
62
|
+
</li>
|
|
63
|
+
))}
|
|
64
|
+
</ul>
|
|
65
|
+
</section>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export type MembershipSubject = { id: string; label: string };
|
|
4
|
+
export type ManagedMembership = { userId: string; containerId: string };
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
kind: 'tenant' | 'group';
|
|
8
|
+
users: readonly MembershipSubject[];
|
|
9
|
+
containers: readonly MembershipSubject[];
|
|
10
|
+
memberships: readonly ManagedMembership[];
|
|
11
|
+
onAdd: (membership: ManagedMembership) => void;
|
|
12
|
+
onRemove: (membership: ManagedMembership) => void;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Only use with backend-authorized mutations and server-sourced memberships. */
|
|
17
|
+
export function AdminMembershipManager({ kind, users, containers, memberships, onAdd, onRemove, disabled = false }: Props) {
|
|
18
|
+
const [userId, setUserId] = useState('');
|
|
19
|
+
const [containerId, setContainerId] = useState('');
|
|
20
|
+
const [query, setQuery] = useState('');
|
|
21
|
+
const subjectName = (id: string) => users.find((user) => user.id === id)?.label ?? id;
|
|
22
|
+
const containerName = (id: string) => containers.find((item) => item.id === id)?.label ?? id;
|
|
23
|
+
const eligible = memberships.filter((item) =>
|
|
24
|
+
`${subjectName(item.userId)} ${containerName(item.containerId)}`.toLowerCase().includes(query.toLowerCase()));
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<section aria-label={`${kind} memberships`} className="space-y-4">
|
|
28
|
+
<form className="flex flex-wrap gap-2" onSubmit={(event) => {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
if (disabled || !userId || !containerId) return;
|
|
31
|
+
if (!memberships.some((item) => item.userId === userId && item.containerId === containerId)) {
|
|
32
|
+
onAdd({ userId, containerId });
|
|
33
|
+
}
|
|
34
|
+
}}>
|
|
35
|
+
<select className="rounded-md border p-2" aria-label="User" value={userId} disabled={disabled} required onChange={(event) => setUserId(event.target.value)}>
|
|
36
|
+
<option value="">Select user</option>
|
|
37
|
+
{users.map((user) => <option key={user.id} value={user.id}>{user.label}</option>)}
|
|
38
|
+
</select>
|
|
39
|
+
<select className="rounded-md border p-2" aria-label={kind === 'tenant' ? 'Tenant' : 'Group'} value={containerId} disabled={disabled} required onChange={(event) => setContainerId(event.target.value)}>
|
|
40
|
+
<option value="">Select {kind}</option>
|
|
41
|
+
{containers.map((item) => <option key={item.id} value={item.id}>{item.label}</option>)}
|
|
42
|
+
</select>
|
|
43
|
+
<button type="submit" className="rounded-md border px-3" disabled={disabled || !userId || !containerId}>Add membership</button>
|
|
44
|
+
</form>
|
|
45
|
+
<input aria-label="Search memberships" className="rounded-md border p-2" value={query} onChange={(event) => setQuery(event.target.value)} />
|
|
46
|
+
<ul className="space-y-2">
|
|
47
|
+
{eligible.map((item) => (
|
|
48
|
+
<li key={`${item.containerId}:${item.userId}`} className="flex flex-wrap items-center justify-between gap-2 rounded-md border p-2">
|
|
49
|
+
<span>{subjectName(item.userId)} — {containerName(item.containerId)}</span>
|
|
50
|
+
<button type="button" className="rounded-md border px-3 py-1" disabled={disabled} onClick={() => onRemove(item)}>Remove</button>
|
|
51
|
+
</li>
|
|
52
|
+
))}
|
|
53
|
+
</ul>
|
|
54
|
+
</section>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
|
2
|
+
|
|
3
|
+
export type PermissionCell = { resource: string; action: string; scope: 'any' | 'own' };
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
resources: readonly string[];
|
|
7
|
+
actions: readonly string[];
|
|
8
|
+
value: readonly PermissionCell[];
|
|
9
|
+
onChange: (next: PermissionCell[]) => void;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Presentation only. Saving grants must be authorized and validated server-side. */
|
|
14
|
+
export function AdminPermissionMatrix({ resources, actions, value, onChange, disabled = false }: Props) {
|
|
15
|
+
return (
|
|
16
|
+
<div className="w-full min-w-0 overflow-x-auto rounded-lg border">
|
|
17
|
+
<Table>
|
|
18
|
+
<TableHeader>
|
|
19
|
+
<TableRow>
|
|
20
|
+
<TableHead>Resource</TableHead>
|
|
21
|
+
{actions.flatMap((action) => [
|
|
22
|
+
<TableHead key={`${action}:any`}>{action}</TableHead>,
|
|
23
|
+
<TableHead key={`${action}:own`}>{action} own</TableHead>,
|
|
24
|
+
])}
|
|
25
|
+
</TableRow>
|
|
26
|
+
</TableHeader>
|
|
27
|
+
<TableBody>
|
|
28
|
+
{resources.map((resource) => (
|
|
29
|
+
<TableRow key={resource}>
|
|
30
|
+
<TableCell className="font-medium">{resource}</TableCell>
|
|
31
|
+
{actions.flatMap((action) => (['any', 'own'] as const).map((scope) => {
|
|
32
|
+
const selected = value.some((item) => item.resource === resource && item.action === action && item.scope === scope);
|
|
33
|
+
return (
|
|
34
|
+
<TableCell key={`${action}:${scope}`}>
|
|
35
|
+
<input
|
|
36
|
+
type="checkbox"
|
|
37
|
+
aria-label={`${resource} ${action} ${scope}`}
|
|
38
|
+
checked={selected}
|
|
39
|
+
disabled={disabled}
|
|
40
|
+
onChange={(event) => {
|
|
41
|
+
const next = value.filter((item) => !(item.resource === resource && item.action === action && item.scope === scope));
|
|
42
|
+
onChange(event.target.checked ? [...next, { resource, action, scope }] : next);
|
|
43
|
+
}}
|
|
44
|
+
/>
|
|
45
|
+
</TableCell>
|
|
46
|
+
);
|
|
47
|
+
}))}
|
|
48
|
+
</TableRow>
|
|
49
|
+
))}
|
|
50
|
+
</TableBody>
|
|
51
|
+
</Table>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { AdminPermissionMatrix, type PermissionCell } from './AdminPermissionMatrix';
|
|
3
|
+
import { AdminConfirmDialog } from './AdminConfirmDialog';
|
|
4
|
+
|
|
5
|
+
export type ManagedRole = {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
tenantId: string | null;
|
|
9
|
+
permissions: readonly PermissionCell[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
roles: readonly ManagedRole[];
|
|
14
|
+
tenantId: string | null;
|
|
15
|
+
resources: readonly string[];
|
|
16
|
+
actions: readonly string[];
|
|
17
|
+
onCreate: (name: string, tenantId: string | null) => void;
|
|
18
|
+
onRename: (roleId: string, name: string) => void;
|
|
19
|
+
onDelete: (roleId: string) => void;
|
|
20
|
+
onPermissionsChange: (roleId: string, permissions: PermissionCell[]) => void;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** All callbacks must call trusted, admin-authorized server handlers. */
|
|
25
|
+
export function AdminRoleManager({
|
|
26
|
+
roles, tenantId, resources, actions, onCreate, onRename, onDelete, onPermissionsChange,
|
|
27
|
+
disabled = false,
|
|
28
|
+
}: Props) {
|
|
29
|
+
const [query, setQuery] = useState('');
|
|
30
|
+
const [name, setName] = useState('');
|
|
31
|
+
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
32
|
+
const visible = roles.filter((role) => role.tenantId === tenantId && role.name.toLowerCase().includes(query.toLowerCase()));
|
|
33
|
+
const selected = roles.find((role) => role.id === selectedId && role.tenantId === tenantId);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<section aria-label="Role management" className="space-y-4">
|
|
37
|
+
<header className="flex flex-wrap items-center gap-3">
|
|
38
|
+
<input aria-label="Search roles" className="rounded-md border p-2" value={query} onChange={(event) => setQuery(event.target.value)} />
|
|
39
|
+
<form onSubmit={(event) => {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
if (!disabled && name.trim()) {
|
|
42
|
+
onCreate(name.trim(), tenantId);
|
|
43
|
+
setName('');
|
|
44
|
+
}
|
|
45
|
+
}} className="flex gap-2">
|
|
46
|
+
<input aria-label="New role name" className="rounded-md border p-2" required value={name} onChange={(event) => setName(event.target.value)} disabled={disabled} />
|
|
47
|
+
<button className="rounded-md border px-3" type="submit" disabled={disabled || !name.trim()}>Create role</button>
|
|
48
|
+
</form>
|
|
49
|
+
</header>
|
|
50
|
+
<div className="flex flex-wrap gap-2">
|
|
51
|
+
{visible.map((role) => (
|
|
52
|
+
<button key={role.id} type="button" aria-pressed={selected?.id === role.id}
|
|
53
|
+
className="rounded-md border px-3 py-2 aria-pressed:bg-muted"
|
|
54
|
+
onClick={() => setSelectedId(role.id)}>{role.name}</button>
|
|
55
|
+
))}
|
|
56
|
+
{visible.length === 0 ? <p>No roles found</p> : null}
|
|
57
|
+
</div>
|
|
58
|
+
{selected ? (
|
|
59
|
+
<div className="space-y-4 rounded-lg border p-4" key={selected.id}>
|
|
60
|
+
<form className="flex flex-wrap gap-2" onSubmit={(event) => {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
const data = new FormData(event.currentTarget);
|
|
63
|
+
const nextName = data.get('roleName');
|
|
64
|
+
if (!disabled && typeof nextName === 'string' && nextName.trim()) onRename(selected.id, nextName.trim());
|
|
65
|
+
}}>
|
|
66
|
+
<input name="roleName" aria-label="Role name" defaultValue={selected.name} required className="rounded-md border p-2" disabled={disabled} />
|
|
67
|
+
<button type="submit" className="rounded-md border px-3" disabled={disabled}>Rename</button>
|
|
68
|
+
{!disabled ? <AdminConfirmDialog
|
|
69
|
+
trigger={<button type="button" className="rounded-md border px-3">Delete role</button>}
|
|
70
|
+
title="Delete role"
|
|
71
|
+
description={`Delete ${selected.name}? This may revoke user and group permissions.`}
|
|
72
|
+
onConfirm={() => { onDelete(selected.id); setSelectedId(null); }}
|
|
73
|
+
/> : null}
|
|
74
|
+
</form>
|
|
75
|
+
<AdminPermissionMatrix resources={resources} actions={actions} value={selected.permissions}
|
|
76
|
+
onChange={(permissions) => onPermissionsChange(selected.id, permissions)} disabled={disabled} />
|
|
77
|
+
</div>
|
|
78
|
+
) : null}
|
|
79
|
+
</section>
|
|
80
|
+
);
|
|
81
|
+
}
|