@hadooppei/hwcode 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,91 @@
1
+ ---
2
+ name: hwcode-cloud
3
+ description: Run a credential-isolated, approval-gated cloud planning and deployment workflow. Use only after the /hwcode-cloud command has selected and validated a provider account.
4
+ ---
5
+
6
+ # HWCode Cloud
7
+
8
+ Use this skill only after `/hwcode-cloud` has activated the workflow. The activation message is authoritative for the locked project root, selected provider, whether the current project should be deployed, and the user's objective.
9
+
10
+ ## Non-negotiable security rules
11
+
12
+ - Never ask for, display, infer, copy, log, summarize, or place credentials in chat, shell text, source files, environment files, tool arguments, plans, or session artifacts.
13
+ - Never read `~/.hwcode/cloud/credentials.enc`. The extension owns encryption, decryption, and credential injection.
14
+ - Use `hwcode_cloud_exec` for every provider CLI, Terraform/OpenTofu, Pulumi, kubectl, or Helm operation. Direct Bash use for those commands is forbidden.
15
+ - Keep project reads, writes, builds, manifests, and generated artifacts inside the locked project root. External paths require the workflow guard's one-call approval.
16
+ - Prefer short-lived, least-privilege identities and narrowly scoped roles. Never widen permissions merely to bypass an authorization error without explaining the exact missing permission and obtaining approval.
17
+ - Do not expose sensitive values returned by a provider. If output unexpectedly contains a secret, do not repeat it; tell the user to rotate it.
18
+
19
+ ## Phase 1: Establish facts
20
+
21
+ The command already collected the provider, deployment choice, objective, and validated account connection. Do not repeat those questions unless the activation context is contradictory.
22
+
23
+ Inspect the project only as needed to determine:
24
+
25
+ - application type, build and runtime requirements;
26
+ - existing IaC, container, Kubernetes, CI/CD, and environment configuration;
27
+ - expected domains, networking, data stores, secrets, observability, scaling, and recovery needs;
28
+ - provider region/account/subscription/project identity using read-only `hwcode_cloud_exec` calls;
29
+ - which resources already exist and should be reused.
30
+
31
+ Ask concise follow-up questions when the objective lacks a material decision such as region, environment name, public exposure, data durability, budget, compliance, availability, or acceptable downtime. Do not guess choices with financial or security impact.
32
+
33
+ ## Phase 2: Present an execution plan
34
+
35
+ Before modifying account resources, present a plan containing:
36
+
37
+ 1. target architecture and provider services;
38
+ 2. resources to reuse, create, modify, and potentially delete;
39
+ 3. local project changes and generated IaC artifacts;
40
+ 4. security boundaries, identity permissions, secret handling, and network exposure;
41
+ 5. rollout, verification, observability, rollback, and estimated cost drivers;
42
+ 6. ordered commands and their expected resource impact.
43
+
44
+ Prefer declarative, reviewable, idempotent infrastructure as code. Use a plan/dry-run command before apply when the selected tooling supports it. Pin important versions and avoid provider defaults that materially affect cost or exposure.
45
+
46
+ ## Phase 3: Execute with approval gates
47
+
48
+ For every `hwcode_cloud_exec` call:
49
+
50
+ - set `operation` to `read`, `change`, or `delete` honestly;
51
+ - provide a concise `intent` understandable without reading the raw command;
52
+ - use a stable `approach` name for the current technical strategy;
53
+ - pass an executable and argument vector, never shell syntax;
54
+ - inspect the result before proceeding.
55
+
56
+ The extension confirms every account-resource create or modification unless the user selects session-wide approval for non-delete changes. A deletion is always confirmed separately, even after that opt-out.
57
+
58
+ Local source changes still follow normal HWCode safeguards. Validate configuration locally before any apply. After changes, perform provider-side health checks and application-level smoke tests. Compare the final state with the stated objective.
59
+
60
+ ## Failure budget
61
+
62
+ An approach is a materially different technical strategy, not a renamed retry. Examples include switching from a managed deployment service to Kubernetes, changing the authentication path, or replacing a failing IaC provider with the provider CLI. Parameter tweaks, transient retries, and rerunning the same command remain one approach.
63
+
64
+ When a command fails:
65
+
66
+ 1. identify the concrete cause from safe output;
67
+ 2. decide whether to repair the current approach or adopt a genuinely different one;
68
+ 3. keep the same `approach` value for repairs and retries;
69
+ 4. explain any new risks before switching strategy.
70
+
71
+ After three genuinely different approaches fail, stop all execution. Tell the user that the objective cannot be completed in this run and provide:
72
+
73
+ - the concrete cause of each failed approach;
74
+ - completed local and cloud-side changes;
75
+ - resources that may still exist and their state;
76
+ - verification already performed;
77
+ - rollback or cleanup still required, noting that cleanup deletions need confirmation;
78
+ - the smallest next action that could unblock a future attempt.
79
+
80
+ Do not attempt a fourth approach.
81
+
82
+ ## Completion
83
+
84
+ On success, summarize:
85
+
86
+ - deployed architecture and endpoints;
87
+ - created, changed, reused, and deleted resources;
88
+ - local files changed;
89
+ - verification results;
90
+ - ongoing cost, security, monitoring, backup, and credential-rotation considerations;
91
+ - rollback and teardown procedure (do not execute teardown unless separately requested and approved).
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "HWCode Cloud"
3
+ short_description: "Approval-gated, credential-isolated cloud deployment workflow"
4
+ default_prompt: "Use $hwcode-cloud after /hwcode-cloud has validated the selected cloud account."
package/.pi/welcome.json CHANGED
@@ -9,7 +9,9 @@
9
9
  "success",
10
10
  "warning"
11
11
  ],
12
- "subtitle": "Local AI Coding Workspace",
12
+ "subtitle": "Local HuaweiCloud AI Coding Workspace",
13
13
  "subtitleColor": "muted",
14
- "reservedRows": 8
14
+ "reservedRows": 8,
15
+ "logoScale": 0.82,
16
+ "verticalOffsetRows": 1
15
17
  }
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # HWCode
2
2
 
3
3
  A customizable terminal coding agent built on Pi, with local-model providers,
4
- persistent working directories, a tailored TUI, and Vibe/SDD workflows.
4
+ persistent working directories, a tailored TUI, and Vibe/SDD/Cloud workflows.
5
5
 
6
6
  ## Install
7
7
 
@@ -18,10 +18,14 @@ cd your-project
18
18
  hwcode
19
19
  ```
20
20
 
21
- `npx @hadooppei/hwcode` is also supported without a global installation. HWCode loads a
22
- project's `.env` file when present and keeps Pi's normal user-level auth and
23
- session storage. Project-local `.pi` resources continue to load alongside the
24
- built-in HWCode profile.
21
+ Run `hwcode --help` for the HWCode command reference, including model,
22
+ session, tool, and workflow options.
23
+
24
+ `npx @hadooppei/hwcode` is also supported without a global installation. HWCode
25
+ loads a project's `.env` file when present and keeps Pi's normal user-level auth
26
+ and session storage. Project-local Pi resources continue to load alongside the
27
+ built-in HWCode profile, except for HWCode's package-scoped model-provider
28
+ definition described below.
25
29
 
26
30
  ## Repository setup
27
31
 
@@ -35,45 +39,31 @@ On first launch, review and accept Pi's project-trust prompt so it can load the
35
39
 
36
40
  ## Model providers
37
41
 
38
- OpenAI-compatible providers are declared in `.pi/model-providers.json`.
39
- Static providers list their models directly:
42
+ The published `.pi/model-providers.json` is package-scoped and is not replaced
43
+ by a file in the current project. It registers the configurable `hw` provider
44
+ without shipping a machine-specific endpoint or a pre-populated model catalog.
45
+ Use Pi's native `/login` flow, select `Huawei MaaS`, and enter the endpoint and
46
+ API key. The key can instead come from `HW_API_KEY`. HWCode then discovers every model exposed by the
47
+ OpenAI-compatible endpoint and Pi stores the selected endpoint, credential, and
48
+ dynamic catalog in its user-level stores.
40
49
 
41
- ```json
42
- {
43
- "id": "local-example",
44
- "name": "Local example",
45
- "baseUrl": "http://127.0.0.1:8082",
46
- "apiKeyEnv": "PI_LOCAL_MODEL_API_KEY",
47
- "models": [
48
- {
49
- "id": "model-id",
50
- "input": ["text", "image"],
51
- "contextWindow": 32768,
52
- "maxTokens": 8192
53
- }
54
- ]
55
- }
56
- ```
57
-
58
- Login providers use Pi's native `/login` flow and discover every model exposed
59
- by an OpenAI-compatible model endpoint:
50
+ The published provider is equivalent to:
60
51
 
61
52
  ```json
62
53
  {
63
54
  "id": "hw",
64
- "name": "hw",
65
- "baseUrl": "http://127.0.0.1:8080/v1",
55
+ "name": "Huawei MaaS",
66
56
  "apiKeyEnv": "HW_API_KEY",
67
57
  "login": {
68
58
  "enabled": true,
69
59
  "promptBaseUrl": true,
70
60
  "promptApiKey": true,
71
- "apiKeyRequired": false,
61
+ "apiKeyRequired": true,
72
62
  "catalogPath": "models"
73
63
  },
74
64
  "modelDefaults": {
75
65
  "input": ["text"],
76
- "contextWindow": 32768,
66
+ "contextWindow": 1000000,
77
67
  "maxTokens": 8192
78
68
  }
79
69
  }
@@ -81,12 +71,14 @@ by an OpenAI-compatible model endpoint:
81
71
 
82
72
  `id` is the stable credential and cache key; `name` is the configurable label
83
73
  shown alongside other providers in `/login`. A login authenticates the whole
84
- provider and publishes its complete model catalog to `/model`. Entries in a
85
- login provider's `models` array are optional metadata overrides for discovered
86
- IDs, which is where vision support should be declared with
87
- `"input": ["text", "image"]`. Unknown models default to text-only. Keep real
88
- API keys in `.env` or enter them through `/login`; Pi stores entered credentials
89
- in its own auth store rather than the project configuration.
74
+ provider and publishes its complete model catalog to `/model`. Unknown models
75
+ default to text-only. Keep real API keys in `.env` or enter them through
76
+ `/login`; Pi stores entered credentials in its own auth store rather than the
77
+ package configuration.
78
+
79
+ Repository maintainers can refer to `.pi/model-providers.json.template` for the
80
+ previous local static-provider examples, including multimodal metadata. The
81
+ template is not loaded at runtime and is explicitly excluded from npm packages.
90
82
 
91
83
  ## Welcome screen
92
84
 
@@ -103,6 +95,7 @@ Start one of the project workflows from the Pi input:
103
95
  ```text
104
96
  /hwcode-vibe Build a small web application with me
105
97
  /hwcode-sdd Add role-based access control
98
+ /hwcode-cloud Deploy this service with a managed database
106
99
  ```
107
100
 
108
101
  Both commands first confirm the current directory and lock project work to that
@@ -113,6 +106,67 @@ to be the Git repository root, inventories the codebase, resolves requirement
113
106
  questions, and persists approved artifacts under
114
107
  `.hwcode/specs/<requirement-slug>/` before test-first implementation begins.
115
108
 
109
+ ### Cloud workflow
110
+
111
+ `/hwcode-cloud` interactively collects the cloud provider, whether the current
112
+ project should be deployed, and the concrete objective. It supports AWS, Azure,
113
+ Google Cloud, Huawei Cloud, Alibaba Cloud, and Tencent Cloud. Provider-specific
114
+ credentials are entered through masked prompts and validated before planning.
115
+
116
+ Credentials are encrypted with AES-256-GCM using a key derived from a user
117
+ master password and stored at `~/.hwcode/cloud/credentials.enc` with user-only
118
+ permissions. They are never added to model context or uploaded to an HWCode
119
+ service. Authentication necessarily sends them to the selected provider's
120
+ official endpoint or CLI. Google credential JSON is materialized only in a
121
+ user-only temporary file for the duration of a command. Azure CLI authentication
122
+ uses an isolated temporary configuration directory that is removed after each
123
+ command.
124
+
125
+ Multiple credential profiles can be saved for the same provider. On the next
126
+ Cloud workflow, HWCode offers each existing profile as
127
+ `使用已有凭据 [n] · Region: <region>` plus `新建凭据`; only the region and an
128
+ ordinal are displayed. Legacy vaults containing one credential per provider are
129
+ migrated in memory and written in the multi-profile format after the next
130
+ successful validation.
131
+
132
+ Cloud and infrastructure commands run through a credential-isolated tool.
133
+ Read-only calls run directly. Account-resource creates and changes require user
134
+ confirmation unless the user approves remaining non-delete changes for the
135
+ session. Resource deletion is always confirmed. After three genuinely distinct
136
+ technical approaches fail, the workflow stops and reports causes, progress,
137
+ remaining resources, and local changes instead of attempting a fourth approach.
138
+
139
+ After at least one cloud command succeeds, run
140
+ `/hwcode-cloud-save-template [name]` to save the objective, validated execution
141
+ sequence, and optional lessons learned as a local Prompt Template. Templates are
142
+ stored under `~/.hwcode/cloud/prompts/` with user-only permissions. Credential
143
+ values are excluded and redacted before steps are persisted.
144
+
145
+ Use `/hwcode-cloud-template [additional instructions]` to select and start a
146
+ saved template immediately. `/hwcode-cloud` also offers saved templates when it
147
+ starts without an inline request. The files use a Pi-compatible
148
+ Markdown/frontmatter format, but HWCode intentionally keeps them out of Pi
149
+ resource discovery so each saved template does not become another slash
150
+ command. Templates are extension-private resources and always run through the
151
+ fixed `/hwcode-cloud-template` entry point, preserving credential isolation and
152
+ Cloud approval guards.
153
+
154
+ ## Internal architecture
155
+
156
+ Extensions under `.pi/extensions/` are Pi-facing adapters: they register events,
157
+ commands, tools, and UI. Reusable behavior lives under `.pi/lib/`:
158
+
159
+ - `runtime/` owns layered/replacing configuration and session-state primitives.
160
+ - `workflows/` owns the shared Vibe/SDD/Cloud lifecycle schema.
161
+ - `workspace/` owns tool and command path-boundary decisions.
162
+ - `cloud/` owns provider adapters, isolated processes, and prompt templates.
163
+ - `context/` and `models/` own compaction and provider-configuration policy.
164
+
165
+ `settings.json` is layered as defaults → profile → project for settings such as
166
+ context and hidden commands. `welcome.json` uses a single replacing resource.
167
+ `model-providers.json` is deliberately package-scoped so a project cannot
168
+ silently replace login providers or reintroduce machine-local defaults.
169
+
116
170
  ## Working directory
117
171
 
118
172
  Use `/cd <path>` to change the working directory without starting a new
@@ -133,6 +187,44 @@ command. Restart Pi or manually enter `/reload` after changing the list.
133
187
  This setting controls visibility, not capability. A hidden command can still be
134
188
  entered manually when it is needed.
135
189
 
190
+ ## Context and compaction
191
+
192
+ HWCode defaults locally configured and dynamically discovered models to a
193
+ 1,000,000-token context window and caps configured or provider-reported values
194
+ at that limit. If an OpenAI-compatible model catalog reports a smaller
195
+ `context_window`, `context_length`, `max_context_length`, `max_model_len`, or
196
+ `n_ctx`, the smaller server value wins. The package-scoped provider's
197
+ `modelDefaults.contextWindow` can also select a smaller limit for dynamically
198
+ discovered models.
199
+
200
+ The default context policy is configured under `hwcode.context` in
201
+ `.pi/settings.json`:
202
+
203
+ ```json
204
+ {
205
+ "compaction": {
206
+ "enabled": true,
207
+ "reserveTokens": 80000,
208
+ "keepRecentTokens": 220000
209
+ },
210
+ "hwcode": {
211
+ "context": {
212
+ "defaultContextWindow": 1000000,
213
+ "maxContextWindow": 1000000,
214
+ "compactionTriggerTokens": 920000,
215
+ "compactionTargetTokens": 300000,
216
+ "compactionOverheadTokens": 80000
217
+ }
218
+ }
219
+ }
220
+ ```
221
+
222
+ For a 1M model, HWCode starts compaction around 920K and retains up to 220K of
223
+ recent messages, reserving 80K for the system prompt, tools, and summary so the
224
+ result remains within the 300K target. The policy scales proportionally for
225
+ smaller models. A single indivisible message larger than the target cannot be
226
+ silently truncated; HWCode keeps it and displays a warning instead.
227
+
136
228
  ## Project resources
137
229
 
138
230
  - `AGENTS.md`: project-wide working rules
package/bin/hwcode.js CHANGED
@@ -15,15 +15,85 @@ const piCli = join(
15
15
  "dist",
16
16
  "cli.js",
17
17
  );
18
+ const packageJson = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
18
19
  const userArgs = process.argv.slice(2);
20
+
21
+ function helpText() {
22
+ return `HWCode ${packageJson.version} — 可定制的终端 AI 编程助手
23
+
24
+ 用法:
25
+ hwcode [选项] [@文件...] [指令...]
26
+ hwcode <管理命令> [选项]
27
+
28
+ 启动与会话:
29
+ hwcode 在当前目录启动交互式 TUI
30
+ hwcode "分析这个项目" 启动并发送首条指令
31
+ hwcode -p "列出所有 API" 非交互执行一次任务
32
+ hwcode -c 继续当前项目最近一次会话
33
+ hwcode -r 选择历史会话恢复
34
+ hwcode --session <路径或 ID> 打开指定会话
35
+ hwcode --no-session 使用不落盘的临时会话
36
+
37
+ 模型选项:
38
+ --provider <名称> 指定模型提供商
39
+ --model <名称> 指定模型,支持 provider/model
40
+ --models <模式列表> 限定模型切换范围
41
+ --api-key <密钥> 为本次运行提供 API Key
42
+ --thinking <级别> off|minimal|low|medium|high|xhigh|max
43
+
44
+ 运行模式与工具:
45
+ -p, --print 非交互模式,完成后退出
46
+ --mode <模式> text|json|rpc
47
+ --tools <工具列表> 只启用指定工具
48
+ --exclude-tools <工具列表> 禁用指定工具
49
+ --no-tools 禁用全部工具
50
+ --tui-mode <模式> fullscreen|regular
51
+ --offline 禁止启动时的网络操作
52
+ -a, --approve 本次运行信任项目本地资源
53
+ -na, --no-approve 本次运行忽略项目本地资源
54
+
55
+ HWCode 交互命令:
56
+ /hwcode-vibe [需求] 启动持续对话式 Vibe Coding workflow
57
+ /hwcode-sdd [需求] 启动测试优先的 Spec-Driven workflow
58
+ /hwcode-cloud [需求] 启动凭据隔离、变更审批的云部署 workflow
59
+ /hwcode-cloud-template [补充] 从本地成功模板启动 Cloud workflow
60
+ /hwcode-cloud-save-template 将成功执行路径保存为本地 Prompt Template
61
+ /cd <目录> 持久切换当前会话工作目录
62
+ /model 选择模型
63
+ /login 登录或配置模型提供商
64
+ /new 新建会话
65
+ /resume 恢复历史会话
66
+
67
+ 管理命令:
68
+ auth <命令> 查看认证状态或读取凭据
69
+ config 管理已安装的资源
70
+ install <来源> 安装扩展包
71
+ remove <来源> 移除扩展包
72
+ update [来源] 更新扩展或运行时
73
+ list 列出已安装扩展
74
+
75
+ 其他选项:
76
+ -h, --help 显示此帮助
77
+ -v, --version 显示 HWCode 版本
78
+
79
+ 示例:
80
+ hwcode
81
+ hwcode --model hw/Qwen3.5-9B-Q4_K_M
82
+ hwcode -p "总结当前代码库"
83
+ hwcode @README.md "检查文档是否完整"
84
+
85
+ 项目中的 .env 会自动加载;模型 Provider 使用 HWCode 发布配置,其余项目本地 .pi 资源照常生效。`;
86
+ }
87
+
88
+ if (userArgs[0] === "--help" || userArgs[0] === "-h") {
89
+ console.log(helpText());
90
+ process.exit(0);
91
+ }
19
92
  if (userArgs[0] === "--version" || userArgs[0] === "-v") {
20
- const packageJson = JSON.parse(readFileSync(join(packageRoot, "package.json"), "utf8"));
21
93
  console.log(packageJson.version);
22
94
  process.exit(0);
23
95
  }
24
96
  const piManagementCommands = new Set([
25
- "--help",
26
- "-h",
27
97
  "auth",
28
98
  "config",
29
99
  "install",
@@ -44,6 +114,8 @@ const profileArgs = [
44
114
 
45
115
  for (const extension of [
46
116
  "command-filter.ts",
117
+ "cloud.ts",
118
+ "context-policy.ts",
47
119
  "cwd.ts",
48
120
  "footer-tps.ts",
49
121
  "hwcode.ts",
@@ -54,7 +126,7 @@ for (const extension of [
54
126
  profileArgs.push("--extension", join(profileDirectory, "extensions", extension));
55
127
  }
56
128
 
57
- for (const skill of ["hwcode-vibe", "hwcode-sdd"]) {
129
+ for (const skill of ["hwcode-vibe", "hwcode-sdd", "hwcode-cloud"]) {
58
130
  profileArgs.push("--skill", join(profileDirectory, "skills", skill));
59
131
  }
60
132
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hadooppei/hwcode",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "A customizable terminal coding agent with local-model support and HWCode workflows.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,15 +10,14 @@
10
10
  "bin/hwcode.js",
11
11
  ".env.example",
12
12
  ".pi/APPEND_SYSTEM.md",
13
+ ".pi/settings.json",
13
14
  ".pi/extensions",
14
- ".pi/lib/command-filter.ts",
15
- ".pi/lib/pixel-font.ts",
16
- ".pi/lib/welcome-input.ts",
17
- ".pi/lib/workflow-guard.ts",
18
- ".pi/lib/working-directory.ts",
15
+ ".pi/lib",
16
+ "!.pi/lib/*.test.ts",
19
17
  ".pi/model-providers.json",
20
18
  ".pi/skills/hwcode-sdd",
21
19
  ".pi/skills/hwcode-vibe",
20
+ ".pi/skills/hwcode-cloud",
22
21
  ".pi/welcome.json",
23
22
  "README.md"
24
23
  ],
@@ -27,7 +26,7 @@
27
26
  "pi": "node --env-file-if-exists=.env ./bin/hwcode.js",
28
27
  "test": "node --test .pi/lib/*.test.ts",
29
28
  "test:workflows": "npm test",
30
- "prepack": "npm test"
29
+ "prepack": "npm test && node scripts/audit-package.mjs"
31
30
  },
32
31
  "engines": {
33
32
  "node": ">=22.19.0"
@@ -46,6 +45,8 @@
46
45
  "registry": "https://registry.npmjs.org/"
47
46
  },
48
47
  "dependencies": {
49
- "@earendil-works/pi-coding-agent": "0.84.2"
48
+ "@earendil-works/pi-ai": "0.84.2",
49
+ "@earendil-works/pi-coding-agent": "0.84.2",
50
+ "@earendil-works/pi-tui": "0.84.2"
50
51
  }
51
52
  }