@dharta/cli 0.6.77
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/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/agent.d.ts +17 -0
- package/dist/agent.js +134 -0
- package/dist/agent.js.map +1 -0
- package/dist/api-error.d.ts +3 -0
- package/dist/api-error.js +80 -0
- package/dist/api-error.js.map +1 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +19 -0
- package/dist/browser.js.map +1 -0
- package/dist/cli.d.ts +5 -0
- package/dist/cli.js +1978 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/agents.d.ts +131 -0
- package/dist/commands/agents.js +439 -0
- package/dist/commands/agents.js.map +1 -0
- package/dist/commands/analytics.d.ts +25 -0
- package/dist/commands/analytics.js +166 -0
- package/dist/commands/analytics.js.map +1 -0
- package/dist/commands/api.d.ts +19 -0
- package/dist/commands/api.js +278 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/appearance.d.ts +19 -0
- package/dist/commands/appearance.js +63 -0
- package/dist/commands/appearance.js.map +1 -0
- package/dist/commands/artifact.d.ts +33 -0
- package/dist/commands/artifact.js +235 -0
- package/dist/commands/artifact.js.map +1 -0
- package/dist/commands/audit-log.d.ts +32 -0
- package/dist/commands/audit-log.js +102 -0
- package/dist/commands/audit-log.js.map +1 -0
- package/dist/commands/auth.d.ts +47 -0
- package/dist/commands/auth.js +117 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/caps.d.ts +82 -0
- package/dist/commands/caps.js +213 -0
- package/dist/commands/caps.js.map +1 -0
- package/dist/commands/create.d.ts +22 -0
- package/dist/commands/create.js +76 -0
- package/dist/commands/create.js.map +1 -0
- package/dist/commands/deploy.d.ts +45 -0
- package/dist/commands/deploy.js +892 -0
- package/dist/commands/deploy.js.map +1 -0
- package/dist/commands/dev.d.ts +33 -0
- package/dist/commands/dev.js +655 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/directories.d.ts +60 -0
- package/dist/commands/directories.js +83 -0
- package/dist/commands/directories.js.map +1 -0
- package/dist/commands/doctor.d.ts +13 -0
- package/dist/commands/doctor.js +123 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/embed-keys.d.ts +61 -0
- package/dist/commands/embed-keys.js +165 -0
- package/dist/commands/embed-keys.js.map +1 -0
- package/dist/commands/env.d.ts +59 -0
- package/dist/commands/env.js +300 -0
- package/dist/commands/env.js.map +1 -0
- package/dist/commands/files.d.ts +14 -0
- package/dist/commands/files.js +84 -0
- package/dist/commands/files.js.map +1 -0
- package/dist/commands/git-credential.d.ts +1 -0
- package/dist/commands/git-credential.js +70 -0
- package/dist/commands/git-credential.js.map +1 -0
- package/dist/commands/kartas.d.ts +101 -0
- package/dist/commands/kartas.js +289 -0
- package/dist/commands/kartas.js.map +1 -0
- package/dist/commands/keys.d.ts +33 -0
- package/dist/commands/keys.js +141 -0
- package/dist/commands/keys.js.map +1 -0
- package/dist/commands/login.d.ts +22 -0
- package/dist/commands/login.js +78 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/logs.d.ts +14 -0
- package/dist/commands/logs.js +89 -0
- package/dist/commands/logs.js.map +1 -0
- package/dist/commands/members.d.ts +32 -0
- package/dist/commands/members.js +77 -0
- package/dist/commands/members.js.map +1 -0
- package/dist/commands/model-keys.d.ts +22 -0
- package/dist/commands/model-keys.js +222 -0
- package/dist/commands/model-keys.js.map +1 -0
- package/dist/commands/open.d.ts +29 -0
- package/dist/commands/open.js +119 -0
- package/dist/commands/open.js.map +1 -0
- package/dist/commands/parity.d.ts +15 -0
- package/dist/commands/parity.js +73 -0
- package/dist/commands/parity.js.map +1 -0
- package/dist/commands/rollback.d.ts +21 -0
- package/dist/commands/rollback.js +26 -0
- package/dist/commands/rollback.js.map +1 -0
- package/dist/commands/schedules.d.ts +52 -0
- package/dist/commands/schedules.js +231 -0
- package/dist/commands/schedules.js.map +1 -0
- package/dist/commands/scopes.d.ts +3 -0
- package/dist/commands/scopes.js +21 -0
- package/dist/commands/scopes.js.map +1 -0
- package/dist/commands/sessions.d.ts +53 -0
- package/dist/commands/sessions.js +142 -0
- package/dist/commands/sessions.js.map +1 -0
- package/dist/commands/setup.d.ts +28 -0
- package/dist/commands/setup.js +949 -0
- package/dist/commands/setup.js.map +1 -0
- package/dist/commands/status.d.ts +19 -0
- package/dist/commands/status.js +63 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/commands/update.d.ts +14 -0
- package/dist/commands/update.js +120 -0
- package/dist/commands/update.js.map +1 -0
- package/dist/commands/usage.d.ts +3 -0
- package/dist/commands/usage.js +37 -0
- package/dist/commands/usage.js.map +1 -0
- package/dist/commands/webhooks.d.ts +47 -0
- package/dist/commands/webhooks.js +156 -0
- package/dist/commands/webhooks.js.map +1 -0
- package/dist/commands/whoami.d.ts +7 -0
- package/dist/commands/whoami.js +17 -0
- package/dist/commands/whoami.js.map +1 -0
- package/dist/completions.d.ts +13 -0
- package/dist/completions.js +120 -0
- package/dist/completions.js.map +1 -0
- package/dist/config.d.ts +20 -0
- package/dist/config.js +98 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +14 -0
- package/dist/context.js +38 -0
- package/dist/context.js.map +1 -0
- package/dist/device-flow.d.ts +9 -0
- package/dist/device-flow.js +127 -0
- package/dist/device-flow.js.map +1 -0
- package/dist/harness-preflight.d.ts +24 -0
- package/dist/harness-preflight.js +252 -0
- package/dist/harness-preflight.js.map +1 -0
- package/dist/harnesses.d.ts +11 -0
- package/dist/harnesses.js +112 -0
- package/dist/harnesses.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/login-offer.d.ts +9 -0
- package/dist/login-offer.js +36 -0
- package/dist/login-offer.js.map +1 -0
- package/dist/manifest.d.ts +15 -0
- package/dist/manifest.js +142 -0
- package/dist/manifest.js.map +1 -0
- package/dist/money.d.ts +1 -0
- package/dist/money.js +16 -0
- package/dist/money.js.map +1 -0
- package/dist/output.d.ts +2 -0
- package/dist/output.js +20 -0
- package/dist/output.js.map +1 -0
- package/dist/runtime.d.ts +19 -0
- package/dist/runtime.js +95 -0
- package/dist/runtime.js.map +1 -0
- package/dist/scaffold.d.ts +16 -0
- package/dist/scaffold.js +74 -0
- package/dist/scaffold.js.map +1 -0
- package/dist/setup-scan.d.ts +21 -0
- package/dist/setup-scan.js +127 -0
- package/dist/setup-scan.js.map +1 -0
- package/dist/templates.d.ts +14 -0
- package/dist/templates.js +65 -0
- package/dist/templates.js.map +1 -0
- package/dist/validators.d.ts +10 -0
- package/dist/validators.js +116 -0
- package/dist/validators.js.map +1 -0
- package/dist/version-check.d.ts +25 -0
- package/dist/version-check.js +68 -0
- package/dist/version-check.js.map +1 -0
- package/node_modules/@dharta/sdk/LICENSE +21 -0
- package/node_modules/@dharta/sdk/README.md +87 -0
- package/node_modules/@dharta/sdk/dist/errors.d.ts +20 -0
- package/node_modules/@dharta/sdk/dist/errors.d.ts.map +1 -0
- package/node_modules/@dharta/sdk/dist/errors.js +51 -0
- package/node_modules/@dharta/sdk/dist/errors.js.map +1 -0
- package/node_modules/@dharta/sdk/dist/http.d.ts +26 -0
- package/node_modules/@dharta/sdk/dist/http.d.ts.map +1 -0
- package/node_modules/@dharta/sdk/dist/http.js +136 -0
- package/node_modules/@dharta/sdk/dist/http.js.map +1 -0
- package/node_modules/@dharta/sdk/dist/index.d.ts +15 -0
- package/node_modules/@dharta/sdk/dist/index.d.ts.map +1 -0
- package/node_modules/@dharta/sdk/dist/index.js +21 -0
- package/node_modules/@dharta/sdk/dist/index.js.map +1 -0
- package/node_modules/@dharta/sdk/dist/resources.d.ts +48 -0
- package/node_modules/@dharta/sdk/dist/resources.d.ts.map +1 -0
- package/node_modules/@dharta/sdk/dist/resources.js +150 -0
- package/node_modules/@dharta/sdk/dist/resources.js.map +1 -0
- package/node_modules/@dharta/sdk/dist/types.d.ts +94 -0
- package/node_modules/@dharta/sdk/dist/types.d.ts.map +1 -0
- package/node_modules/@dharta/sdk/dist/types.js +59 -0
- package/node_modules/@dharta/sdk/dist/types.js.map +1 -0
- package/node_modules/@dharta/sdk/package.json +32 -0
- package/node_modules/@dharta/sdk/src/errors.ts +58 -0
- package/node_modules/@dharta/sdk/src/http.ts +166 -0
- package/node_modules/@dharta/sdk/src/index.ts +36 -0
- package/node_modules/@dharta/sdk/src/resources.ts +197 -0
- package/node_modules/@dharta/sdk/src/types.ts +179 -0
- package/package.json +38 -0
- package/src/agent.ts +147 -0
- package/src/api-error.ts +88 -0
- package/src/browser.ts +20 -0
- package/src/cli.ts +2339 -0
- package/src/commands/agents.ts +635 -0
- package/src/commands/analytics.ts +181 -0
- package/src/commands/api.ts +297 -0
- package/src/commands/appearance.ts +79 -0
- package/src/commands/artifact.ts +331 -0
- package/src/commands/audit-log.ts +125 -0
- package/src/commands/auth.ts +186 -0
- package/src/commands/caps.ts +302 -0
- package/src/commands/create.ts +114 -0
- package/src/commands/deploy.ts +1122 -0
- package/src/commands/dev.ts +792 -0
- package/src/commands/directories.ts +136 -0
- package/src/commands/doctor.ts +138 -0
- package/src/commands/embed-keys.ts +237 -0
- package/src/commands/env.ts +369 -0
- package/src/commands/files.ts +124 -0
- package/src/commands/git-credential.ts +78 -0
- package/src/commands/kartas.ts +439 -0
- package/src/commands/keys.ts +206 -0
- package/src/commands/login.ts +115 -0
- package/src/commands/logs.ts +111 -0
- package/src/commands/members.ts +109 -0
- package/src/commands/model-keys.ts +278 -0
- package/src/commands/open.ts +173 -0
- package/src/commands/parity.ts +96 -0
- package/src/commands/rollback.ts +45 -0
- package/src/commands/schedules.ts +290 -0
- package/src/commands/scopes.ts +22 -0
- package/src/commands/sessions.ts +225 -0
- package/src/commands/setup.ts +1176 -0
- package/src/commands/status.ts +94 -0
- package/src/commands/update.ts +157 -0
- package/src/commands/usage.ts +41 -0
- package/src/commands/webhooks.ts +200 -0
- package/src/commands/whoami.ts +24 -0
- package/src/completions.ts +168 -0
- package/src/config.ts +143 -0
- package/src/context.ts +59 -0
- package/src/device-flow.ts +174 -0
- package/src/harness-preflight.ts +293 -0
- package/src/harnesses.ts +117 -0
- package/src/index.ts +3 -0
- package/src/login-offer.ts +49 -0
- package/src/manifest.ts +153 -0
- package/src/money.ts +15 -0
- package/src/output.ts +22 -0
- package/src/runtime.ts +127 -0
- package/src/scaffold.ts +102 -0
- package/src/setup-scan.ts +154 -0
- package/src/templates.ts +85 -0
- package/src/validators.ts +124 -0
- package/src/version-check.ts +75 -0
- package/templates/blank/CLAUDE.md +21 -0
- package/templates/blank/dharta.toml +11 -0
- package/templates/faq-agent/CLAUDE.md +51 -0
- package/templates/faq-agent/dharta.toml +11 -0
package/dist/money.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function parseDollarAmountToCents(value, flag) {
|
|
2
|
+
const trimmed = value.trim();
|
|
3
|
+
const match = trimmed.match(/^(?:(\d+)(?:\.(\d{1,2}))?|\.(\d{1,2}))$/);
|
|
4
|
+
if (!match)
|
|
5
|
+
throw amountError(flag);
|
|
6
|
+
const dollars = match[1] ? Number(match[1]) : 0;
|
|
7
|
+
const centsPart = match[2] ?? match[3] ?? "";
|
|
8
|
+
const cents = dollars * 100 + Number(centsPart.padEnd(2, "0"));
|
|
9
|
+
if (!Number.isSafeInteger(cents) || cents <= 0)
|
|
10
|
+
throw amountError(flag);
|
|
11
|
+
return cents;
|
|
12
|
+
}
|
|
13
|
+
function amountError(flag) {
|
|
14
|
+
return new Error(`${flag} must be a dollar amount greater than 0 with at most two decimal places.`);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=money.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.js","sourceRoot":"","sources":["../src/money.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,wBAAwB,CAAC,KAAa,EAAE,IAAY;IAClE,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC;IACvE,IAAI,CAAC,KAAK;QAAE,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;IAEpC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7C,MAAM,KAAK,GAAG,OAAO,GAAG,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAC/D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;IACxE,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,WAAW,CAAC,IAAY;IAC/B,OAAO,IAAI,KAAK,CAAC,GAAG,IAAI,0EAA0E,CAAC,CAAC;AACtG,CAAC"}
|
package/dist/output.d.ts
ADDED
package/dist/output.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Output helpers. Tiny on purpose — the CLI's UX is "narrate one line
|
|
2
|
+
// per row + occasional table"; pulling in cli-table or chalk costs
|
|
3
|
+
// more than it buys at this scale.
|
|
4
|
+
export function table(rows) {
|
|
5
|
+
if (rows.length === 0)
|
|
6
|
+
return "";
|
|
7
|
+
const cols = Object.keys(rows[0]);
|
|
8
|
+
const widths = cols.map((c) => Math.max(c.length, ...rows.map((r) => (r[c] ?? "").length)));
|
|
9
|
+
const pad = (s, w) => s + " ".repeat(Math.max(0, w - s.length));
|
|
10
|
+
const header = cols.map((c, i) => pad(c, widths[i])).join(" ");
|
|
11
|
+
const divider = widths.map((w) => "-".repeat(w)).join(" ");
|
|
12
|
+
const body = rows
|
|
13
|
+
.map((r) => cols.map((c, i) => pad(r[c] ?? "", widths[i])).join(" "))
|
|
14
|
+
.join("\n");
|
|
15
|
+
return `${header}\n${divider}\n${body}`;
|
|
16
|
+
}
|
|
17
|
+
export function fmtTs(ts) {
|
|
18
|
+
return ts ?? "—";
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,mEAAmE;AACnE,mCAAmC;AAEnC,MAAM,UAAU,KAAK,CAAC,IAAmC;IACvD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAC5B,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAC5D,CAAC;IACF,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAChF,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,IAAI,GAAG,IAAI;SACd,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACrE,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO,GAAG,MAAM,KAAK,OAAO,KAAK,IAAI,EAAE,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,EAA6B;IACjD,OAAO,EAAE,IAAI,GAAG,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
export declare const DHARTA_RUNTIME_PIN = "0.6.77";
|
|
3
|
+
export declare const UV_INSTALL_HINT: string;
|
|
4
|
+
export interface RuntimeCommand {
|
|
5
|
+
command: string[];
|
|
6
|
+
source: "env-executable" | "env-checkout" | "uv";
|
|
7
|
+
description: string;
|
|
8
|
+
}
|
|
9
|
+
export interface RuntimeResolveOptions {
|
|
10
|
+
env?: NodeJS.ProcessEnv;
|
|
11
|
+
commandExists?: (cmd: string) => Promise<boolean>;
|
|
12
|
+
}
|
|
13
|
+
export declare function resolveRuntime(opts?: RuntimeResolveOptions): Promise<RuntimeCommand>;
|
|
14
|
+
export declare function whichAll(cmd: string, env?: NodeJS.ProcessEnv): Promise<string[]>;
|
|
15
|
+
export declare function spawnRuntime(runtime: RuntimeCommand, args: string[], options?: {
|
|
16
|
+
cwd?: string;
|
|
17
|
+
env?: NodeJS.ProcessEnv;
|
|
18
|
+
stdio?: "inherit" | "pipe";
|
|
19
|
+
}): ReturnType<typeof spawn>;
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Runtime bootstrap for `dharta dev` (RFC 0013 CLI-3, decision D2): the
|
|
2
|
+
// harness-adapter kernel lives in the Python `dharta-runtime` package,
|
|
3
|
+
// single-sourced with production. The CLI resolves it via uv with a
|
|
4
|
+
// version pin that ships inside each CLI release, so CLI and runtime
|
|
5
|
+
// version as a pair. DHARTA_RUNTIME is the escape hatch (point it at a
|
|
6
|
+
// checkout or an executable). Zero Python is ever visible on the happy
|
|
7
|
+
// path; every failure prints the one remedial command.
|
|
8
|
+
import { promises as fs } from "node:fs";
|
|
9
|
+
import * as path from "node:path";
|
|
10
|
+
import { spawn } from "node:child_process";
|
|
11
|
+
// Ships with the CLI release; bump together with dharta-runtime.
|
|
12
|
+
export const DHARTA_RUNTIME_PIN = "0.6.77";
|
|
13
|
+
export const UV_INSTALL_HINT = "Install uv first: curl -LsSf https://astral.sh/uv/install.sh | sh (or: brew install uv)\n" +
|
|
14
|
+
"Then re-run dharta dev. To use a local checkout instead, set DHARTA_RUNTIME=/path/to/dharta-runtime.";
|
|
15
|
+
// Resolve how to launch dharta-runtime. Throws with remedial guidance —
|
|
16
|
+
// never a stack trace — when the bootstrap can't work.
|
|
17
|
+
export async function resolveRuntime(opts = {}) {
|
|
18
|
+
const env = opts.env ?? process.env;
|
|
19
|
+
const exists = opts.commandExists ?? commandOnPath;
|
|
20
|
+
const override = env.DHARTA_RUNTIME;
|
|
21
|
+
if (override) {
|
|
22
|
+
const stat = await fs.stat(override).catch(() => null);
|
|
23
|
+
if (!stat) {
|
|
24
|
+
throw new Error(`DHARTA_RUNTIME points at ${override}, which does not exist. ` +
|
|
25
|
+
"Unset it to use the pinned runtime, or point it at a dharta-runtime checkout or executable.");
|
|
26
|
+
}
|
|
27
|
+
if (stat.isDirectory()) {
|
|
28
|
+
if (!(await exists("uv"))) {
|
|
29
|
+
throw new Error(`DHARTA_RUNTIME is a checkout, which needs uv to run.\n${UV_INSTALL_HINT}`);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
command: ["uv", "run", "--project", override, "dharta-runtime"],
|
|
33
|
+
source: "env-checkout",
|
|
34
|
+
description: `checkout at ${override} (DHARTA_RUNTIME)`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
command: [override],
|
|
39
|
+
source: "env-executable",
|
|
40
|
+
description: `executable ${override} (DHARTA_RUNTIME)`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// Check for the binary we actually launch (uvx ships with uv, but a
|
|
44
|
+
// partial install would otherwise surface as a raw spawn ENOENT).
|
|
45
|
+
if (!(await exists("uvx"))) {
|
|
46
|
+
throw new Error(`dharta dev needs uv to bootstrap the agent runtime.\n${UV_INSTALL_HINT}`);
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
// uvx resolves and caches the pinned package on first use — the
|
|
50
|
+
// "install" step the user never sees.
|
|
51
|
+
command: ["uvx", "--from", `dharta-runtime==${DHARTA_RUNTIME_PIN}`, "dharta-runtime"],
|
|
52
|
+
source: "uv",
|
|
53
|
+
description: `dharta-runtime ${DHARTA_RUNTIME_PIN} via uv`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// `which`-equivalent: scan PATH for an executable, returning every hit
|
|
57
|
+
// in order. Used both for uv detection and the doctor's PATH-shadow
|
|
58
|
+
// check (a stale pip-installed `dharta` shadowing this CLI). On Windows
|
|
59
|
+
// the PATHEXT suffixes apply and the executable bit is meaningless.
|
|
60
|
+
export async function whichAll(cmd, env = process.env) {
|
|
61
|
+
const dirs = (env.PATH ?? "").split(path.delimiter).filter(Boolean);
|
|
62
|
+
const win = process.platform === "win32";
|
|
63
|
+
const suffixes = win
|
|
64
|
+
? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((s) => s.toLowerCase())
|
|
65
|
+
: [""];
|
|
66
|
+
const hits = [];
|
|
67
|
+
for (const dir of dirs) {
|
|
68
|
+
for (const suffix of suffixes) {
|
|
69
|
+
const candidate = path.join(dir, cmd + suffix);
|
|
70
|
+
try {
|
|
71
|
+
await fs.access(candidate, win ? fs.constants.F_OK : fs.constants.X_OK);
|
|
72
|
+
hits.push(candidate);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// not here
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return hits;
|
|
81
|
+
}
|
|
82
|
+
async function commandOnPath(cmd) {
|
|
83
|
+
return (await whichAll(cmd)).length > 0;
|
|
84
|
+
}
|
|
85
|
+
// Spawn the runtime with the resolved command + args, inheriting stdio
|
|
86
|
+
// by default. The error path names the escape hatch.
|
|
87
|
+
export function spawnRuntime(runtime, args, options = {}) {
|
|
88
|
+
const [cmd, ...prefix] = runtime.command;
|
|
89
|
+
return spawn(cmd, [...prefix, ...args], {
|
|
90
|
+
cwd: options.cwd,
|
|
91
|
+
env: options.env ?? process.env,
|
|
92
|
+
stdio: options.stdio ?? "inherit",
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,uEAAuE;AACvE,oEAAoE;AACpE,qEAAqE;AACrE,uEAAuE;AACvE,uEAAuE;AACvE,uDAAuD;AAEvD,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,iEAAiE;AACjE,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAE3C,MAAM,CAAC,MAAM,eAAe,GAC1B,6FAA6F;IAC7F,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IAAI,CAAC,CAAC;gBACxE,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACrB,MAAM;YACR,CAAC;YAAC,MAAM,CAAC;gBACP,WAAW;YACb,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,GAAW;IACtC,OAAO,CAAC,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED,uEAAuE;AACvE,qDAAqD;AACrD,MAAM,UAAU,YAAY,CAC1B,OAAuB,EACvB,IAAc,EACd,UAAiF,EAAE;IAEnF,MAAM,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IACzC,OAAO,KAAK,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE;QACtC,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG;QAC/B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,SAAS;KAClC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type HarnessType } from "./harnesses.js";
|
|
2
|
+
export interface ScaffoldOptions {
|
|
3
|
+
template?: string;
|
|
4
|
+
harness?: HarnessType;
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
fetchImpl?: typeof fetch;
|
|
7
|
+
log?: (line: string) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface ScaffoldResult {
|
|
10
|
+
template: string;
|
|
11
|
+
harness: HarnessType;
|
|
12
|
+
instructionFile: "CLAUDE.md" | "AGENTS.md";
|
|
13
|
+
files: string[];
|
|
14
|
+
source: "control-plane" | "bundled";
|
|
15
|
+
}
|
|
16
|
+
export declare function scaffoldTemplate(target: string, opts: ScaffoldOptions): Promise<ScaffoldResult>;
|
package/dist/scaffold.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Template scaffolding, extracted from the old `dharta init` (RFC 0024 DEP-4c,
|
|
2
|
+
// B.1): `dharta setup` reuses this to lay down a starter agent in a brand-new
|
|
3
|
+
// folder. Unlike init it does NOT git-init or commit (setup prompts for git,
|
|
4
|
+
// `dharta deploy` makes the first commit), does NOT require an empty directory
|
|
5
|
+
// (setup configures folders that may already have files), never clobbers an
|
|
6
|
+
// existing file, and skips dharta.toml - setup writes the self-documenting one.
|
|
7
|
+
import { existsSync, promises as fs } from "node:fs";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import { resolveTemplates } from "./templates.js";
|
|
10
|
+
import { closestChoice, normalizeNonBlank } from "./validators.js";
|
|
11
|
+
import { DEFAULT_CREATE_HARNESS, nativeInstructionFile, translateTemplateFilesForHarness, } from "./harnesses.js";
|
|
12
|
+
export async function scaffoldTemplate(target, opts) {
|
|
13
|
+
const log = opts.log ?? ((line) => console.log(line));
|
|
14
|
+
const templateKey = opts.template === undefined ? "blank" : normalizeNonBlank(opts.template, "--template");
|
|
15
|
+
const harness = opts.harness ?? DEFAULT_CREATE_HARNESS;
|
|
16
|
+
const resolved = await resolveTemplates(opts.baseUrl, opts.fetchImpl);
|
|
17
|
+
if (resolved.source === "bundled") {
|
|
18
|
+
log("Could not reach the template service - using the bundled template set.");
|
|
19
|
+
}
|
|
20
|
+
const template = resolved.templates.find((t) => t.key === templateKey);
|
|
21
|
+
if (!template) {
|
|
22
|
+
const keys = resolved.templates.map((t) => t.key);
|
|
23
|
+
const suggestion = closestChoice(templateKey, keys);
|
|
24
|
+
throw new Error(`Unknown template '${templateKey}'. Available: ${keys.join(", ")}.` +
|
|
25
|
+
(suggestion ? ` Did you mean ${suggestion}?` : ""));
|
|
26
|
+
}
|
|
27
|
+
await fs.mkdir(target, { recursive: true });
|
|
28
|
+
const written = [];
|
|
29
|
+
const files = translateTemplateFilesForHarness(template.files, harness);
|
|
30
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
31
|
+
if (rel === "dharta.toml")
|
|
32
|
+
continue; // setup owns identity (the commented manifest)
|
|
33
|
+
// Template files come from server JSON - never let a hostile path
|
|
34
|
+
// (../..) or non-string content escape the target directory.
|
|
35
|
+
const dest = path.resolve(target, rel);
|
|
36
|
+
if (dest !== target && !dest.startsWith(target + path.sep)) {
|
|
37
|
+
throw new Error(`Template file path escapes the target directory: ${rel}. ` +
|
|
38
|
+
"Re-run with a bundled template (--template blank) and report this.");
|
|
39
|
+
}
|
|
40
|
+
if (typeof content !== "string") {
|
|
41
|
+
throw new Error(`Template file ${rel} has non-text content. Re-run with --template blank and report this.`);
|
|
42
|
+
}
|
|
43
|
+
if (existsSync(dest))
|
|
44
|
+
continue; // never clobber the user's own file
|
|
45
|
+
await fs.mkdir(path.dirname(dest), { recursive: true });
|
|
46
|
+
await fs.writeFile(dest, content);
|
|
47
|
+
written.push(rel);
|
|
48
|
+
}
|
|
49
|
+
// .env binds the [env] declarations locally and must never be committed.
|
|
50
|
+
await ensureGitignoreHasDotEnv(target);
|
|
51
|
+
return {
|
|
52
|
+
template: template.key,
|
|
53
|
+
harness,
|
|
54
|
+
instructionFile: nativeInstructionFile(harness),
|
|
55
|
+
files: written,
|
|
56
|
+
source: resolved.source,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async function ensureGitignoreHasDotEnv(target) {
|
|
60
|
+
const file = path.join(target, ".gitignore");
|
|
61
|
+
let existing = "";
|
|
62
|
+
try {
|
|
63
|
+
existing = await fs.readFile(file, "utf8");
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// no .gitignore yet
|
|
67
|
+
}
|
|
68
|
+
const lines = existing.split("\n").map((l) => l.trim());
|
|
69
|
+
if (lines.includes(".env"))
|
|
70
|
+
return;
|
|
71
|
+
const next = existing.length > 0 && !existing.endsWith("\n") ? `${existing}\n.env\n` : `${existing}.env\n`;
|
|
72
|
+
await fs.writeFile(file, next);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AAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,UAAU,CAAC,CAAC,CAAC,GAAG,QAAQ,QAAQ,CAAC;IAC3G,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type HarnessType } from "./harnesses.js";
|
|
2
|
+
import type { DeployMethod } from "./manifest.js";
|
|
3
|
+
export declare const MARKERS: (".claude" | "CLAUDE.md" | ".deepagents" | ".goose" | "dharta.toml" | ".opencode" | ".codex")[];
|
|
4
|
+
export interface AgentFolder {
|
|
5
|
+
dir: string;
|
|
6
|
+
rel: string;
|
|
7
|
+
name?: string;
|
|
8
|
+
slug?: string;
|
|
9
|
+
configured: boolean;
|
|
10
|
+
deployEnabled: boolean;
|
|
11
|
+
deployMethod?: DeployMethod;
|
|
12
|
+
harnessType?: HarnessType;
|
|
13
|
+
}
|
|
14
|
+
export declare function findGitRoot(start: string): string | null;
|
|
15
|
+
export interface ScanOptions {
|
|
16
|
+
isGitRepo?: boolean;
|
|
17
|
+
runGit?: (args: string[], cwd: string) => Promise<string | null>;
|
|
18
|
+
}
|
|
19
|
+
export declare function scanAgentFolders(root: string, opts?: ScanOptions): Promise<AgentFolder[]>;
|
|
20
|
+
export declare function renderTable(folders: AgentFolder[]): string;
|
|
21
|
+
export declare function describeFolder(dir: string, rel: string): Promise<AgentFolder>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync, promises as fs } from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import TOML from "@iarna/toml";
|
|
5
|
+
import { AGENT_MARKERS, hasAgentMarker, markerFolderRel, readDeclaredHarnessType, sniffHarnessType, } from "./harnesses.js";
|
|
6
|
+
// `dharta setup` lists every agent folder so you can pick one to configure
|
|
7
|
+
// (RFC 0024 DEP-4 / D10). A folder counts if it holds ANY harness/karta
|
|
8
|
+
// marker - configured or not, repo root included. Detection never
|
|
9
|
+
// auto-deploys; it just surfaces candidates.
|
|
10
|
+
export const MARKERS = [...AGENT_MARKERS];
|
|
11
|
+
// Walk up from `start` for a directory containing .git; null if none.
|
|
12
|
+
export function findGitRoot(start) {
|
|
13
|
+
let dir = path.resolve(start);
|
|
14
|
+
for (;;) {
|
|
15
|
+
if (existsSync(path.join(dir, ".git")))
|
|
16
|
+
return dir;
|
|
17
|
+
const parent = path.dirname(dir);
|
|
18
|
+
if (parent === dir)
|
|
19
|
+
return null;
|
|
20
|
+
dir = parent;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Every agent folder under `root`, sorted by relative path. In a git repo we
|
|
24
|
+
// union git's view of marker files - tracked AND new-but-not-ignored, at ANY
|
|
25
|
+
// depth (`--cached --others --exclude-standard`) - with a shallow walk that
|
|
26
|
+
// also catches directory markers like `.claude`. Outside git it is the shallow
|
|
27
|
+
// walk alone (root + immediate subdirs, RFC 0024 §4). The `--others` half is
|
|
28
|
+
// what surfaces a freshly `dharta create`d folder before it is committed.
|
|
29
|
+
export async function scanAgentFolders(root, opts = {}) {
|
|
30
|
+
const absRoot = path.resolve(root);
|
|
31
|
+
const rels = new Set();
|
|
32
|
+
if (opts.isGitRepo) {
|
|
33
|
+
const listed = await (opts.runGit ?? gitLsFiles)(["ls-files", "-z", "--cached", "--others", "--exclude-standard"], absRoot);
|
|
34
|
+
for (const p of (listed ?? "").split("\0")) {
|
|
35
|
+
if (!p)
|
|
36
|
+
continue;
|
|
37
|
+
const folder = markerFolderRel(p);
|
|
38
|
+
if (!folder)
|
|
39
|
+
continue;
|
|
40
|
+
rels.add(folder);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
await shallowWalk(absRoot, rels);
|
|
44
|
+
const folders = [];
|
|
45
|
+
for (const rel of [...rels].sort()) {
|
|
46
|
+
folders.push(await describeFolder(path.resolve(absRoot, rel), rel));
|
|
47
|
+
}
|
|
48
|
+
return folders;
|
|
49
|
+
}
|
|
50
|
+
// Destination-agnostic setup table: folder, name, configured?, deploy enabled?,
|
|
51
|
+
// and transport. Live release/version is joined separately by `dharta status`
|
|
52
|
+
// when an authenticated profile is available.
|
|
53
|
+
export function renderTable(folders) {
|
|
54
|
+
const headers = ["AGENT FOLDER", "NAME", "HARNESS", "CONFIGURED", "DEPLOY", "METHOD"];
|
|
55
|
+
const rows = folders.map((f) => [
|
|
56
|
+
f.rel === "." ? "./ (repo root)" : `./${f.rel}`,
|
|
57
|
+
f.name ?? "-",
|
|
58
|
+
f.harnessType ?? "-",
|
|
59
|
+
f.configured ? "yes" : "no",
|
|
60
|
+
f.configured ? (f.deployEnabled ? "enabled" : "disabled") : "-",
|
|
61
|
+
f.deployMethod ?? "-",
|
|
62
|
+
]);
|
|
63
|
+
const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => r[i].length)));
|
|
64
|
+
const fmt = (cols) => cols.map((c, i) => c.padEnd(widths[i])).join(" ").trimEnd();
|
|
65
|
+
return [fmt(headers), ...rows.map(fmt)].join("\n");
|
|
66
|
+
}
|
|
67
|
+
async function shallowWalk(absRoot, rels) {
|
|
68
|
+
if (await hasMarker(absRoot))
|
|
69
|
+
rels.add(".");
|
|
70
|
+
let entries;
|
|
71
|
+
try {
|
|
72
|
+
entries = await fs.readdir(absRoot, { withFileTypes: true });
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
for (const e of entries) {
|
|
78
|
+
// Skip dot-dirs (incl. .git) and node_modules as CANDIDATES - a marker
|
|
79
|
+
// like .claude makes its PARENT an agent folder, not itself.
|
|
80
|
+
if (!e.isDirectory() || e.name === "node_modules" || e.name.startsWith("."))
|
|
81
|
+
continue;
|
|
82
|
+
if (await hasMarker(path.join(absRoot, e.name)))
|
|
83
|
+
rels.add(e.name);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function hasMarker(dir) {
|
|
87
|
+
return hasAgentMarker(dir);
|
|
88
|
+
}
|
|
89
|
+
export async function describeFolder(dir, rel) {
|
|
90
|
+
const folder = { dir, rel: rel === "" ? "." : rel, configured: false, deployEnabled: false };
|
|
91
|
+
const tomlPath = path.join(dir, "dharta.toml");
|
|
92
|
+
if (!existsSync(tomlPath)) {
|
|
93
|
+
folder.harnessType = sniffHarnessType(dir);
|
|
94
|
+
return folder;
|
|
95
|
+
}
|
|
96
|
+
folder.configured = true;
|
|
97
|
+
try {
|
|
98
|
+
const raw = await fs.readFile(tomlPath, "utf8");
|
|
99
|
+
const parsed = TOML.parse(raw);
|
|
100
|
+
if (typeof parsed.name === "string")
|
|
101
|
+
folder.name = parsed.name;
|
|
102
|
+
if (typeof parsed.slug === "string")
|
|
103
|
+
folder.slug = parsed.slug;
|
|
104
|
+
folder.deployEnabled = parsed.deploy === true;
|
|
105
|
+
if (parsed.deploy_method === "git" || parsed.deploy_method === "folder") {
|
|
106
|
+
folder.deployMethod = parsed.deploy_method;
|
|
107
|
+
}
|
|
108
|
+
folder.harnessType = readDeclaredHarnessType(raw) ?? sniffHarnessType(dir);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
// A malformed dharta.toml is still a configured folder; it stays
|
|
112
|
+
// nameless here and the manifest writer / build server reports the
|
|
113
|
+
// parse error when it matters.
|
|
114
|
+
folder.harnessType = sniffHarnessType(dir);
|
|
115
|
+
}
|
|
116
|
+
return folder;
|
|
117
|
+
}
|
|
118
|
+
function gitLsFiles(args, cwd) {
|
|
119
|
+
return new Promise((resolve) => {
|
|
120
|
+
const proc = spawn("git", args, { cwd, stdio: ["ignore", "pipe", "ignore"] });
|
|
121
|
+
const out = [];
|
|
122
|
+
proc.stdout.on("data", (c) => out.push(c));
|
|
123
|
+
proc.on("error", () => resolve(null));
|
|
124
|
+
proc.on("close", (code) => resolve(code === 0 ? Buffer.concat(out).toString("utf8") : null));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
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AAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACtC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAC/F,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface Template {
|
|
2
|
+
key: string;
|
|
3
|
+
title: string;
|
|
4
|
+
description: string;
|
|
5
|
+
files: Record<string, string>;
|
|
6
|
+
}
|
|
7
|
+
export interface ResolvedTemplates {
|
|
8
|
+
templates: Template[];
|
|
9
|
+
source: "control-plane" | "bundled";
|
|
10
|
+
}
|
|
11
|
+
export declare const TEMPLATE_FETCH_TIMEOUT_MS = 3000;
|
|
12
|
+
export declare function resolveTemplates(baseUrl: string, fetchImpl?: typeof fetch): Promise<ResolvedTemplates>;
|
|
13
|
+
export declare function bundledTemplates(): Promise<Template[]>;
|
|
14
|
+
export declare function bundledTemplatesRoot(): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Template resolution for `dharta setup` scaffolding (RFC 0013 CLI-2 / 0024
|
|
2
|
+
// DEP-4c, decision D9): fetch the current set from the control plane so CLI
|
|
3
|
+
// and dashboard scaffolds never drift, with the launch set bundled in the
|
|
4
|
+
// package as the offline fallback.
|
|
5
|
+
import { promises as fs } from "node:fs";
|
|
6
|
+
import * as path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
// How long the control-plane fetch gets before we give up and take the bundled
|
|
9
|
+
// set below. `dharta create` is often a new user's first command, so it must
|
|
10
|
+
// not hang on a blackholed network. Exported because anything that kills the
|
|
11
|
+
// CLI on its own clock - the packed-CLI smoke test - has to allow strictly
|
|
12
|
+
// longer than this: kill the process first and the fallback never runs, so the
|
|
13
|
+
// only evidence left is an empty stdout+stderr.
|
|
14
|
+
export const TEMPLATE_FETCH_TIMEOUT_MS = 3000;
|
|
15
|
+
export async function resolveTemplates(baseUrl, fetchImpl) {
|
|
16
|
+
try {
|
|
17
|
+
const f = (fetchImpl ?? globalThis.fetch).bind(globalThis);
|
|
18
|
+
const res = await f(`${baseUrl.replace(/\/+$/, "")}/agent_templates`, {
|
|
19
|
+
headers: { Accept: "application/json" },
|
|
20
|
+
signal: AbortSignal.timeout(TEMPLATE_FETCH_TIMEOUT_MS),
|
|
21
|
+
});
|
|
22
|
+
if (res.ok) {
|
|
23
|
+
const body = (await res.json());
|
|
24
|
+
if (Array.isArray(body.templates) && body.templates.length > 0) {
|
|
25
|
+
return { templates: body.templates, source: "control-plane" };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// fall through to the bundled set
|
|
31
|
+
}
|
|
32
|
+
return { templates: await bundledTemplates(), source: "bundled" };
|
|
33
|
+
}
|
|
34
|
+
// The launch set shipped inside the package (templates/ at the package
|
|
35
|
+
// root, vendored from dharta-web's lib/agent_templates — a test pins the
|
|
36
|
+
// two trees identical).
|
|
37
|
+
export async function bundledTemplates() {
|
|
38
|
+
const root = bundledTemplatesRoot();
|
|
39
|
+
const meta = {
|
|
40
|
+
blank: {
|
|
41
|
+
title: "Blank",
|
|
42
|
+
description: "A minimal skeleton. Start from an empty native instruction outline.",
|
|
43
|
+
},
|
|
44
|
+
"faq-agent": {
|
|
45
|
+
title: "FAQ agent",
|
|
46
|
+
description: "A worked support-agent example: persona, knowledge section, escalation rule.",
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const templates = [];
|
|
50
|
+
for (const key of Object.keys(meta)) {
|
|
51
|
+
const dir = path.join(root, key);
|
|
52
|
+
const files = {};
|
|
53
|
+
for (const name of await fs.readdir(dir)) {
|
|
54
|
+
files[name] = await fs.readFile(path.join(dir, name), "utf8");
|
|
55
|
+
}
|
|
56
|
+
templates.push({ key, ...meta[key], files });
|
|
57
|
+
}
|
|
58
|
+
return templates;
|
|
59
|
+
}
|
|
60
|
+
export function bundledTemplatesRoot() {
|
|
61
|
+
// src/templates.ts compiles to dist/templates.js; templates/ sits at
|
|
62
|
+
// the package root either way.
|
|
63
|
+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "templates");
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,0EAA0E;AAC1E,mCAAmC;AAEnC,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAczC,+EAA+E;AAC/E,6EAA6E;AAC7E,6EAA6E;AAC7E,2EAA2E;AAC3E,+EAA+E;AAC/E,gDAAgD;AAChD,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAe,EACf,SAAwB;IAExB,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,CAAC,SAAS,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,kBAAkB,EAAE;YACpE,OAAO,EAAE,EAAE,MAAM,EAAE,kBAAkB,EAAE;YACvC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,yBAAyB,CAAC;SACvD,CAAC,CAAC;QACH,IAAI,GAAG,CAAC,E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ChE,CAAC;QACD,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,qEAAqE;IACrE,+BAA+B;IAC/B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;AACvF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function validateDateOnly(value: string, flag: string): void;
|
|
2
|
+
export declare function normalizeDateOnly(value: string, flag: string): string;
|
|
3
|
+
export declare function validateIsoTimestamp(value: string, flag: string): void;
|
|
4
|
+
export declare function normalizeIsoTimestamp(value: string, flag: string): string;
|
|
5
|
+
export declare function parseReleaseVersion(value: string, flag: string): number;
|
|
6
|
+
export declare function parsePositiveInteger(value: string, label: string): number;
|
|
7
|
+
export declare function normalizeNonBlank(value: string, label: string): string;
|
|
8
|
+
export declare function normalizeHttpUrl(value: string, flag: string): string;
|
|
9
|
+
export declare function normalizeTimezone(value: string, flag: string): string;
|
|
10
|
+
export declare function closestChoice(value: string, allowed: readonly string[]): string | null;
|