@kb-labs/infra-worker-core 0.5.0

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 ADDED
@@ -0,0 +1,19 @@
1
+ # @kb-labs/infra-worker-core
2
+
3
+ Core package for the KB Labs infra worker plugin.
4
+
5
+ Exports:
6
+ - V3 plugin manifest (`./plugin-manifest`)
7
+ - CLI command handlers under `src/cli/commands`
8
+
9
+ ## Commands
10
+
11
+ - `infra-worker:prepare`
12
+ - `infra-worker:capture-snapshot`
13
+ - `infra-worker:restore-snapshot`
14
+
15
+ ## Build
16
+
17
+ ```bash
18
+ pnpm --filter @kb-labs/infra-worker-core build
19
+ ```
@@ -0,0 +1,18 @@
1
+ import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
2
+
3
+ interface CaptureSnapshotFlags {
4
+ workspaceId?: string;
5
+ environmentId?: string;
6
+ namespace?: string;
7
+ sourcePath?: string;
8
+ }
9
+ interface CaptureSnapshotInput {
10
+ argv: string[];
11
+ flags: CaptureSnapshotFlags;
12
+ }
13
+ interface CaptureSnapshotResult {
14
+ snapshotId: string;
15
+ }
16
+ declare const _default: _kb_labs_shared_command_kit.CommandHandlerV3<unknown, CaptureSnapshotInput, CaptureSnapshotResult>;
17
+
18
+ export { _default as default };
@@ -0,0 +1,28 @@
1
+ import { defineCommand } from '@kb-labs/sdk';
2
+
3
+ // src/cli/commands/capture-snapshot.ts
4
+ var capture_snapshot_default = defineCommand({
5
+ id: "infra-worker:capture-snapshot",
6
+ description: "Capture snapshot from workspace/environment.",
7
+ handler: {
8
+ async execute(ctx, input) {
9
+ const flags = input.flags;
10
+ const snapshot = await ctx.api.snapshot.capture({
11
+ workspaceId: flags.workspaceId,
12
+ environmentId: flags.environmentId,
13
+ namespace: flags.namespace,
14
+ sourcePath: flags.sourcePath
15
+ });
16
+ const result = { snapshotId: snapshot.snapshotId };
17
+ ctx.ui.success(`Snapshot captured: ${result.snapshotId}`);
18
+ return {
19
+ exitCode: 0,
20
+ result
21
+ };
22
+ }
23
+ }
24
+ });
25
+
26
+ export { capture_snapshot_default as default };
27
+ //# sourceMappingURL=capture-snapshot.js.map
28
+ //# sourceMappingURL=capture-snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/cli/commands/capture-snapshot.ts"],"names":[],"mappings":";;;AAkBA,IAAO,2BAAQ,aAAA,CAAoE;AAAA,EACjF,EAAA,EAAI,+BAAA;AAAA,EACJ,WAAA,EAAa,8CAAA;AAAA,EACb,OAAA,EAAS;AAAA,IACP,MAAM,OAAA,CACJ,GAAA,EACA,KAAA,EAC+C;AAC/C,MAAA,MAAM,QAAQ,KAAA,CAAM,KAAA;AACpB,MAAA,MAAM,QAAA,GAAW,MAAM,GAAA,CAAI,GAAA,CAAI,SAAS,OAAA,CAAQ;AAAA,QAC9C,aAAa,KAAA,CAAM,WAAA;AAAA,QACnB,eAAe,KAAA,CAAM,aAAA;AAAA,QACrB,WAAW,KAAA,CAAM,SAAA;AAAA,QACjB,YAAY,KAAA,CAAM;AAAA,OACnB,CAAA;AAED,MAAA,MAAM,MAAA,GAAgC,EAAE,UAAA,EAAY,QAAA,CAAS,UAAA,EAAW;AACxE,MAAA,GAAA,CAAI,EAAA,CAAG,OAAA,CAAQ,CAAA,mBAAA,EAAsB,MAAA,CAAO,UAAU,CAAA,CAAE,CAAA;AAExD,MAAA,OAAO;AAAA,QACL,QAAA,EAAU,CAAA;AAAA,QACV;AAAA,OACF;AAAA,IACF;AAAA;AAEJ,CAAC","file":"capture-snapshot.js","sourcesContent":["import { defineCommand, type CommandResult, type PluginContextV3 } from '@kb-labs/sdk';\n\ninterface CaptureSnapshotFlags {\n workspaceId?: string;\n environmentId?: string;\n namespace?: string;\n sourcePath?: string;\n}\n\ninterface CaptureSnapshotInput {\n argv: string[];\n flags: CaptureSnapshotFlags;\n}\n\ninterface CaptureSnapshotResult {\n snapshotId: string;\n}\n\nexport default defineCommand<unknown, CaptureSnapshotInput, CaptureSnapshotResult>({\n id: 'infra-worker:capture-snapshot',\n description: 'Capture snapshot from workspace/environment.',\n handler: {\n async execute(\n ctx: PluginContextV3<unknown>,\n input: CaptureSnapshotInput\n ): Promise<CommandResult<CaptureSnapshotResult>> {\n const flags = input.flags;\n const snapshot = await ctx.api.snapshot.capture({\n workspaceId: flags.workspaceId,\n environmentId: flags.environmentId,\n namespace: flags.namespace,\n sourcePath: flags.sourcePath,\n });\n\n const result: CaptureSnapshotResult = { snapshotId: snapshot.snapshotId };\n ctx.ui.success(`Snapshot captured: ${result.snapshotId}`);\n\n return {\n exitCode: 0,\n result,\n };\n },\n },\n});\n"]}
@@ -0,0 +1,4 @@
1
+ export { default as prepareInfraCommand } from './prepare-infra.js';
2
+ export { default as captureSnapshotCommand } from './capture-snapshot.js';
3
+ export { default as restoreSnapshotCommand } from './restore-snapshot.js';
4
+ import '@kb-labs/shared-command-kit';
@@ -0,0 +1,142 @@
1
+ import { defineCommand } from '@kb-labs/sdk';
2
+
3
+ // src/cli/commands/prepare-infra.ts
4
+ function toBoolean(value) {
5
+ if (typeof value === "boolean") {
6
+ return value;
7
+ }
8
+ if (typeof value === "string") {
9
+ const normalized = value.trim().toLowerCase();
10
+ if (normalized === "true") {
11
+ return true;
12
+ }
13
+ if (normalized === "false") {
14
+ return false;
15
+ }
16
+ }
17
+ return void 0;
18
+ }
19
+ function toNumber(value) {
20
+ if (typeof value === "number" && Number.isFinite(value)) {
21
+ return value;
22
+ }
23
+ if (typeof value === "string" && value.trim().length > 0) {
24
+ const parsed = Number(value);
25
+ if (Number.isFinite(parsed)) {
26
+ return parsed;
27
+ }
28
+ }
29
+ return void 0;
30
+ }
31
+ var prepare_infra_default = defineCommand({
32
+ id: "infra-worker:prepare",
33
+ description: "Materialize workspace, optionally provision environment, optionally capture snapshot.",
34
+ handler: {
35
+ async execute(ctx, input) {
36
+ const flags = input.flags;
37
+ const createEnvironment = toBoolean(flags.createEnvironment) ?? false;
38
+ const captureSnapshot = toBoolean(flags.captureSnapshot) ?? false;
39
+ const ttlMs = toNumber(flags.ttlMs);
40
+ const workspace = await ctx.api.workspace.materialize({
41
+ sourceRef: flags.sourceRef,
42
+ basePath: flags.basePath
43
+ });
44
+ let environmentId;
45
+ if (createEnvironment) {
46
+ const environment = await ctx.api.environment.create({
47
+ templateId: flags.templateId,
48
+ ttlMs,
49
+ workspacePath: workspace.rootPath ?? flags.basePath
50
+ });
51
+ environmentId = environment.environmentId;
52
+ await ctx.api.workspace.attach({
53
+ workspaceId: workspace.workspaceId,
54
+ environmentId
55
+ });
56
+ }
57
+ let snapshotId;
58
+ if (captureSnapshot) {
59
+ const snapshot = await ctx.api.snapshot.capture({
60
+ workspaceId: workspace.workspaceId,
61
+ environmentId,
62
+ namespace: flags.namespace
63
+ });
64
+ snapshotId = snapshot.snapshotId;
65
+ }
66
+ const result = {
67
+ workspaceId: workspace.workspaceId,
68
+ environmentId,
69
+ snapshotId
70
+ };
71
+ ctx.ui.success("Infrastructure prepared", {
72
+ sections: [
73
+ {
74
+ header: "Identifiers",
75
+ items: [
76
+ `workspaceId: ${result.workspaceId}`,
77
+ `environmentId: ${result.environmentId ?? "-"}`,
78
+ `snapshotId: ${result.snapshotId ?? "-"}`
79
+ ]
80
+ }
81
+ ]
82
+ });
83
+ return {
84
+ exitCode: 0,
85
+ result
86
+ };
87
+ }
88
+ }
89
+ });
90
+ var capture_snapshot_default = defineCommand({
91
+ id: "infra-worker:capture-snapshot",
92
+ description: "Capture snapshot from workspace/environment.",
93
+ handler: {
94
+ async execute(ctx, input) {
95
+ const flags = input.flags;
96
+ const snapshot = await ctx.api.snapshot.capture({
97
+ workspaceId: flags.workspaceId,
98
+ environmentId: flags.environmentId,
99
+ namespace: flags.namespace,
100
+ sourcePath: flags.sourcePath
101
+ });
102
+ const result = { snapshotId: snapshot.snapshotId };
103
+ ctx.ui.success(`Snapshot captured: ${result.snapshotId}`);
104
+ return {
105
+ exitCode: 0,
106
+ result
107
+ };
108
+ }
109
+ }
110
+ });
111
+ var restore_snapshot_default = defineCommand({
112
+ id: "infra-worker:restore-snapshot",
113
+ description: "Restore snapshot to workspace/environment.",
114
+ handler: {
115
+ async execute(ctx, input) {
116
+ const flags = input.flags;
117
+ if (!flags.snapshotId) {
118
+ throw new Error("Missing required flag: snapshotId");
119
+ }
120
+ const restored = await ctx.api.snapshot.restore({
121
+ snapshotId: flags.snapshotId,
122
+ workspaceId: flags.workspaceId,
123
+ environmentId: flags.environmentId,
124
+ targetPath: flags.targetPath,
125
+ overwrite: flags.overwrite
126
+ });
127
+ const result = {
128
+ snapshotId: restored.snapshotId,
129
+ restoredAt: restored.restoredAt
130
+ };
131
+ ctx.ui.success(`Snapshot restored: ${result.snapshotId}`);
132
+ return {
133
+ exitCode: 0,
134
+ result
135
+ };
136
+ }
137
+ }
138
+ });
139
+
140
+ export { capture_snapshot_default as captureSnapshotCommand, prepare_infra_default as prepareInfraCommand, restore_snapshot_default as restoreSnapshotCommand };
141
+ //# sourceMappingURL=index.js.map
142
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/cli/commands/prepare-infra.ts","../../../src/cli/commands/capture-snapshot.ts","../../../src/cli/commands/restore-snapshot.ts"],"names":["defineCommand"],"mappings":";;;AAuBA,SAAS,UAAU,KAAA,EAAqC;AACtD,EAAA,IAAI,OAAO,UAAU,SAAA,EAAW;AAC9B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,MAAM,UAAA,GAAa,KAAA,CAAM,IAAA,EAAK,CAAE,WAAA,EAAY;AAC5C,IAAA,IAAI,eAAe,MAAA,EAAQ;AAAC,MAAA,OAAO,IAAA;AAAA,IAAK;AACxC,IAAA,IAAI,eAAe,OAAA,EAAS;AAAC,MAAA,OAAO,KAAA;AAAA,IAAM;AAAA,EAC5C;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,SAAS,KAAA,EAAoC;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C,YAAY,QAAA,CAAS,UAAA;AAAA,QACrB,YAAY,QAAA,CAAS;AAAA,OACvB;AACA,MAAA,GAAA,CAAI,EAAA,CAAG,OAAA,CAAQ,CAAA,mBAAA,EAAsB,MAAA,CAAO,UAAU,CAAA,CAAE,CAAA;AAExD,MAAA,OAAO;AAAA,QACL,QAAA,EAAU,CAAA;AAAA,QACV;AAAA,OACF;AAAA,IACF;AAAA;AAEJ,CAAC","file":"index.js","sourcesContent":["import { defineCommand, type CommandResult, type PluginContextV3 } from '@kb-labs/sdk';\n\ninterface PrepareInfraFlags {\n sourceRef?: string;\n basePath?: string;\n createEnvironment?: boolean;\n templateId?: string;\n ttlMs?: number;\n captureSnapshot?: boolean;\n namespace?: string;\n}\n\ninterface PrepareInfraInput {\n argv: string[];\n flags: PrepareInfraFlags;\n}\n\ninterface PrepareInfraResult {\n workspaceId: string;\n environmentId?: string;\n snapshotId?: string;\n}\n\nfunction toBoolean(value: unknown): boolean | undefined {\n if (typeof value === 'boolean') {\n return value;\n }\n if (typeof value === 'string') {\n const normalized = value.trim().toLowerCase();\n if (normalized === 'true') {return true;}\n if (normalized === 'false') {return false;}\n }\n return undefined;\n}\n\nfunction toNumber(value: unknown): number | undefined {\n if (typeof value === 'number' && Number.isFinite(value)) {\n return value;\n }\n if (typeof value === 'string' && value.trim().length > 0) {\n const parsed = Number(value);\n if (Number.isFinite(parsed)) {return parsed;}\n }\n return undefined;\n}\n\nexport default defineCommand<unknown, PrepareInfraInput, PrepareInfraResult>({\n id: 'infra-worker:prepare',\n description: 'Materialize workspace, optionally provision environment, optionally capture snapshot.',\n handler: {\n async execute(\n ctx: PluginContextV3<unknown>,\n input: PrepareInfraInput\n ): Promise<CommandResult<PrepareInfraResult>> {\n const flags = input.flags;\n const createEnvironment = toBoolean(flags.createEnvironment) ?? false;\n const captureSnapshot = toBoolean(flags.captureSnapshot) ?? false;\n const ttlMs = toNumber(flags.ttlMs);\n\n const workspace = await ctx.api.workspace.materialize({\n sourceRef: flags.sourceRef,\n basePath: flags.basePath,\n });\n\n let environmentId: string | undefined;\n if (createEnvironment) {\n const environment = await ctx.api.environment.create({\n templateId: flags.templateId,\n ttlMs,\n workspacePath: workspace.rootPath ?? flags.basePath,\n });\n environmentId = environment.environmentId;\n await ctx.api.workspace.attach({\n workspaceId: workspace.workspaceId,\n environmentId,\n });\n }\n\n let snapshotId: string | undefined;\n if (captureSnapshot) {\n const snapshot = await ctx.api.snapshot.capture({\n workspaceId: workspace.workspaceId,\n environmentId,\n namespace: flags.namespace,\n });\n snapshotId = snapshot.snapshotId;\n }\n\n const result: PrepareInfraResult = {\n workspaceId: workspace.workspaceId,\n environmentId,\n snapshotId,\n };\n\n ctx.ui.success('Infrastructure prepared', {\n sections: [\n {\n header: 'Identifiers',\n items: [\n `workspaceId: ${result.workspaceId}`,\n `environmentId: ${result.environmentId ?? '-'}`,\n `snapshotId: ${result.snapshotId ?? '-'}`,\n ],\n },\n ],\n });\n\n return {\n exitCode: 0,\n result,\n };\n },\n },\n});\n","import { defineCommand, type CommandResult, type PluginContextV3 } from '@kb-labs/sdk';\n\ninterface CaptureSnapshotFlags {\n workspaceId?: string;\n environmentId?: string;\n namespace?: string;\n sourcePath?: string;\n}\n\ninterface CaptureSnapshotInput {\n argv: string[];\n flags: CaptureSnapshotFlags;\n}\n\ninterface CaptureSnapshotResult {\n snapshotId: string;\n}\n\nexport default defineCommand<unknown, CaptureSnapshotInput, CaptureSnapshotResult>({\n id: 'infra-worker:capture-snapshot',\n description: 'Capture snapshot from workspace/environment.',\n handler: {\n async execute(\n ctx: PluginContextV3<unknown>,\n input: CaptureSnapshotInput\n ): Promise<CommandResult<CaptureSnapshotResult>> {\n const flags = input.flags;\n const snapshot = await ctx.api.snapshot.capture({\n workspaceId: flags.workspaceId,\n environmentId: flags.environmentId,\n namespace: flags.namespace,\n sourcePath: flags.sourcePath,\n });\n\n const result: CaptureSnapshotResult = { snapshotId: snapshot.snapshotId };\n ctx.ui.success(`Snapshot captured: ${result.snapshotId}`);\n\n return {\n exitCode: 0,\n result,\n };\n },\n },\n});\n","import { defineCommand, type CommandResult, type PluginContextV3 } from '@kb-labs/sdk';\n\ninterface RestoreSnapshotFlags {\n snapshotId?: string;\n workspaceId?: string;\n environmentId?: string;\n targetPath?: string;\n overwrite?: boolean;\n}\n\ninterface RestoreSnapshotInput {\n argv: string[];\n flags: RestoreSnapshotFlags;\n}\n\ninterface RestoreSnapshotResult {\n snapshotId: string;\n restoredAt: string;\n}\n\nexport default defineCommand<unknown, RestoreSnapshotInput, RestoreSnapshotResult>({\n id: 'infra-worker:restore-snapshot',\n description: 'Restore snapshot to workspace/environment.',\n handler: {\n async execute(\n ctx: PluginContextV3<unknown>,\n input: RestoreSnapshotInput\n ): Promise<CommandResult<RestoreSnapshotResult>> {\n const flags = input.flags;\n if (!flags.snapshotId) {\n throw new Error('Missing required flag: snapshotId');\n }\n\n const restored = await ctx.api.snapshot.restore({\n snapshotId: flags.snapshotId,\n workspaceId: flags.workspaceId,\n environmentId: flags.environmentId,\n targetPath: flags.targetPath,\n overwrite: flags.overwrite,\n });\n\n const result: RestoreSnapshotResult = {\n snapshotId: restored.snapshotId,\n restoredAt: restored.restoredAt,\n };\n ctx.ui.success(`Snapshot restored: ${result.snapshotId}`);\n\n return {\n exitCode: 0,\n result,\n };\n },\n },\n});\n"]}
@@ -0,0 +1,23 @@
1
+ import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
2
+
3
+ interface PrepareInfraFlags {
4
+ sourceRef?: string;
5
+ basePath?: string;
6
+ createEnvironment?: boolean;
7
+ templateId?: string;
8
+ ttlMs?: number;
9
+ captureSnapshot?: boolean;
10
+ namespace?: string;
11
+ }
12
+ interface PrepareInfraInput {
13
+ argv: string[];
14
+ flags: PrepareInfraFlags;
15
+ }
16
+ interface PrepareInfraResult {
17
+ workspaceId: string;
18
+ environmentId?: string;
19
+ snapshotId?: string;
20
+ }
21
+ declare const _default: _kb_labs_shared_command_kit.CommandHandlerV3<unknown, PrepareInfraInput, PrepareInfraResult>;
22
+
23
+ export { _default as default };
@@ -0,0 +1,93 @@
1
+ import { defineCommand } from '@kb-labs/sdk';
2
+
3
+ // src/cli/commands/prepare-infra.ts
4
+ function toBoolean(value) {
5
+ if (typeof value === "boolean") {
6
+ return value;
7
+ }
8
+ if (typeof value === "string") {
9
+ const normalized = value.trim().toLowerCase();
10
+ if (normalized === "true") {
11
+ return true;
12
+ }
13
+ if (normalized === "false") {
14
+ return false;
15
+ }
16
+ }
17
+ return void 0;
18
+ }
19
+ function toNumber(value) {
20
+ if (typeof value === "number" && Number.isFinite(value)) {
21
+ return value;
22
+ }
23
+ if (typeof value === "string" && value.trim().length > 0) {
24
+ const parsed = Number(value);
25
+ if (Number.isFinite(parsed)) {
26
+ return parsed;
27
+ }
28
+ }
29
+ return void 0;
30
+ }
31
+ var prepare_infra_default = defineCommand({
32
+ id: "infra-worker:prepare",
33
+ description: "Materialize workspace, optionally provision environment, optionally capture snapshot.",
34
+ handler: {
35
+ async execute(ctx, input) {
36
+ const flags = input.flags;
37
+ const createEnvironment = toBoolean(flags.createEnvironment) ?? false;
38
+ const captureSnapshot = toBoolean(flags.captureSnapshot) ?? false;
39
+ const ttlMs = toNumber(flags.ttlMs);
40
+ const workspace = await ctx.api.workspace.materialize({
41
+ sourceRef: flags.sourceRef,
42
+ basePath: flags.basePath
43
+ });
44
+ let environmentId;
45
+ if (createEnvironment) {
46
+ const environment = await ctx.api.environment.create({
47
+ templateId: flags.templateId,
48
+ ttlMs,
49
+ workspacePath: workspace.rootPath ?? flags.basePath
50
+ });
51
+ environmentId = environment.environmentId;
52
+ await ctx.api.workspace.attach({
53
+ workspaceId: workspace.workspaceId,
54
+ environmentId
55
+ });
56
+ }
57
+ let snapshotId;
58
+ if (captureSnapshot) {
59
+ const snapshot = await ctx.api.snapshot.capture({
60
+ workspaceId: workspace.workspaceId,
61
+ environmentId,
62
+ namespace: flags.namespace
63
+ });
64
+ snapshotId = snapshot.snapshotId;
65
+ }
66
+ const result = {
67
+ workspaceId: workspace.workspaceId,
68
+ environmentId,
69
+ snapshotId
70
+ };
71
+ ctx.ui.success("Infrastructure prepared", {
72
+ sections: [
73
+ {
74
+ header: "Identifiers",
75
+ items: [
76
+ `workspaceId: ${result.workspaceId}`,
77
+ `environmentId: ${result.environmentId ?? "-"}`,
78
+ `snapshotId: ${result.snapshotId ?? "-"}`
79
+ ]
80
+ }
81
+ ]
82
+ });
83
+ return {
84
+ exitCode: 0,
85
+ result
86
+ };
87
+ }
88
+ }
89
+ });
90
+
91
+ export { prepare_infra_default as default };
92
+ //# sourceMappingURL=prepare-infra.js.map
93
+ //# sourceMappingURL=prepare-infra.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/cli/commands/prepare-infra.ts"],"names":[],"mappings":";;;AAuBA,SAAS,UAAU,KAAA,EAAqC;AACtD,EAAA,IAAI,OAAO,UAAU,SAAA,EAAW;AAC9B,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,MAAM,UAAA,GAAa,KAAA,CAAM,IAAA,EAAK,CAAE,WAAA,EAAY;AAC5C,IAAA,IAAI,eAAe,MAAA,EAAQ;AAAC,MAAA,OAAO,IAAA;AAAA,IAAK;AACxC,IAAA,IAAI,eAAe,OAAA,EAAS;AAAC,MAAA,OAAO,KAAA;AAAA,IAAM;AAAA,EAC5C;AACA,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,SAAS,KAAA,EAAoC;AACpD,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,MAAA,CAAO,QAAA,CAAS,KAAK,CAAA,EAAG;AACvD,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,MAAM,IAAA,EAAK,CAAE,SAAS,CAAA,EAAG;AACxD,IAAA,MAAM,MAAA,GAAS,OAAO,KAAK,CAAA;AAC3B,IAAA,IAAI,MAAA,C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ACnB,QAAA,MAAM,QAAA,GAAW,MAAM,GAAA,CAAI,GAAA,CAAI,SAAS,OAAA,CAAQ;AAAA,UAC9C,aAAa,SAAA,CAAU,WAAA;AAAA,UACvB,aAAA;AAAA,UACA,WAAW,KAAA,CAAM;AAAA,SAClB,CAAA;AACD,QAAA,UAAA,GAAa,QAAA,CAAS,UAAA;AAAA,MACxB;AAEA,MAAA,MAAM,MAAA,GAA6B;AAAA,QACjC,aAAa,SAAA,CAAU,WAAA;AAAA,QACvB,aAAA;AAAA,QACA;AAAA,OACF;AAEA,MAAA,GAAA,CAAI,EAAA,CAAG,QAAQ,yBAAA,EAA2B;AAAA,QACxC,QAAA,EAAU;AAAA,UACR;AAAA,YACE,MAAA,EAAQ,aAAA;AAAA,YACR,KAAA,EAAO;AAAA,cACL,CAAA,aAAA,EAAgB,OAAO,WAAW,CAAA,CAAA;AAAA,cAClC,CAAA,eAAA,EAAkB,MAAA,CAAO,aAAA,IAAiB,GAAG,CAAA,CAAA;AAAA,cAC7C,CAAA,YAAA,EAAe,MAAA,CAAO,UAAA,IAAc,GAAG,CAAA;AAAA;AACzC;AACF;AACF,OACD,CAAA;AAED,MAAA,OAAO;AAAA,QACL,QAAA,EAAU,CAAA;AAAA,QACV;AAAA,OACF;AAAA,IACF;AAAA;AAEJ,CAAC","file":"prepare-infra.js","sourcesContent":["import { defineCommand, type CommandResult, type PluginContextV3 } from '@kb-labs/sdk';\n\ninterface PrepareInfraFlags {\n sourceRef?: string;\n basePath?: string;\n createEnvironment?: boolean;\n templateId?: string;\n ttlMs?: number;\n captureSnapshot?: boolean;\n namespace?: string;\n}\n\ninterface PrepareInfraInput {\n argv: string[];\n flags: PrepareInfraFlags;\n}\n\ninterface PrepareInfraResult {\n workspaceId: string;\n environmentId?: string;\n snapshotId?: string;\n}\n\nfunction toBoolean(value: unknown): boolean | undefined {\n if (typeof value === 'boolean') {\n return value;\n }\n if (typeof value === 'string') {\n const normalized = value.trim().toLowerCase();\n if (normalized === 'true') {return true;}\n if (normalized === 'false') {return false;}\n }\n return undefined;\n}\n\nfunction toNumber(value: unknown): number | undefined {\n if (typeof value === 'number' && Number.isFinite(value)) {\n return value;\n }\n if (typeof value === 'string' && value.trim().length > 0) {\n const parsed = Number(value);\n if (Number.isFinite(parsed)) {return parsed;}\n }\n return undefined;\n}\n\nexport default defineCommand<unknown, PrepareInfraInput, PrepareInfraResult>({\n id: 'infra-worker:prepare',\n description: 'Materialize workspace, optionally provision environment, optionally capture snapshot.',\n handler: {\n async execute(\n ctx: PluginContextV3<unknown>,\n input: PrepareInfraInput\n ): Promise<CommandResult<PrepareInfraResult>> {\n const flags = input.flags;\n const createEnvironment = toBoolean(flags.createEnvironment) ?? false;\n const captureSnapshot = toBoolean(flags.captureSnapshot) ?? false;\n const ttlMs = toNumber(flags.ttlMs);\n\n const workspace = await ctx.api.workspace.materialize({\n sourceRef: flags.sourceRef,\n basePath: flags.basePath,\n });\n\n let environmentId: string | undefined;\n if (createEnvironment) {\n const environment = await ctx.api.environment.create({\n templateId: flags.templateId,\n ttlMs,\n workspacePath: workspace.rootPath ?? flags.basePath,\n });\n environmentId = environment.environmentId;\n await ctx.api.workspace.attach({\n workspaceId: workspace.workspaceId,\n environmentId,\n });\n }\n\n let snapshotId: string | undefined;\n if (captureSnapshot) {\n const snapshot = await ctx.api.snapshot.capture({\n workspaceId: workspace.workspaceId,\n environmentId,\n namespace: flags.namespace,\n });\n snapshotId = snapshot.snapshotId;\n }\n\n const result: PrepareInfraResult = {\n workspaceId: workspace.workspaceId,\n environmentId,\n snapshotId,\n };\n\n ctx.ui.success('Infrastructure prepared', {\n sections: [\n {\n header: 'Identifiers',\n items: [\n `workspaceId: ${result.workspaceId}`,\n `environmentId: ${result.environmentId ?? '-'}`,\n `snapshotId: ${result.snapshotId ?? '-'}`,\n ],\n },\n ],\n });\n\n return {\n exitCode: 0,\n result,\n };\n },\n },\n});\n"]}
@@ -0,0 +1,20 @@
1
+ import * as _kb_labs_shared_command_kit from '@kb-labs/shared-command-kit';
2
+
3
+ interface RestoreSnapshotFlags {
4
+ snapshotId?: string;
5
+ workspaceId?: string;
6
+ environmentId?: string;
7
+ targetPath?: string;
8
+ overwrite?: boolean;
9
+ }
10
+ interface RestoreSnapshotInput {
11
+ argv: string[];
12
+ flags: RestoreSnapshotFlags;
13
+ }
14
+ interface RestoreSnapshotResult {
15
+ snapshotId: string;
16
+ restoredAt: string;
17
+ }
18
+ declare const _default: _kb_labs_shared_command_kit.CommandHandlerV3<unknown, RestoreSnapshotInput, RestoreSnapshotResult>;
19
+
20
+ export { _default as default };
@@ -0,0 +1,35 @@
1
+ import { defineCommand } from '@kb-labs/sdk';
2
+
3
+ // src/cli/commands/restore-snapshot.ts
4
+ var restore_snapshot_default = defineCommand({
5
+ id: "infra-worker:restore-snapshot",
6
+ description: "Restore snapshot to workspace/environment.",
7
+ handler: {
8
+ async execute(ctx, input) {
9
+ const flags = input.flags;
10
+ if (!flags.snapshotId) {
11
+ throw new Error("Missing required flag: snapshotId");
12
+ }
13
+ const restored = await ctx.api.snapshot.restore({
14
+ snapshotId: flags.snapshotId,
15
+ workspaceId: flags.workspaceId,
16
+ environmentId: flags.environmentId,
17
+ targetPath: flags.targetPath,
18
+ overwrite: flags.overwrite
19
+ });
20
+ const result = {
21
+ snapshotId: restored.snapshotId,
22
+ restoredAt: restored.restoredAt
23
+ };
24
+ ctx.ui.success(`Snapshot restored: ${result.snapshotId}`);
25
+ return {
26
+ exitCode: 0,
27
+ result
28
+ };
29
+ }
30
+ }
31
+ });
32
+
33
+ export { restore_snapshot_default as default };
34
+ //# sourceMappingURL=restore-snapshot.js.map
35
+ //# sourceMappingURL=restore-snapshot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/cli/commands/restore-snapshot.ts"],"names":[],"mappings":";;;AAoBA,IAAO,2BAAQ,aAAA,CAAoE;AAAA,EACjF,EAAA,EAAI,+BAAA;AAAA,EACJ,WAAA,EAAa,4CAAA;AAAA,EACb,OAAA,EAAS;AAAA,IACP,MAAM,OAAA,CACJ,GAAA,EACA,KAAA,EAC+C;AAC/C,MAAA,MAAM,QAAQ,KAAA,CAAM,KAAA;AACpB,MAAA,IAAI,CAAC,MAAM,UAAA,EAAY;AACrB,QAAA,MAAM,IAAI,MAAM,mCAAmC,CAAA;AAAA,MACrD;AAEA,MAAA,MAAM,QAAA,GAAW,MAAM,GAAA,CAAI,GAAA,CAAI,SAAS,OAAA,CAAQ;AAAA,QAC9C,YAAY,KAAA,CAAM,UAAA;AAAA,QAClB,aAAa,KAAA,CAAM,WAAA;AAAA,QACnB,eAAe,KAAA,CAAM,aAAA;AAAA,QACrB,YAAY,KAAA,CAAM,UAAA;AAAA,QAClB,WAAW,KAAA,CAAM;AAAA,OAClB,CAAA;AAED,MAAA,MAAM,MAAA,GAAgC;AAAA,QACpC,YAAY,QAAA,CAAS,UAAA;AAAA,QACrB,YAAY,QAAA,CAAS;AAAA,OACvB;AACA,MAAA,GAAA,CAAI,EAAA,CAAG,OAAA,CAAQ,CAAA,mBAAA,EAAsB,MAAA,CAAO,UAAU,CAAA,CAAE,CAAA;AAExD,MAAA,OAAO;AAAA,QACL,QAAA,EAAU,CAAA;AAAA,QACV;AAAA,OACF;AAAA,IACF;AAAA;AAEJ,CAAC","file":"restore-snapshot.js","sourcesContent":["import { defineCommand, type CommandResult, type PluginContextV3 } from '@kb-labs/sdk';\n\ninterface RestoreSnapshotFlags {\n snapshotId?: string;\n workspaceId?: string;\n environmentId?: string;\n targetPath?: string;\n overwrite?: boolean;\n}\n\ninterface RestoreSnapshotInput {\n argv: string[];\n flags: RestoreSnapshotFlags;\n}\n\ninterface RestoreSnapshotResult {\n snapshotId: string;\n restoredAt: string;\n}\n\nexport default defineCommand<unknown, RestoreSnapshotInput, RestoreSnapshotResult>({\n id: 'infra-worker:restore-snapshot',\n description: 'Restore snapshot to workspace/environment.',\n handler: {\n async execute(\n ctx: PluginContextV3<unknown>,\n input: RestoreSnapshotInput\n ): Promise<CommandResult<RestoreSnapshotResult>> {\n const flags = input.flags;\n if (!flags.snapshotId) {\n throw new Error('Missing required flag: snapshotId');\n }\n\n const restored = await ctx.api.snapshot.restore({\n snapshotId: flags.snapshotId,\n workspaceId: flags.workspaceId,\n environmentId: flags.environmentId,\n targetPath: flags.targetPath,\n overwrite: flags.overwrite,\n });\n\n const result: RestoreSnapshotResult = {\n snapshotId: restored.snapshotId,\n restoredAt: restored.restoredAt,\n };\n ctx.ui.success(`Snapshot restored: ${result.snapshotId}`);\n\n return {\n exitCode: 0,\n result,\n };\n },\n },\n});\n"]}
@@ -0,0 +1,6 @@
1
+ export { default as prepareInfraCommand } from './cli/commands/prepare-infra.js';
2
+ export { default as captureSnapshotCommand } from './cli/commands/capture-snapshot.js';
3
+ export { default as restoreSnapshotCommand } from './cli/commands/restore-snapshot.js';
4
+ export { default as manifest } from './manifest.v3.js';
5
+ import '@kb-labs/shared-command-kit';
6
+ import '@kb-labs/plugin-contracts';
package/dist/index.js ADDED
@@ -0,0 +1,226 @@
1
+ import { defineCommand, defineCommandFlags } from '@kb-labs/sdk';
2
+
3
+ // src/cli/commands/prepare-infra.ts
4
+ function toBoolean(value) {
5
+ if (typeof value === "boolean") {
6
+ return value;
7
+ }
8
+ if (typeof value === "string") {
9
+ const normalized = value.trim().toLowerCase();
10
+ if (normalized === "true") {
11
+ return true;
12
+ }
13
+ if (normalized === "false") {
14
+ return false;
15
+ }
16
+ }
17
+ return void 0;
18
+ }
19
+ function toNumber(value) {
20
+ if (typeof value === "number" && Number.isFinite(value)) {
21
+ return value;
22
+ }
23
+ if (typeof value === "string" && value.trim().length > 0) {
24
+ const parsed = Number(value);
25
+ if (Number.isFinite(parsed)) {
26
+ return parsed;
27
+ }
28
+ }
29
+ return void 0;
30
+ }
31
+ var prepare_infra_default = defineCommand({
32
+ id: "infra-worker:prepare",
33
+ description: "Materialize workspace, optionally provision environment, optionally capture snapshot.",
34
+ handler: {
35
+ async execute(ctx, input) {
36
+ const flags = input.flags;
37
+ const createEnvironment = toBoolean(flags.createEnvironment) ?? false;
38
+ const captureSnapshot = toBoolean(flags.captureSnapshot) ?? false;
39
+ const ttlMs = toNumber(flags.ttlMs);
40
+ const workspace = await ctx.api.workspace.materialize({
41
+ sourceRef: flags.sourceRef,
42
+ basePath: flags.basePath
43
+ });
44
+ let environmentId;
45
+ if (createEnvironment) {
46
+ const environment = await ctx.api.environment.create({
47
+ templateId: flags.templateId,
48
+ ttlMs,
49
+ workspacePath: workspace.rootPath ?? flags.basePath
50
+ });
51
+ environmentId = environment.environmentId;
52
+ await ctx.api.workspace.attach({
53
+ workspaceId: workspace.workspaceId,
54
+ environmentId
55
+ });
56
+ }
57
+ let snapshotId;
58
+ if (captureSnapshot) {
59
+ const snapshot = await ctx.api.snapshot.capture({
60
+ workspaceId: workspace.workspaceId,
61
+ environmentId,
62
+ namespace: flags.namespace
63
+ });
64
+ snapshotId = snapshot.snapshotId;
65
+ }
66
+ const result = {
67
+ workspaceId: workspace.workspaceId,
68
+ environmentId,
69
+ snapshotId
70
+ };
71
+ ctx.ui.success("Infrastructure prepared", {
72
+ sections: [
73
+ {
74
+ header: "Identifiers",
75
+ items: [
76
+ `workspaceId: ${result.workspaceId}`,
77
+ `environmentId: ${result.environmentId ?? "-"}`,
78
+ `snapshotId: ${result.snapshotId ?? "-"}`
79
+ ]
80
+ }
81
+ ]
82
+ });
83
+ return {
84
+ exitCode: 0,
85
+ result
86
+ };
87
+ }
88
+ }
89
+ });
90
+ var capture_snapshot_default = defineCommand({
91
+ id: "infra-worker:capture-snapshot",
92
+ description: "Capture snapshot from workspace/environment.",
93
+ handler: {
94
+ async execute(ctx, input) {
95
+ const flags = input.flags;
96
+ const snapshot = await ctx.api.snapshot.capture({
97
+ workspaceId: flags.workspaceId,
98
+ environmentId: flags.environmentId,
99
+ namespace: flags.namespace,
100
+ sourcePath: flags.sourcePath
101
+ });
102
+ const result = { snapshotId: snapshot.snapshotId };
103
+ ctx.ui.success(`Snapshot captured: ${result.snapshotId}`);
104
+ return {
105
+ exitCode: 0,
106
+ result
107
+ };
108
+ }
109
+ }
110
+ });
111
+ var restore_snapshot_default = defineCommand({
112
+ id: "infra-worker:restore-snapshot",
113
+ description: "Restore snapshot to workspace/environment.",
114
+ handler: {
115
+ async execute(ctx, input) {
116
+ const flags = input.flags;
117
+ if (!flags.snapshotId) {
118
+ throw new Error("Missing required flag: snapshotId");
119
+ }
120
+ const restored = await ctx.api.snapshot.restore({
121
+ snapshotId: flags.snapshotId,
122
+ workspaceId: flags.workspaceId,
123
+ environmentId: flags.environmentId,
124
+ targetPath: flags.targetPath,
125
+ overwrite: flags.overwrite
126
+ });
127
+ const result = {
128
+ snapshotId: restored.snapshotId,
129
+ restoredAt: restored.restoredAt
130
+ };
131
+ ctx.ui.success(`Snapshot restored: ${result.snapshotId}`);
132
+ return {
133
+ exitCode: 0,
134
+ result
135
+ };
136
+ }
137
+ }
138
+ });
139
+ var manifest = {
140
+ schema: "kb.plugin/3",
141
+ id: "@kb-labs/infra-worker",
142
+ version: "0.1.0",
143
+ display: {
144
+ name: "Infra Worker",
145
+ description: "Provision infra capabilities and return stable IDs for orchestrators.",
146
+ tags: ["infra", "workspace", "environment", "snapshot"]
147
+ },
148
+ permissions: {
149
+ platform: {
150
+ environment: {
151
+ create: true,
152
+ read: true,
153
+ destroy: true,
154
+ renewLease: true,
155
+ templates: ["*"]
156
+ },
157
+ workspace: {
158
+ materialize: true,
159
+ attach: true,
160
+ release: true,
161
+ read: true,
162
+ sources: ["*"],
163
+ paths: ["*"]
164
+ },
165
+ snapshot: {
166
+ capture: true,
167
+ restore: true,
168
+ delete: true,
169
+ read: true,
170
+ garbageCollect: true,
171
+ namespaces: ["*"]
172
+ }
173
+ }
174
+ },
175
+ cli: {
176
+ commands: [
177
+ {
178
+ id: "infra-worker:prepare",
179
+ group: "infra-worker",
180
+ describe: "Materialize workspace, optional environment, and optional snapshot.",
181
+ handler: "./cli/commands/prepare-infra.js#default",
182
+ handlerPath: "./cli/commands/prepare-infra.js",
183
+ flags: defineCommandFlags({
184
+ sourceRef: { type: "string", description: "Workspace source reference (repo/branch/etc)" },
185
+ basePath: { type: "string", description: "Workspace base path" },
186
+ createEnvironment: { type: "boolean", default: false, description: "Provision environment after workspace materialize" },
187
+ templateId: { type: "string", description: "Environment template ID" },
188
+ ttlMs: { type: "number", description: "Environment lease TTL in milliseconds" },
189
+ captureSnapshot: { type: "boolean", default: false, description: "Capture snapshot after prepare" },
190
+ namespace: { type: "string", description: "Snapshot namespace" }
191
+ })
192
+ },
193
+ {
194
+ id: "infra-worker:capture-snapshot",
195
+ group: "infra-worker",
196
+ describe: "Capture snapshot for workspace/environment.",
197
+ handler: "./cli/commands/capture-snapshot.js#default",
198
+ handlerPath: "./cli/commands/capture-snapshot.js",
199
+ flags: defineCommandFlags({
200
+ workspaceId: { type: "string", description: "Workspace ID" },
201
+ environmentId: { type: "string", description: "Environment ID" },
202
+ namespace: { type: "string", description: "Snapshot namespace" },
203
+ sourcePath: { type: "string", description: "Source path for snapshot" }
204
+ })
205
+ },
206
+ {
207
+ id: "infra-worker:restore-snapshot",
208
+ group: "infra-worker",
209
+ describe: "Restore snapshot to workspace/environment target.",
210
+ handler: "./cli/commands/restore-snapshot.js#default",
211
+ handlerPath: "./cli/commands/restore-snapshot.js",
212
+ flags: defineCommandFlags({
213
+ snapshotId: { type: "string", required: true, description: "Snapshot ID to restore" },
214
+ workspaceId: { type: "string", description: "Workspace ID target" },
215
+ environmentId: { type: "string", description: "Environment ID target" },
216
+ targetPath: { type: "string", description: "Restore target path" },
217
+ overwrite: { type: "boolean", default: false, description: "Overwrite existing files" }
218
+ })
219
+ }
220
+ ]
221
+ }
222
+ };
223
+
224
+ export { capture_snapshot_default as captureSnapshotCommand, manifest, prepare_infra_default as prepareInfraCommand, restore_snapshot_default as restoreSnapshotCommand };
225
+ //# sourceMappingURL=index.js.map
226
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cli/commands/prepare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H;AACF;AAEJ","file":"index.js","sourcesContent":["import { defineCommand, type CommandResult, type PluginContextV3 } from '@kb-labs/sdk';\n\ninterface PrepareInfraFlags {\n sourceRef?: string;\n basePath?: string;\n createEnvironment?: boolean;\n templateId?: string;\n ttlMs?: number;\n captureSnapshot?: boolean;\n namespace?: string;\n}\n\ninterface PrepareInfraInput {\n argv: string[];\n flags: PrepareInfraFlags;\n}\n\ninterface PrepareInfraResult {\n workspaceId: string;\n environmentId?: string;\n snapshotId?: string;\n}\n\nfunction toBoolean(value: unknown): boolean | undefined {\n if (typeof value === 'boolean') {\n return value;\n }\n if (typeof value === 'string') {\n const normalized = value.trim().toLowerCase();\n if (normalized === 'true') {return true;}\n if (normalized === 'false') {return false;}\n }\n return undefined;\n}\n\nfunction toNumber(value: unknown): number | undefined {\n if (typeof value === 'number' && Number.isFinite(value)) {\n return value;\n }\n if (typeof value === 'string' && value.trim().length > 0) {\n const parsed = Number(value);\n if (Number.isFinite(parsed)) {return parsed;}\n }\n return undefined;\n}\n\nexport default defineCommand<unknown, PrepareInfraInput, PrepareInfraResult>({\n id: 'infra-worker:prepare',\n description: 'Materialize workspace, optionally provision environment, optionally capture snapshot.',\n handler: {\n async execute(\n ctx: PluginContextV3<unknown>,\n input: PrepareInfraInput\n ): Promise<CommandResult<PrepareInfraResult>> {\n const flags = input.flags;\n const createEnvironment = toBoolean(flags.createEnvironment) ?? false;\n const captureSnapshot = toBoolean(flags.captureSnapshot) ?? false;\n const ttlMs = toNumber(flags.ttlMs);\n\n const workspace = await ctx.api.workspace.materialize({\n sourceRef: flags.sourceRef,\n basePath: flags.basePath,\n });\n\n let environmentId: string | undefined;\n if (createEnvironment) {\n const environment = await ctx.api.environment.create({\n templateId: flags.templateId,\n ttlMs,\n workspacePath: workspace.rootPath ?? flags.basePath,\n });\n environmentId = environment.environmentId;\n await ctx.api.workspace.attach({\n workspaceId: workspace.workspaceId,\n environmentId,\n });\n }\n\n let snapshotId: string | undefined;\n if (captureSnapshot) {\n const snapshot = await ctx.api.snapshot.capture({\n workspaceId: workspace.workspaceId,\n environmentId,\n namespace: flags.namespace,\n });\n snapshotId = snapshot.snapshotId;\n }\n\n const result: PrepareInfraResult = {\n workspaceId: workspace.workspaceId,\n environmentId,\n snapshotId,\n };\n\n ctx.ui.success('Infrastructure prepared', {\n sections: [\n {\n header: 'Identifiers',\n items: [\n `workspaceId: ${result.workspaceId}`,\n `environmentId: ${result.environmentId ?? '-'}`,\n `snapshotId: ${result.snapshotId ?? '-'}`,\n ],\n },\n ],\n });\n\n return {\n exitCode: 0,\n result,\n };\n },\n },\n});\n","import { defineCommand, type CommandResult, type PluginContextV3 } from '@kb-labs/sdk';\n\ninterface CaptureSnapshotFlags {\n workspaceId?: string;\n environmentId?: string;\n namespace?: string;\n sourcePath?: string;\n}\n\ninterface CaptureSnapshotInput {\n argv: string[];\n flags: CaptureSnapshotFlags;\n}\n\ninterface CaptureSnapshotResult {\n snapshotId: string;\n}\n\nexport default defineCommand<unknown, CaptureSnapshotInput, CaptureSnapshotResult>({\n id: 'infra-worker:capture-snapshot',\n description: 'Capture snapshot from workspace/environment.',\n handler: {\n async execute(\n ctx: PluginContextV3<unknown>,\n input: CaptureSnapshotInput\n ): Promise<CommandResult<CaptureSnapshotResult>> {\n const flags = input.flags;\n const snapshot = await ctx.api.snapshot.capture({\n workspaceId: flags.workspaceId,\n environmentId: flags.environmentId,\n namespace: flags.namespace,\n sourcePath: flags.sourcePath,\n });\n\n const result: CaptureSnapshotResult = { snapshotId: snapshot.snapshotId };\n ctx.ui.success(`Snapshot captured: ${result.snapshotId}`);\n\n return {\n exitCode: 0,\n result,\n };\n },\n },\n});\n","import { defineCommand, type CommandResult, type PluginContextV3 } from '@kb-labs/sdk';\n\ninterface RestoreSnapshotFlags {\n snapshotId?: string;\n workspaceId?: string;\n environmentId?: string;\n targetPath?: string;\n overwrite?: boolean;\n}\n\ninterface RestoreSnapshotInput {\n argv: string[];\n flags: RestoreSnapshotFlags;\n}\n\ninterface RestoreSnapshotResult {\n snapshotId: string;\n restoredAt: string;\n}\n\nexport default defineCommand<unknown, RestoreSnapshotInput, RestoreSnapshotResult>({\n id: 'infra-worker:restore-snapshot',\n description: 'Restore snapshot to workspace/environment.',\n handler: {\n async execute(\n ctx: PluginContextV3<unknown>,\n input: RestoreSnapshotInput\n ): Promise<CommandResult<RestoreSnapshotResult>> {\n const flags = input.flags;\n if (!flags.snapshotId) {\n throw new Error('Missing required flag: snapshotId');\n }\n\n const restored = await ctx.api.snapshot.restore({\n snapshotId: flags.snapshotId,\n workspaceId: flags.workspaceId,\n environmentId: flags.environmentId,\n targetPath: flags.targetPath,\n overwrite: flags.overwrite,\n });\n\n const result: RestoreSnapshotResult = {\n snapshotId: restored.snapshotId,\n restoredAt: restored.restoredAt,\n };\n ctx.ui.success(`Snapshot restored: ${result.snapshotId}`);\n\n return {\n exitCode: 0,\n result,\n };\n },\n },\n});\n","import type { ManifestV3 } from '@kb-labs/plugin-contracts';\nimport { defineCommandFlags } from '@kb-labs/sdk';\n\nexport const manifest: ManifestV3 = {\n schema: 'kb.plugin/3',\n id: '@kb-labs/infra-worker',\n version: '0.1.0',\n display: {\n name: 'Infra Worker',\n description: 'Provision infra capabilities and return stable IDs for orchestrators.',\n tags: ['infra', 'workspace', 'environment', 'snapshot'],\n },\n permissions: {\n platform: {\n environment: {\n create: true,\n read: true,\n destroy: true,\n renewLease: true,\n templates: ['*'],\n },\n workspace: {\n materialize: true,\n attach: true,\n release: true,\n read: true,\n sources: ['*'],\n paths: ['*'],\n },\n snapshot: {\n capture: true,\n restore: true,\n delete: true,\n read: true,\n garbageCollect: true,\n namespaces: ['*'],\n },\n },\n },\n cli: {\n commands: [\n {\n id: 'infra-worker:prepare',\n group: 'infra-worker',\n describe: 'Materialize workspace, optional environment, and optional snapshot.',\n handler: './cli/commands/prepare-infra.js#default',\n handlerPath: './cli/commands/prepare-infra.js',\n flags: defineCommandFlags({\n sourceRef: { type: 'string', description: 'Workspace source reference (repo/branch/etc)' },\n basePath: { type: 'string', description: 'Workspace base path' },\n createEnvironment: { type: 'boolean', default: false, description: 'Provision environment after workspace materialize' },\n templateId: { type: 'string', description: 'Environment template ID' },\n ttlMs: { type: 'number', description: 'Environment lease TTL in milliseconds' },\n captureSnapshot: { type: 'boolean', default: false, description: 'Capture snapshot after prepare' },\n namespace: { type: 'string', description: 'Snapshot namespace' },\n }),\n },\n {\n id: 'infra-worker:capture-snapshot',\n group: 'infra-worker',\n describe: 'Capture snapshot for workspace/environment.',\n handler: './cli/commands/capture-snapshot.js#default',\n handlerPath: './cli/commands/capture-snapshot.js',\n flags: defineCommandFlags({\n workspaceId: { type: 'string', description: 'Workspace ID' },\n environmentId: { type: 'string', description: 'Environment ID' },\n namespace: { type: 'string', description: 'Snapshot namespace' },\n sourcePath: { type: 'string', description: 'Source path for snapshot' },\n }),\n },\n {\n id: 'infra-worker:restore-snapshot',\n group: 'infra-worker',\n describe: 'Restore snapshot to workspace/environment target.',\n handler: './cli/commands/restore-snapshot.js#default',\n handlerPath: './cli/commands/restore-snapshot.js',\n flags: defineCommandFlags({\n snapshotId: { type: 'string', required: true, description: 'Snapshot ID to restore' },\n workspaceId: { type: 'string', description: 'Workspace ID target' },\n environmentId: { type: 'string', description: 'Environment ID target' },\n targetPath: { type: 'string', description: 'Restore target path' },\n overwrite: { type: 'boolean', default: false, description: 'Overwrite existing files' },\n }),\n },\n ],\n },\n};\n\nexport default manifest;\n"]}
@@ -0,0 +1,5 @@
1
+ import { ManifestV3 } from '@kb-labs/plugin-contracts';
2
+
3
+ declare const manifest: ManifestV3;
4
+
5
+ export { manifest as default, manifest };
@@ -0,0 +1,92 @@
1
+ import { defineCommandFlags } from '@kb-labs/sdk';
2
+
3
+ // src/manifest.v3.ts
4
+ var manifest = {
5
+ schema: "kb.plugin/3",
6
+ id: "@kb-labs/infra-worker",
7
+ version: "0.1.0",
8
+ display: {
9
+ name: "Infra Worker",
10
+ description: "Provision infra capabilities and return stable IDs for orchestrators.",
11
+ tags: ["infra", "workspace", "environment", "snapshot"]
12
+ },
13
+ permissions: {
14
+ platform: {
15
+ environment: {
16
+ create: true,
17
+ read: true,
18
+ destroy: true,
19
+ renewLease: true,
20
+ templates: ["*"]
21
+ },
22
+ workspace: {
23
+ materialize: true,
24
+ attach: true,
25
+ release: true,
26
+ read: true,
27
+ sources: ["*"],
28
+ paths: ["*"]
29
+ },
30
+ snapshot: {
31
+ capture: true,
32
+ restore: true,
33
+ delete: true,
34
+ read: true,
35
+ garbageCollect: true,
36
+ namespaces: ["*"]
37
+ }
38
+ }
39
+ },
40
+ cli: {
41
+ commands: [
42
+ {
43
+ id: "infra-worker:prepare",
44
+ group: "infra-worker",
45
+ describe: "Materialize workspace, optional environment, and optional snapshot.",
46
+ handler: "./cli/commands/prepare-infra.js#default",
47
+ handlerPath: "./cli/commands/prepare-infra.js",
48
+ flags: defineCommandFlags({
49
+ sourceRef: { type: "string", description: "Workspace source reference (repo/branch/etc)" },
50
+ basePath: { type: "string", description: "Workspace base path" },
51
+ createEnvironment: { type: "boolean", default: false, description: "Provision environment after workspace materialize" },
52
+ templateId: { type: "string", description: "Environment template ID" },
53
+ ttlMs: { type: "number", description: "Environment lease TTL in milliseconds" },
54
+ captureSnapshot: { type: "boolean", default: false, description: "Capture snapshot after prepare" },
55
+ namespace: { type: "string", description: "Snapshot namespace" }
56
+ })
57
+ },
58
+ {
59
+ id: "infra-worker:capture-snapshot",
60
+ group: "infra-worker",
61
+ describe: "Capture snapshot for workspace/environment.",
62
+ handler: "./cli/commands/capture-snapshot.js#default",
63
+ handlerPath: "./cli/commands/capture-snapshot.js",
64
+ flags: defineCommandFlags({
65
+ workspaceId: { type: "string", description: "Workspace ID" },
66
+ environmentId: { type: "string", description: "Environment ID" },
67
+ namespace: { type: "string", description: "Snapshot namespace" },
68
+ sourcePath: { type: "string", description: "Source path for snapshot" }
69
+ })
70
+ },
71
+ {
72
+ id: "infra-worker:restore-snapshot",
73
+ group: "infra-worker",
74
+ describe: "Restore snapshot to workspace/environment target.",
75
+ handler: "./cli/commands/restore-snapshot.js#default",
76
+ handlerPath: "./cli/commands/restore-snapshot.js",
77
+ flags: defineCommandFlags({
78
+ snapshotId: { type: "string", required: true, description: "Snapshot ID to restore" },
79
+ workspaceId: { type: "string", description: "Workspace ID target" },
80
+ environmentId: { type: "string", description: "Environment ID target" },
81
+ targetPath: { type: "string", description: "Restore target path" },
82
+ overwrite: { type: "boolean", default: false, description: "Overwrite existing files" }
83
+ })
84
+ }
85
+ ]
86
+ }
87
+ };
88
+ var manifest_v3_default = manifest;
89
+
90
+ export { manifest_v3_default as default, manifest };
91
+ //# sourceMappingURL=manifest.v3.js.map
92
+ //# sourceMappingURL=manifest.v3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest.v3.ts"],"names":[],"mappings":";;;AAGO,IAAM,QAAA,GAAuB;AAAA,EAClC,MAAA,EAAQ,aAAA;AAAA,EACR,EAAA,EAAI,uBAAA;AAAA,EACJ,OAAA,EAAS,OAAA;AAAA,EACT,OAAA,EAAS;AAAA,IACP,IAAA,EAAM,cAAA;AAAA,IACN,WAAA,EAAa,uEAAA;AAAA,IACb,IAAA,EAAM,CAAC,OAAA,EAAS,WAAA,EAAa,eAAe,UAAU;AAAA,GACxD;AAAA,EACA,WAAA,EAAa;AAAA,IACX,QAAA,EAAU;AAAA,MACR,WAAA,EAAa;AAAA,QACX,MAAA,EAAQ,IAAA;AAAA,QACR,IAAA,EAAM,IAAA;AAAA,QACN,OAAA,EAAS,IAAA;AAAA,QACT,UAAA,EAAY,IAAA;AAAA,QACZ,SAAA,EAAW,CAAC,GAAG;AAAA,OACjB;AAAA,MACA,SAAA,EAAW;AAAA,QACT,WAAA,EAAa,IAAA;AAAA,QACb,MAAA,EAAQ,IAAA;AAAA,QACR,OAAA,EAAS,IAAA;AAAA,QACT,IAAA,EAAM,IAAA;AAAA,QACN,OAAA,EAAS,CAAC,GAAG,CAAA;AAAA,QACb,KAAA,EAAO,CAAC,GAA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A,CAAmB;AAAA,UACxB,WAAA,EAAa,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,cAAA,EAAe;AAAA,UAC3D,aAAA,EAAe,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,gBAAA,EAAiB;AAAA,UAC/D,SAAA,EAAW,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,oBAAA,EAAqB;AAAA,UAC/D,UAAA,EAAY,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,0BAAA;AAA2B,SACvE;AAAA,OACH;AAAA,MACA;AAAA,QACE,EAAA,EAAI,+BAAA;AAAA,QACJ,KAAA,EAAO,cAAA;AAAA,QACP,QAAA,EAAU,mDAAA;AAAA,QACV,OAAA,EAAS,4CAAA;AAAA,QACT,WAAA,EAAa,oCAAA;AAAA,QACb,OAAO,kBAAA,CAAmB;AAAA,UACxB,YAAY,EAAE,IAAA,EAAM,UAAU,QAAA,EAAU,IAAA,EAAM,aAAa,wBAAA,EAAyB;AAAA,UACpF,WAAA,EAAa,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,qBAAA,EAAsB;AAAA,UAClE,aAAA,EAAe,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,uBAAA,EAAwB;AAAA,UACtE,UAAA,EAAY,EAAE,IAAA,EAAM,QAAA,EAAU,aAAa,qBAAA,EAAsB;AAAA,UACjE,WAAW,EAAE,IAAA,EAAM,WAAW,OAAA,EAAS,KAAA,EAAO,aAAa,0BAAA;AAA2B,SACvF;AAAA;AACH;AACF;AAEJ;AAEA,IAAO,mBAAA,GAAQ","file":"manifest.v3.js","sourcesContent":["import type { ManifestV3 } from '@kb-labs/plugin-contracts';\nimport { defineCommandFlags } from '@kb-labs/sdk';\n\nexport const manifest: ManifestV3 = {\n schema: 'kb.plugin/3',\n id: '@kb-labs/infra-worker',\n version: '0.1.0',\n display: {\n name: 'Infra Worker',\n description: 'Provision infra capabilities and return stable IDs for orchestrators.',\n tags: ['infra', 'workspace', 'environment', 'snapshot'],\n },\n permissions: {\n platform: {\n environment: {\n create: true,\n read: true,\n destroy: true,\n renewLease: true,\n templates: ['*'],\n },\n workspace: {\n materialize: true,\n attach: true,\n release: true,\n read: true,\n sources: ['*'],\n paths: ['*'],\n },\n snapshot: {\n capture: true,\n restore: true,\n delete: true,\n read: true,\n garbageCollect: true,\n namespaces: ['*'],\n },\n },\n },\n cli: {\n commands: [\n {\n id: 'infra-worker:prepare',\n group: 'infra-worker',\n describe: 'Materialize workspace, optional environment, and optional snapshot.',\n handler: './cli/commands/prepare-infra.js#default',\n handlerPath: './cli/commands/prepare-infra.js',\n flags: defineCommandFlags({\n sourceRef: { type: 'string', description: 'Workspace source reference (repo/branch/etc)' },\n basePath: { type: 'string', description: 'Workspace base path' },\n createEnvironment: { type: 'boolean', default: false, description: 'Provision environment after workspace materialize' },\n templateId: { type: 'string', description: 'Environment template ID' },\n ttlMs: { type: 'number', description: 'Environment lease TTL in milliseconds' },\n captureSnapshot: { type: 'boolean', default: false, description: 'Capture snapshot after prepare' },\n namespace: { type: 'string', description: 'Snapshot namespace' },\n }),\n },\n {\n id: 'infra-worker:capture-snapshot',\n group: 'infra-worker',\n describe: 'Capture snapshot for workspace/environment.',\n handler: './cli/commands/capture-snapshot.js#default',\n handlerPath: './cli/commands/capture-snapshot.js',\n flags: defineCommandFlags({\n workspaceId: { type: 'string', description: 'Workspace ID' },\n environmentId: { type: 'string', description: 'Environment ID' },\n namespace: { type: 'string', description: 'Snapshot namespace' },\n sourcePath: { type: 'string', description: 'Source path for snapshot' },\n }),\n },\n {\n id: 'infra-worker:restore-snapshot',\n group: 'infra-worker',\n describe: 'Restore snapshot to workspace/environment target.',\n handler: './cli/commands/restore-snapshot.js#default',\n handlerPath: './cli/commands/restore-snapshot.js',\n flags: defineCommandFlags({\n snapshotId: { type: 'string', required: true, description: 'Snapshot ID to restore' },\n workspaceId: { type: 'string', description: 'Workspace ID target' },\n environmentId: { type: 'string', description: 'Environment ID target' },\n targetPath: { type: 'string', description: 'Restore target path' },\n overwrite: { type: 'boolean', default: false, description: 'Overwrite existing files' },\n }),\n },\n ],\n },\n};\n\nexport default manifest;\n"]}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@kb-labs/infra-worker-core",
3
+ "version": "0.5.0",
4
+ "type": "module",
5
+ "description": "Infra worker plugin core for workspace/environment/snapshot lifecycle operations.",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./plugin-manifest": {
14
+ "import": "./dist/manifest.v3.js",
15
+ "types": "./dist/manifest.v3.d.ts"
16
+ },
17
+ "./cli": "./dist/cli/index.js",
18
+ "./dist/*": "./dist/*"
19
+ },
20
+ "kb": {
21
+ "manifest": "./dist/manifest.v3.js"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "sideEffects": false,
29
+ "scripts": {
30
+ "pretype-check": "pnpm --filter @kb-labs/infra-worker-core build",
31
+ "clean": "rimraf dist",
32
+ "build": "tsup --config tsup.config.ts",
33
+ "dev": "tsup --config tsup.config.ts --watch",
34
+ "lint": "eslint src --ext .ts,.tsx",
35
+ "lint:fix": "eslint . --fix",
36
+ "type-check": "tsc --noEmit",
37
+ "test": "vitest run --passWithNoTests",
38
+ "test:watch": "vitest"
39
+ },
40
+ "dependencies": {
41
+ "@kb-labs/plugin-contracts": "^1.4.0",
42
+ "@kb-labs/infra-worker-contracts": "^0.5.0",
43
+ "@kb-labs/sdk": "^1.5.0",
44
+ "react": "^18.3.1",
45
+ "zod": "^3.23.8"
46
+ },
47
+ "devDependencies": {
48
+ "@kb-labs/devkit": "link:../../../../infra/kb-labs-devkit",
49
+ "@kb-labs/plugin-runtime": "link:../../../../infra/kb-labs-plugin/packages/plugin-runtime",
50
+ "@types/node": "^24.3.3",
51
+ "@types/react": "^18.3.8",
52
+ "@types/react-dom": "^18.3.0",
53
+ "rimraf": "^6.0.1",
54
+ "tsup": "^8.5.0",
55
+ "typescript": "^5.6.3",
56
+ "vitest": "^3.2.4"
57
+ },
58
+ "engines": {
59
+ "node": ">=20.0.0",
60
+ "pnpm": ">=9.0.0"
61
+ }
62
+ }