@huaweidevtools/aishell-dsh-deploy 0.0.0-stage → 0.0.1-beta.4

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.
Files changed (46) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +164 -2
  3. package/cordis.patch.yml +15 -0
  4. package/lib/data/permission-registry.json +1 -0
  5. package/lib/data/terraform-examples.zip +0 -0
  6. package/lib/index.js +4796 -0
  7. package/lib/types/auth-http.d.ts +44 -0
  8. package/lib/types/auth-obs-signer.d.ts +46 -0
  9. package/lib/types/auth-signer.d.ts +46 -0
  10. package/lib/types/bridge.d.ts +70 -0
  11. package/lib/types/credentials.d.ts +105 -0
  12. package/lib/types/data-paths.d.ts +70 -0
  13. package/lib/types/deployment-state.d.ts +69 -0
  14. package/lib/types/gates/cost_gate.d.ts +24 -0
  15. package/lib/types/gates/credential_gate.d.ts +21 -0
  16. package/lib/types/gates/mirror.d.ts +27 -0
  17. package/lib/types/gates/networking_gate.d.ts +9 -0
  18. package/lib/types/gates/terraform_env.d.ts +26 -0
  19. package/lib/types/index.d.ts +96 -0
  20. package/lib/types/permission/gate.d.ts +87 -0
  21. package/lib/types/permission/mode.d.ts +69 -0
  22. package/lib/types/permission/registry.d.ts +109 -0
  23. package/lib/types/permission-context.d.ts +84 -0
  24. package/lib/types/permission-route.d.ts +78 -0
  25. package/lib/types/permission.d.ts +37 -0
  26. package/lib/types/prompt.d.ts +59 -0
  27. package/lib/types/schemas/cost.d.ts +108 -0
  28. package/lib/types/schemas/networking.d.ts +115 -0
  29. package/lib/types/security-groups.d.ts +43 -0
  30. package/lib/types/tools/annotations.d.ts +94 -0
  31. package/lib/types/tools/balance_summary.d.ts +69 -0
  32. package/lib/types/tools/cost.d.ts +16 -0
  33. package/lib/types/tools/deployment.d.ts +14 -0
  34. package/lib/types/tools/errors.d.ts +40 -0
  35. package/lib/types/tools/examples.d.ts +4 -0
  36. package/lib/types/tools/existing_resources.d.ts +29 -0
  37. package/lib/types/tools/index.d.ts +32 -0
  38. package/lib/types/tools/networking.d.ts +13 -0
  39. package/lib/types/tools/openapi.d.ts +113 -0
  40. package/lib/types/tools/provider_schema.d.ts +19 -0
  41. package/lib/types/tools/terraform.d.ts +32 -0
  42. package/lib/types/types.d.ts +84 -0
  43. package/lib/types/utils/hash.d.ts +11 -0
  44. package/lib/types/utils/tar.d.ts +29 -0
  45. package/lib/types/version.d.ts +18 -0
  46. package/package.json +59 -3
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Signed HTTP client — single source of truth for sign + fetch.
3
+ *
4
+ * All signed requests to HuaweiCloud APIs from this plugin's tools go through
5
+ * here: openapi_request, list_existing_resources, balance_summary. Keeping the
6
+ * sign+fetch in one place means signing headers, retries, and error handling
7
+ * are maintained once.
8
+ *
9
+ * Credentials come from one of two places:
10
+ * - Default (no `creds` arg): the plugin's credential store, read per call
11
+ * via `loadCredentials`.
12
+ * - Explicit `creds` arg: a caller that already holds the pair.
13
+ *
14
+ * IAM *verification* no longer runs through here — it moved to the shared
15
+ * `credentials-store/verify` module when `auth` moved to `aishell-credentials`.
16
+ * This client stays the funnel for the cloud calls the tools make, which is
17
+ * what the read-only gate below needs to cover.
18
+ *
19
+ * Verified end-to-end against HuaweiCloud APIs:
20
+ * - IAM GET /v3/projects → 200
21
+ * - BSS GET /v2/accounts/customer-accounts/balances → 200
22
+ * - BSS GET /v2/promotions/benefits/coupons → 200
23
+ */
24
+ import { type Credentials } from "./credentials.js";
25
+ export interface SignedHttpResponse {
26
+ status: number;
27
+ headers: Record<string, string>;
28
+ body: string;
29
+ }
30
+ /**
31
+ * Send a signed HTTP request to a HuaweiCloud API endpoint.
32
+ *
33
+ * The request is signed with SDK-HMAC-SHA256 (signer.ts). Host header is set
34
+ * automatically; caller-provided headers are merged on top.
35
+ *
36
+ * @param creds optional explicit credentials. Omit to read the plugin store
37
+ * (the normal path).
38
+ * @throws if not authenticated (call auth first) — only when `creds` is
39
+ * omitted and no credentials are stored.
40
+ * @throws if read-only mode is in effect and the request is not a permitted
41
+ * read. The gate is unconditional — see permission/gate.ts.
42
+ */
43
+ export declare function signedHttp(method: string, url: URL, body: string, extraHeaders?: Record<string, string>, creds?: Credentials): Promise<SignedHttpResponse>;
44
+ //# sourceMappingURL=auth-http.d.ts.map
@@ -0,0 +1,46 @@
1
+ /**
2
+ * OBS (Object Storage Service) V2/OBS request signing.
3
+ *
4
+ * OBS uses a signature scheme completely separate from IAM's SDK-HMAC-SHA256:
5
+ * - Algorithm: HMAC-SHA1, base64-encoded (not HMAC-SHA256 hex)
6
+ * - Authorization header: `OBS <AK>:<Signature>` (not `SDK-HMAC-SHA256 Access=...`)
7
+ * - StringToSign: six segments — HTTP-Verb, Content-MD5, Content-Type, Date,
8
+ * CanonicalizedHeaders, CanonicalizedResource — joined by "\n"
9
+ * - Date header: RFC 1123 GMT (not X-Sdk-Date)
10
+ *
11
+ * Ported from esdk-obs-nodejs 3.26.8 `doAuth` (utils.js line 1497-1578). The
12
+ * SDK is CommonJS + log4js + callback-style + signature-negotiation; importing
13
+ * it would pollute the ESM architecture, so the algorithm is ported instead.
14
+ * The signing logic is HuaweiCloud's public spec — no copyright concern.
15
+ *
16
+ * Verified against the SDK source at /home/eushing/Downloads/utils.js.
17
+ */
18
+ export interface ObsSigningParams {
19
+ method: string;
20
+ url: URL;
21
+ /** Caller-populated headers. Mutated in place: Authorization, Date, and
22
+ * x-obs-security-token (if STS) are added. Content-Type/Content-MD5, if
23
+ * present, participate in the signature. */
24
+ headers: Record<string, string>;
25
+ /** Request body. GET/HEAD/DELETE pass "". For PUT, the body content. The
26
+ * body itself is NOT directly in the StringToSign — Content-MD5 (if set)
27
+ * is the body's signature entry. */
28
+ body: string;
29
+ ak: string;
30
+ sk: string;
31
+ /** STS token if using temporary credentials. */
32
+ securityToken?: string | undefined;
33
+ }
34
+ /**
35
+ * Sign a HuaweiCloud OBS API request. Mutates `params.headers` to add:
36
+ * - `Date` (RFC 1123 GMT) — if not already set by the caller
37
+ * - `x-obs-security-token` — if `securityToken` is provided
38
+ * - `Authorization` — `OBS <AK>:<base64 signature>`
39
+ *
40
+ * The caller must set Content-Type and Content-MD5 (when applicable) BEFORE
41
+ * calling this — they participate in the signature.
42
+ *
43
+ * @see https://support.huaweicloud.com/api-obs/obs_04_0010.html
44
+ */
45
+ export declare function signObsRequest(params: ObsSigningParams): void;
46
+ //# sourceMappingURL=auth-obs-signer.d.ts.map
@@ -0,0 +1,46 @@
1
+ /**
2
+ * SDK-HMAC-SHA256 request signing for HuaweiCloud APIs.
3
+ *
4
+ * openapi_request signs requests internally with AK/SK;
5
+ * the client never handles credentials. This implements the HuaweiCloud
6
+ * SDK-HMAC-SHA256 algorithm:
7
+ *
8
+ * 1. Build the canonical request (method, URI, query, headers, signed
9
+ * header list, hashed body).
10
+ * 2. Build the string-to-sign: "SDK-HMAC-SHA256\n<timestamp>\n<hash>".
11
+ * 3. The signing key is the SK itself (HuaweiCloud's scheme is simpler
12
+ * than AWS sigv4 — no date/region-derived key chain); the signature
13
+ * is HMAC-SHA256(sk, string-to-sign), hex-encoded.
14
+ *
15
+ * Status: verified end-to-end against real HuaweiCloud APIs:
16
+ * - IAM GET /v3/projects → 200
17
+ * - BSS GET /v2/accounts/customer-accounts/balances → 200
18
+ * - BSS GET /v2/promotions/benefits/coupons → 200
19
+ * The signer is production-ready. The shared signed HTTP client in
20
+ * auth/http.ts wraps this + fetch for all callers.
21
+ */
22
+ export interface SigningParams {
23
+ method: string;
24
+ url: URL;
25
+ headers: Record<string, string>;
26
+ body: string;
27
+ ak: string;
28
+ sk: string;
29
+ region: string;
30
+ /** STS token if using temporary credentials. */
31
+ securityToken?: string | undefined;
32
+ }
33
+ export interface SignedRequest {
34
+ method: string;
35
+ url: URL;
36
+ headers: Record<string, string>;
37
+ body: string;
38
+ }
39
+ /**
40
+ * Sign a HuaweiCloud API request. Mutates headers in place to add
41
+ * Authorization, X-Sdk-Date, and (if STS) X-Security-Token.
42
+ *
43
+ * @see https://support.huaweicloud.com/api-iam/iam_30_0001.html
44
+ */
45
+ export declare function signRequest(params: SigningParams): SignedRequest;
46
+ //# sourceMappingURL=auth-signer.d.ts.map
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The seam between the tool handlers and DSH's tool registry.
3
+ *
4
+ * ## What this module is
5
+ *
6
+ * The tool modules in `tools/` register themselves through `registerTool(name,
7
+ * declaration, handler)` and return `{ content, isError? }`. This module plays
8
+ * that registrar's role — collecting the declarations — and converts each one
9
+ * into a DSH `ToolDefinition`.
10
+ *
11
+ * ## Why the handlers are not rewritten
12
+ *
13
+ * Their result shape is a good internal contract: success and failure are
14
+ * explicit, and every diagnostic is somewhere the model reads. Flattening 5000
15
+ * lines of handlers into canonical values would be a mechanical diff across
16
+ * every file, and a mechanical diff is where a misplaced return hides until a
17
+ * tool runs. So the handlers stay, and this module is the only place that knows
18
+ * both vocabularies.
19
+ *
20
+ * ## What DSH needs that the handlers did not produce
21
+ *
22
+ * - **A canonical output value.** DSH tools return a lossless-JSON value and
23
+ * render it. That value is the result itself, so `structuredContent`
24
+ * survives for programmatic callers and `render` alone decides what the
25
+ * model reads.
26
+ * - **A failure that is really a failure.** `isError` becomes a rejection:
27
+ * DSH records rejection as a failed call, and an error payload returned as
28
+ * a value reads to the model as success.
29
+ * - **JSON Schema, not a zod object.** `parameters` is a JSON Schema, and the
30
+ * tools declare zod. The conversion happens once, at registration.
31
+ *
32
+ * @module @huaweidevtools/aishell-dsh-deploy/bridge
33
+ */
34
+ import type { ToolDefinition } from '@deepseek-ai/dsh-tools';
35
+ import type { CallToolResult, ToolContext, ToolRegistrar, ToolRegistrationConfig } from './types.ts';
36
+ /** One captured registration. */
37
+ interface CapturedTool {
38
+ readonly name: string;
39
+ readonly config: ToolRegistrationConfig;
40
+ readonly handler: (args: unknown, ctx: ToolContext) => Promise<CallToolResult>;
41
+ }
42
+ /**
43
+ * Collect the tools the `register*()` functions register.
44
+ *
45
+ * @returns the registrar the tool modules write into, and the list it fills.
46
+ */
47
+ export declare function createRegistrar(): {
48
+ readonly registrar: ToolRegistrar;
49
+ readonly captured: CapturedTool[];
50
+ };
51
+ /**
52
+ * The model-facing name for one tool.
53
+ *
54
+ * Registered as `aishell__<name>`. The prefix exists because this plugin is not
55
+ * the only source of cloud tools in a deployment, and a bare `terraform_apply`
56
+ * in a shared namespace is one collision away from calling someone else's tool.
57
+ *
58
+ * @param rawName - the tool's own name.
59
+ */
60
+ export declare function publicToolName(rawName: string): string;
61
+ /**
62
+ * Convert one registration into a DSH tool definition.
63
+ *
64
+ * @param tool - the captured registration.
65
+ * @param timeoutMs - per-call budget handed to the harness.
66
+ * @returns the definition to hand to `ctx.tools.register`.
67
+ */
68
+ export declare function toToolDefinition(tool: CapturedTool, timeoutMs: number): ToolDefinition;
69
+ export {};
70
+ //# sourceMappingURL=bridge.d.ts.map
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Credentials for this plugin's tools.
3
+ *
4
+ * The AK/SK pair comes from the one store AI Shell has — the `aishell-dsh-plugins`
5
+ * keyring the credential form writes — read through `readStoredPair`, the same
6
+ * function `aishell-llm`, `aishell-e2b` and `aishell-credentials` use. There is
7
+ * no adapter and no mirror here: a rotation in the form applies to the very
8
+ * next tool call, and a clear means what it says.
9
+ *
10
+ * Two things the shared store deliberately does not know, and this module
11
+ * supplies:
12
+ *
13
+ * 1. **The region.** Not a credential: a deployment choice the plugin config
14
+ * owns, applied to every signed call and to the terraform subprocess env.
15
+ * 2. **The account identity.** The store holds secrets and nothing else, so
16
+ * `{account_id, name}` is resolved from IAM on demand and cached for this
17
+ * process.
18
+ *
19
+ * @module @huaweidevtools/aishell-dsh-deploy/credentials
20
+ */
21
+ import type { CredentialsStore } from '@huaweidevtools/aishell-dsh-credentials-store';
22
+ /**
23
+ * One credential set, as the signing paths here take it.
24
+ *
25
+ * `region` rides alongside because every HuaweiCloud caller in this plugin
26
+ * needs one and none may guess: the plugin config decides it, not the store.
27
+ */
28
+ export interface Credentials {
29
+ readonly ak: string;
30
+ readonly sk: string;
31
+ readonly region: string;
32
+ /** Present only for STS (temporary) credentials. */
33
+ readonly securityToken?: string;
34
+ }
35
+ /**
36
+ * The account identity resolved from IAM.
37
+ *
38
+ * Diagnostics only — it names the account in the deployment snapshot and is
39
+ * used as an RMS path parameter.
40
+ */
41
+ export interface AccountIdentity {
42
+ readonly account_id: string;
43
+ readonly account_name: string;
44
+ }
45
+ /** How this module reaches the host: the plugin's store and its region. */
46
+ export interface CredentialSource {
47
+ /** The plugin's credential store; read per call, never captured. */
48
+ readonly store: CredentialsStore;
49
+ /** Region every signed request and terraform env carries. */
50
+ readonly region: string;
51
+ }
52
+ /**
53
+ * Bind the credential source. Called once from the plugin's `apply()`.
54
+ *
55
+ * A module-level setter carries a real hazard worth naming: it is
56
+ * process-wide, so two mounts of this plugin in one process would share the
57
+ * last-configured reader. That cannot happen under DSH — a loader row mounts
58
+ * once — and the alternative (threading a reader through 18 tool registrars)
59
+ * would touch every file for a case that does not exist.
60
+ *
61
+ * @param next - the store and region this plugin was configured with.
62
+ */
63
+ export declare function configureCredentials(next: CredentialSource): void;
64
+ /**
65
+ * Read the current credentials.
66
+ *
67
+ * @returns the pair with the configured region, or `undefined` when the AK/SK
68
+ * pair is incomplete.
69
+ */
70
+ export declare function readStoredCredentials(): Credentials | undefined;
71
+ /**
72
+ * Load credentials or fail with the remedy the model can act on.
73
+ *
74
+ * The message names the condition and stops: which control opens the credential
75
+ * form is the UI's business, and a tool message naming a button would be a
76
+ * second copy of that path to keep in step.
77
+ *
78
+ * @returns the credentials in hand.
79
+ * @throws when nothing usable is stored.
80
+ */
81
+ export declare function loadCredentials(): Promise<Credentials>;
82
+ /** Whether a complete AK/SK pair is stored. */
83
+ export declare function hasCredentials(): boolean;
84
+ /**
85
+ * Resolve and cache the account identity.
86
+ *
87
+ * Verification goes through the shared `verifyCredentials`, so "is this
88
+ * account" is answered by the same call the credential form uses — no second
89
+ * notion of validity.
90
+ *
91
+ * @returns the identity, or `undefined` when the stored credentials cannot be
92
+ * verified. A missing identity is diagnostic-only, so this never fails a tool
93
+ * call; `list_existing_resources` is the one tool that turns it into its own
94
+ * error, because RMS needs the id as a path parameter.
95
+ */
96
+ export declare function loadAccount(): Promise<AccountIdentity | undefined>;
97
+ /**
98
+ * Drop the cached identity, so the next read resolves it again.
99
+ *
100
+ * Called when the stored credentials change: the account a deployment is
101
+ * recorded under must follow the credentials in hand, not the ones this
102
+ * process started with.
103
+ */
104
+ export declare function forgetAccount(): void;
105
+ //# sourceMappingURL=credentials.d.ts.map
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Where the shipped data files live at runtime.
3
+ *
4
+ * ## Why this is one module
5
+ *
6
+ * Two files ship beside the code and are read at call time: the read-only
7
+ * registry (the table that decides whether an arbitrary URL is a query) and the
8
+ * terraform examples archive.
9
+ *
10
+ * This package is bundled by tsdown into a single `lib/index.js`, so every
11
+ * `import.meta.url` points at that one file. A path written relative to an
12
+ * individual source module would therefore resolve one level too far up —
13
+ * outside the package. The failure would be a missing-data error at the first
14
+ * `openapi_request` or example export, long after the build looked fine.
15
+ *
16
+ * So both lookups go through here, against one directory: `lib/data/`, where
17
+ * the build puts them (see `build:bundle` in `package.json`).
18
+ *
19
+ * ## Why not resolve from `process.cwd()`
20
+ *
21
+ * Because the cwd is the user's workspace. A deployment directory can contain
22
+ * anything, including a `lib/data/permission-registry.json` that would then
23
+ * decide what this plugin considers read-only — a policy file a model's tool
24
+ * call could influence. The plugin's own install location is the only safe
25
+ * base.
26
+ *
27
+ * ## Per-host state, which is different
28
+ *
29
+ * Shipped data is read-only and lives with the code. State this plugin
30
+ * *writes* — the terraform binary cache and provider plugins — belongs beside
31
+ * the rest of the host's data, so it survives a reinstall and is shared by
32
+ * every profile rather than duplicated per package version.
33
+ *
34
+ * That base directory is defined once, in `credentials-store/paths`: this
35
+ * package already depends on the store, so taking it from there keeps one
36
+ * definition rather than adding a second that can drift.
37
+ *
38
+ * @module @huaweidevtools/aishell-dsh-deploy/data-paths
39
+ */
40
+ /**
41
+ * The directory holding the shipped data files.
42
+ *
43
+ * Resolved from this module's own URL. Because the bundle is flat, this file
44
+ * and `lib/index.js` share a directory once compiled, so the result is
45
+ * `<package>/lib/data` in the installed package; the test run exercises the
46
+ * same resolution through the source tree.
47
+ */
48
+ export declare const DATA_DIR: string;
49
+ /**
50
+ * Path of one data file.
51
+ *
52
+ * @param name - file name inside the data directory.
53
+ * @returns its absolute path.
54
+ */
55
+ export declare function dataFile(name: string): string;
56
+ /**
57
+ * The terraform directory: binary cache and provider plugins.
58
+ *
59
+ * Created on demand by the caller that writes into it. Kept as one root rather
60
+ * than a bare `bin`/`plugins` pair so every path under it resolves through
61
+ * `join`, and so a future artifact has an obvious home.
62
+ *
63
+ * @returns `<DSH_HOME>/terraform`; not created here.
64
+ */
65
+ export declare function terraformRoot(): string;
66
+ /** The terraform binary cache: `<DSH_HOME>/terraform/bin`. */
67
+ export declare function terraformBinDir(): string;
68
+ /** The terraform provider-plugin cache: `<DSH_HOME>/terraform/plugins`. */
69
+ export declare function terraformPluginDir(): string;
70
+ //# sourceMappingURL=data-paths.d.ts.map
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Deployment workspace state (§4.3 .deployment.json).
3
+ *
4
+ * A deployment directory is identified by the presence of
5
+ * .deployment.json. The file holds a status snapshot — not an operation
6
+ * log. The tools update it on each state change (update_networking /
7
+ * update_cost / terraform_apply / terraform_destroy). The model never writes
8
+ * this file directly.
9
+ */
10
+ export declare const DEPLOYMENT_STATE_FILE = ".deployment.json";
11
+ export interface DeploymentSnapshot {
12
+ created_at: string;
13
+ created_with: string;
14
+ server_version: string;
15
+ account?: {
16
+ name: string;
17
+ account_id: string;
18
+ };
19
+ status: {
20
+ networking_written: boolean;
21
+ cost_written: boolean;
22
+ applied: boolean;
23
+ destroyed: boolean;
24
+ last_operation: string;
25
+ last_operation_at: string;
26
+ };
27
+ }
28
+ /** Check whether a directory is a deployment (has .deployment.json). */
29
+ export declare function isDeploymentDir(dir: string): Promise<boolean>;
30
+ /** Create a deployment directory + initial .deployment.json. Refuse if non-empty. */
31
+ export declare function ensureDeployment(dir: string): Promise<DeploymentSnapshot>;
32
+ /** Update the status snapshot (called by other modules after state changes). */
33
+ export declare function updateSnapshot(dir: string, patch: Partial<DeploymentSnapshot["status"]> & {
34
+ last_operation: string;
35
+ }): Promise<void>;
36
+ /**
37
+ * Backfill the account field in .deployment.json if it's empty and the
38
+ * server is now authenticated (§4.3: "后续 auth 后 server 操作该 deployment
39
+ * 时补写").
40
+ *
41
+ * Called by runTerraform after resolveTerraformEnv succeeds. The account
42
+ * identity was resolved at auth time (GET /v3/projects → domain_id + name)
43
+ * and stored alongside the credentials; runTerraform reads it via
44
+ * loadAccount() — no IAM re-query here. This is a stateless write: the
45
+ * account is only backfilled once (idempotent — already-filled is a no-op).
46
+ *
47
+ * This is intentionally a no-op when:
48
+ * - the deployment has no .deployment.json (not a deployment dir)
49
+ * - account is already filled (idempotent)
50
+ * - loadAccount returns null (not authenticated, or payload predates
51
+ * IAM verification wiring)
52
+ */
53
+ export declare function backfillAccount(dir: string, account: {
54
+ name: string;
55
+ account_id: string;
56
+ }): Promise<void>;
57
+ /**
58
+ * Count resources recorded in terraform.tfstate (0 = clean / never applied).
59
+ *
60
+ * This is the count RECORDED in the state file, NOT the live count on the
61
+ * cloud — tfstate may be stale if resources were changed outside terraform.
62
+ * For the live count, run terraform_refresh first. Used by delete_deployment
63
+ * and terraform_destroy to guard against destroying/emptying a deployment
64
+ * that still has recorded resources.
65
+ */
66
+ export declare function stateRecordedResourceCount(dir: string): Promise<number>;
67
+ /** Remove the deployment directory. */
68
+ export declare function removeDeploymentDir(dir: string): Promise<void>;
69
+ //# sourceMappingURL=deployment-state.d.ts.map
@@ -0,0 +1,24 @@
1
+ /**
2
+ * cost_gate.ts — cost.json existence + tf_hash state machine (§6.3 门 2+3).
3
+ *
4
+ * The tf_hash logic:
5
+ * - cost.json written BEFORE .tf, so tf_hash is null on write
6
+ * - null → allow (first time / last apply failed); fill hash after success
7
+ * - non-null → recompute current .tf SHA256, compare; mismatch rejects
8
+ *
9
+ * "Fill after success, not before" (§4.1): apply failure doesn't fill,
10
+ * so retry after a bug fix doesn't demand a pointless cost recompute.
11
+ */
12
+ import type { Cost } from "../schemas/cost.js";
13
+ export declare function loadCost(dir: string): Promise<Cost>;
14
+ export declare function costJsonExists(dir: string): Promise<boolean>;
15
+ /**
16
+ * Run the cost gate. Returns the cost.json (with its tf_hash) so the
17
+ * caller can fill it after a successful apply.
18
+ *
19
+ * @throws Error if cost.json missing or tf_hash mismatch
20
+ */
21
+ export declare function runCostGate(dir: string): Promise<Cost>;
22
+ /** Fill tf_hash in cost.json after a successful apply (§6.3). */
23
+ export declare function fillTfHash(dir: string): Promise<void>;
24
+ //# sourceMappingURL=cost_gate.d.ts.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * credential_gate.ts — plaintext credential scanner (§6.2).
3
+ *
4
+ * Deterministic grep for access_key/secret_key/security_token/password
5
+ * assignments in .tf files. Catches the most severe leak: credentials
6
+ * hardcoded into .tf. Whitelists var.xxx / data.xxx references (those are
7
+ * not plaintext values, though instructions still say don't define cred
8
+ * variables — the gate only catches the plaintext case).
9
+ *
10
+ * Mounted at terraform_init (early exposure) and terraform_apply (§6.3 门 4).
11
+ */
12
+ export interface CredentialFinding {
13
+ file: string;
14
+ line: number;
15
+ pattern: string;
16
+ }
17
+ /** Scan all .tf files (recursively, including modules/) for plaintext credentials. */
18
+ export declare function scanTfCredentials(dir: string): Promise<CredentialFinding[]>;
19
+ /** Throw if any plaintext credential is found. */
20
+ export declare function assertNoCredentials(dir: string): Promise<void>;
21
+ //# sourceMappingURL=credential_gate.d.ts.map
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Provider mirror config generator (§6.6 / mirror.go 思路).
3
+ *
4
+ * Generates <deployment>/.terraformrc with network_mirror / filesystem_mirror
5
+ * entries from a list of mirror URLs or paths. Terraform tries mirrors in
6
+ * order, then falls back to the official registry via a direct { exclude }
7
+ * block for providers not covered by the mirror (random, tls, ...).
8
+ *
9
+ * Only huaweicloud is excluded from the direct fallback — the default mirror
10
+ * covers just that provider, so auxiliary providers must still reach the
11
+ * registry.
12
+ *
13
+ * Mirror URL: https://mirrors.huaweicloud.com/terraform/
14
+ * is a registry.terraform.io mirror that hosts ONLY the huaweicloud provider.
15
+ * So the include MUST be scoped to huaweicloud; a broader include of all providers
16
+ * would route random/tls to this mirror and fail. The direct { exclude }
17
+ * block then forces huaweicloud to the mirror and lets everything else reach
18
+ * the official registry directly.
19
+ */
20
+ export declare const HUAWEICLOUD_PROVIDER_MIRRORS: string[];
21
+ /**
22
+ * Write <deployment>/.terraformrc with provider mirror config.
23
+ * Does NOT overwrite if the file already exists (user-provided).
24
+ * Returns the path, or null if no file was written.
25
+ */
26
+ export declare function writeProviderMirrorConfig(deployment: string, mirrors?: string[]): Promise<string | null>;
27
+ //# sourceMappingURL=mirror.d.ts.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ * networking_gate.ts — existence check for networking.json (§6.3 门 1).
3
+ *
4
+ * Weak gate: only proves the networking design was persisted. Cannot
5
+ * verify .tf matches the design (HCL semantics, needs AI).
6
+ */
7
+ export declare function networkingJsonExists(dir: string): Promise<boolean>;
8
+ export declare function assertNetworking(dir: string): Promise<void>;
9
+ //# sourceMappingURL=networking_gate.d.ts.map
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Stateless terraform execution environment resolver (§6.6).
3
+ *
4
+ * Each tool call is independent — nothing here remembers what terraform_install
5
+ * or terraform_init did. But the terraform subprocess needs to know: binary
6
+ * path, .terraformrc location, TF_PLUGIN_CACHE_DIR, and credential env.
7
+ *
8
+ * Every terraform tool (init/plan/apply/destroy/refresh/state) calls this
9
+ * before spawning. It re-derives from filesystem state — a few stat calls,
10
+ * no cross-call memory.
11
+ *
12
+ * Credential env is injected from the keychain (§5.5) — NEVER passed via
13
+ * tool parameters. The tool-param-controlled env is `extraEnv` — an array
14
+ * of KEY=VALUE strings merged onto the subprocess env (e.g. TF_LOG=DEBUG,
15
+ * TF_LOG_PROVIDER=OFF, TF_CLI_ARGS_plan=-refresh=false).
16
+ */
17
+ export interface ResolvedEnv {
18
+ binary: string;
19
+ env: Record<string, string>;
20
+ }
21
+ /**
22
+ * Resolve the terraform binary path + env for a deployment.
23
+ * Throws if no binary can be found.
24
+ */
25
+ export declare function resolveTerraformEnv(deployment: string, extraEnv?: string[]): Promise<ResolvedEnv>;
26
+ //# sourceMappingURL=terraform_env.d.ts.map
@@ -0,0 +1,96 @@
1
+ /**
2
+ * aishell deploy plugin — Huawei Cloud infrastructure tools for DSH.
3
+ *
4
+ * Terraform deployment workflows, OpenAPI calls, resource inventory and cost
5
+ * estimates, as tools the model calls. The tool implementations live in
6
+ * `tools/`, registered directly on the harness registry.
7
+ *
8
+ * ## What this plugin is
9
+ *
10
+ * One registration loop, one permission switch, one credential source.
11
+ *
12
+ * - `bridge.ts` converts each tool's declaration into a DSH tool definition.
13
+ * - `permission/mode.ts` holds the read-only switch; `permission/gate.ts`
14
+ * enforces it, at the signed-HTTP funnel and at the tool registry.
15
+ * - `credentials.ts` reads the AK/SK pair from the store
16
+ * `aishell-credentials` writes, through the shared vocabulary in
17
+ * `credentials-store/accounts`.
18
+ *
19
+ * There is no second process, no transport, and no protocol in between: a tool
20
+ * call runs in this process, and a credential rotation applies to the next
21
+ * call with nothing to restart.
22
+ *
23
+ * ## The permission switch
24
+ *
25
+ * The mode is process state here. The Host route the composer chip calls reads
26
+ * and writes it directly, so a switch takes effect before the next tool call
27
+ * starts. The gate itself is enforced in `permission/gate.ts` — a refusal
28
+ * cannot be talked around.
29
+ *
30
+ * ## What this plugin does not own
31
+ *
32
+ * Credentials. `aishell-credentials` owns the AK/SK form and the `aishell__auth`
33
+ * tool; this plugin only reads the store. Mounted without it, the tools
34
+ * register and every call fails with "not authenticated" until credentials
35
+ * exist.
36
+ *
37
+ * @module @huaweidevtools/aishell-dsh-deploy
38
+ */
39
+ import type { Context, Volatile } from '@deepseek-ai/cordis';
40
+ import z from '@deepseek-ai/schemastery';
41
+ /** Plugin config. */
42
+ export interface Config {
43
+ /** Region every signed request and terraform run uses; defaults to `'cn-north-4'`. */
44
+ readonly defaultRegion: Volatile<string>;
45
+ /**
46
+ * Per-call timeout in milliseconds.
47
+ *
48
+ * A real budget, not a formality: `terraform_apply` legitimately runs for
49
+ * minutes. Defaulted high-ish for that reason rather than to the seconds a
50
+ * lookup-shaped tool would want.
51
+ */
52
+ readonly toolCallTimeoutMs: Volatile<number>;
53
+ }
54
+ /**
55
+ * Settings schema.
56
+ *
57
+ * Every field is Volatile: each is a deployment fact that may differ between
58
+ * profiles, and a change should apply to the next call rather than require a
59
+ * restart. The bridge reads them through thunks for that reason.
60
+ */
61
+ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
62
+ defaultRegion: z<string, string, "volatile-defined">;
63
+ toolCallTimeoutMs: z<number, number, "volatile-defined">;
64
+ }>>, Schemastery.ObjectT<NoInfer<{
65
+ defaultRegion: z<string, string, "volatile-defined">;
66
+ toolCallTimeoutMs: z<number, number, "volatile-defined">;
67
+ }>>, "plain">;
68
+ export declare const name = "aishell-deploy";
69
+ /**
70
+ * Required services.
71
+ *
72
+ * `tools` is required: the whole point of this plugin is registering its tools.
73
+ * `connection` is required because the permission route registers on the host's
74
+ * authenticated fetch registry, and a plugin that silently lost its permission
75
+ * switch would leave every mutation at the default.
76
+ */
77
+ export declare const inject: string[];
78
+ export declare function apply(ctx: Context, config: Config): void;
79
+ declare module '@deepseek-ai/cordis' {
80
+ interface Events {
81
+ /**
82
+ * The stored Huawei Cloud credentials changed — a verified save, or a
83
+ * clear. Emitted by `aishell-credentials`, which owns the credential form
84
+ * and the store it writes.
85
+ *
86
+ * Declared here as well as on the emitting side because the two packages
87
+ * share no import: this is the whole interface between them. A listener
88
+ * reads the store itself; the event carries no value, so a secret can never
89
+ * ride on it.
90
+ *
91
+ * @mode on
92
+ */
93
+ 'aishell/credentials-updated'(): void;
94
+ }
95
+ }
96
+ //# sourceMappingURL=index.d.ts.map