@hadooppei/hwcode 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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,6 +18,9 @@ cd your-project
18
18
  hwcode
19
19
  ```
20
20
 
21
+ Run `hwcode --help` for the HWCode command reference, including model,
22
+ session, tool, and workflow options.
23
+
21
24
  `npx @hadooppei/hwcode` is also supported without a global installation. HWCode loads a
22
25
  project's `.env` file when present and keeps Pi's normal user-level auth and
23
26
  session storage. Project-local `.pi` resources continue to load alongside the
@@ -103,6 +106,7 @@ Start one of the project workflows from the Pi input:
103
106
  ```text
104
107
  /hwcode-vibe Build a small web application with me
105
108
  /hwcode-sdd Add role-based access control
109
+ /hwcode-cloud Deploy this service with a managed database
106
110
  ```
107
111
 
108
112
  Both commands first confirm the current directory and lock project work to that
@@ -113,6 +117,67 @@ to be the Git repository root, inventories the codebase, resolves requirement
113
117
  questions, and persists approved artifacts under
114
118
  `.hwcode/specs/<requirement-slug>/` before test-first implementation begins.
115
119
 
120
+ ### Cloud workflow
121
+
122
+ `/hwcode-cloud` interactively collects the cloud provider, whether the current
123
+ project should be deployed, and the concrete objective. It supports AWS, Azure,
124
+ Google Cloud, Huawei Cloud, Alibaba Cloud, and Tencent Cloud. Provider-specific
125
+ credentials are entered through masked prompts and validated before planning.
126
+
127
+ Credentials are encrypted with AES-256-GCM using a key derived from a user
128
+ master password and stored at `~/.hwcode/cloud/credentials.enc` with user-only
129
+ permissions. They are never added to model context or uploaded to an HWCode
130
+ service. Authentication necessarily sends them to the selected provider's
131
+ official endpoint or CLI. Google credential JSON is materialized only in a
132
+ user-only temporary file for the duration of a command. Azure CLI authentication
133
+ uses an isolated temporary configuration directory that is removed after each
134
+ command.
135
+
136
+ Multiple credential profiles can be saved for the same provider. On the next
137
+ Cloud workflow, HWCode offers each existing profile as
138
+ `使用已有凭据 [n] · Region: <region>` plus `新建凭据`; only the region and an
139
+ ordinal are displayed. Legacy vaults containing one credential per provider are
140
+ migrated in memory and written in the multi-profile format after the next
141
+ successful validation.
142
+
143
+ Cloud and infrastructure commands run through a credential-isolated tool.
144
+ Read-only calls run directly. Account-resource creates and changes require user
145
+ confirmation unless the user approves remaining non-delete changes for the
146
+ session. Resource deletion is always confirmed. After three genuinely distinct
147
+ technical approaches fail, the workflow stops and reports causes, progress,
148
+ remaining resources, and local changes instead of attempting a fourth approach.
149
+
150
+ After at least one cloud command succeeds, run
151
+ `/hwcode-cloud-save-template [name]` to save the objective, validated execution
152
+ sequence, and optional lessons learned as a local Prompt Template. Templates are
153
+ stored under `~/.hwcode/cloud/prompts/` with user-only permissions. Credential
154
+ values are excluded and redacted before steps are persisted.
155
+
156
+ Use `/hwcode-cloud-template [additional instructions]` to select and start a
157
+ saved template immediately. `/hwcode-cloud` also offers saved templates when it
158
+ starts without an inline request. The files use a Pi-compatible
159
+ Markdown/frontmatter format, but HWCode intentionally keeps them out of Pi
160
+ resource discovery so each saved template does not become another slash
161
+ command. Templates are extension-private resources and always run through the
162
+ fixed `/hwcode-cloud-template` entry point, preserving credential isolation and
163
+ Cloud approval guards.
164
+
165
+ ## Internal architecture
166
+
167
+ Extensions under `.pi/extensions/` are Pi-facing adapters: they register events,
168
+ commands, tools, and UI. Reusable behavior lives under `.pi/lib/`:
169
+
170
+ - `runtime/` owns layered/replacing configuration and session-state primitives.
171
+ - `workflows/` owns the shared Vibe/SDD/Cloud lifecycle schema.
172
+ - `workspace/` owns tool and command path-boundary decisions.
173
+ - `cloud/` owns provider adapters, isolated processes, and prompt templates.
174
+ - `context/` and `models/` own compaction and provider-configuration policy.
175
+
176
+ `settings.json` is layered as defaults → profile → project for settings such as
177
+ context and hidden commands. `welcome.json` and `model-providers.json` use a
178
+ single replacing resource, preferring project, then profile, then the bundled
179
+ default. This keeps configuration precedence consistent across extensions.
180
+
116
181
  ## Working directory
117
182
 
118
183
  Use `/cd <path>` to change the working directory without starting a new
@@ -133,6 +198,43 @@ command. Restart Pi or manually enter `/reload` after changing the list.
133
198
  This setting controls visibility, not capability. A hidden command can still be
134
199
  entered manually when it is needed.
135
200
 
201
+ ## Context and compaction
202
+
203
+ HWCode defaults locally configured and dynamically discovered models to a
204
+ 1,000,000-token context window and caps configured or provider-reported values
205
+ at that limit. If an OpenAI-compatible model catalog reports a smaller
206
+ `context_window`, `context_length`, `max_context_length`, `max_model_len`, or
207
+ `n_ctx`, the smaller server value wins. Per-model `contextWindow` values in
208
+ `.pi/model-providers.json` can also select a smaller limit.
209
+
210
+ The default context policy is configured under `hwcode.context` in
211
+ `.pi/settings.json`:
212
+
213
+ ```json
214
+ {
215
+ "compaction": {
216
+ "enabled": true,
217
+ "reserveTokens": 80000,
218
+ "keepRecentTokens": 220000
219
+ },
220
+ "hwcode": {
221
+ "context": {
222
+ "defaultContextWindow": 1000000,
223
+ "maxContextWindow": 1000000,
224
+ "compactionTriggerTokens": 920000,
225
+ "compactionTargetTokens": 300000,
226
+ "compactionOverheadTokens": 80000
227
+ }
228
+ }
229
+ }
230
+ ```
231
+
232
+ For a 1M model, HWCode starts compaction around 920K and retains up to 220K of
233
+ recent messages, reserving 80K for the system prompt, tools, and summary so the
234
+ result remains within the 300K target. The policy scales proportionally for
235
+ smaller models. A single indivisible message larger than the target cannot be
236
+ silently truncated; HWCode keeps it and displays a warning instead.
237
+
136
238
  ## Project resources
137
239
 
138
240
  - `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 会自动加载;项目本地 .pi 资源会与 HWCode 内置配置共同生效。`;
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.0",
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
  ],
@@ -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
  }