@ohos-cpf/3rdloop 0.0.3 → 0.0.5

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/README.md +124 -87
  2. package/lib/cli.js +25 -0
  3. package/lib/config-cmd.js +1 -1
  4. package/lib/serve.js +268 -0
  5. package/lib/update.js +46 -6
  6. package/lib/web-ext.js +454 -0
  7. package/lib/web.js +664 -0
  8. package/package.json +2 -1
  9. package/vendor/Server/Agent/SkillSelector/README.md +11 -11
  10. package/vendor/Server/Agent/SkillSelector/llm/llmClient.js +3 -3
  11. package/vendor/Server/Skills/arkts-code-use/SKILL.md +270 -0
  12. package/vendor/Server/Skills/arkts-code-use/assets/TEMPLATES.md +367 -0
  13. package/vendor/Server/Skills/arkts-code-use/references/API_VERIFICATION.md +144 -0
  14. package/vendor/Server/Skills/arkts-code-use/references/ARKTS_RULES.md +240 -0
  15. package/vendor/Server/Skills/arkts-code-use/references/CODE_PATTERNS.md +431 -0
  16. package/vendor/Server/Skills/arkts-code-use/references/SYNTAX_CHECK_GUIDE.md +164 -0
  17. package/vendor/Server/Skills/arkts-code-use/scripts/verify-arkts.cjs +428 -0
  18. package/vendor/Server/Skills/gitcode-repo-fork/SKILL.md +310 -0
  19. package/vendor/Server/Skills/gitcode-repo-fork/assets/FORK_REPORT_TEMPLATE.md +113 -0
  20. package/vendor/Server/Skills/gitcode-repo-fork/references/FORK_DECISION_GUIDE.md +124 -0
  21. package/vendor/Server/Skills/gitcode-repo-fork/references/GITCODE_FORK_API.md +95 -0
  22. package/vendor/Server/Skills/gitcode-repo-fork/scripts/gitcode-fork.cjs +285 -0
  23. package/vendor/VERSION +3 -3
  24. package/web/css/arktslibrarycheck.css +322 -0
  25. package/web/css/codecheck.css +464 -0
  26. package/web/css/flutterlibrarycheck.css +322 -0
  27. package/web/css/knowledge.css +332 -0
  28. package/web/css/loop.css +578 -0
  29. package/web/css/md-reader.css +240 -0
  30. package/web/css/rnlibrarycheck.css +322 -0
  31. package/web/css/theme.css +702 -0
  32. package/web/index.html +713 -0
  33. package/web/js/arktslibrarycheck.js +1413 -0
  34. package/web/js/codecheck.js +1039 -0
  35. package/web/js/flutterlibrarycheck.js +1364 -0
  36. package/web/js/health.js +69 -0
  37. package/web/js/knowledge.js +358 -0
  38. package/web/js/loop.js +1102 -0
  39. package/web/js/md-reader.js +435 -0
  40. package/web/js/navigation.js +238 -0
  41. package/web/js/rnlibrarycheck.js +1378 -0
  42. package/web/js/stats.js +110 -0
  43. package/web/js/theme.js +46 -0
  44. package/web/js/utils.js +228 -0
  45. package/web/knowledge.html +146 -0
  46. package/web/loop.html +219 -0
@@ -0,0 +1,367 @@
1
+ # ArkTS 代码模板
2
+
3
+ > 按代码类型选择模板起步,替换占位内容后按需扩展。所有模板均符合 ArkTS 严格模式与华为编码规范,可通过 `devecocli build` 编译验证。
4
+
5
+ ---
6
+
7
+ ## 一、工具类模板(codeType: util)
8
+
9
+ 无状态、可复用的纯逻辑封装。文件:`utils/StringValidator.ets`
10
+
11
+ ```typescript
12
+ import hilog from '@ohos.hilog';
13
+
14
+ const DOMAIN: number = 0x0001;
15
+ const TAG: string = 'MyApp_StringValidator';
16
+
17
+ /**
18
+ * 字符串校验工具类(纯静态方法,禁止实例化)
19
+ */
20
+ export class StringValidator {
21
+ private constructor() {
22
+ // 工具类禁止实例化
23
+ }
24
+
25
+ /**
26
+ * 校验字符串非空且长度不超上限
27
+ * @param value - 待校验字符串
28
+ * @param maxLen - 最大长度,默认 256
29
+ * @returns 是否合法
30
+ */
31
+ static isValidText(value: string | null | undefined, maxLen: number = 256): boolean {
32
+ if (value === null || value === undefined) {
33
+ return false;
34
+ }
35
+ return value.length > 0 && value.length <= maxLen;
36
+ }
37
+
38
+ /**
39
+ * 校验字符串是否匹配正则
40
+ * @param value - 待校验字符串
41
+ * @param pattern - 正则表达式
42
+ * @returns 是否匹配
43
+ */
44
+ static matches(value: string, pattern: RegExp): boolean {
45
+ const matched: boolean = pattern.test(value);
46
+ hilog.debug(DOMAIN, TAG, 'matches result=%{public}s', String(matched));
47
+ return matched;
48
+ }
49
+ }
50
+ ```
51
+
52
+ ---
53
+
54
+ ## 二、业务服务类模板(codeType: service)
55
+
56
+ 有状态、含异步操作与资源生命周期管理。文件:`service/ConfigService.ets`
57
+
58
+ ```typescript
59
+ import hilog from '@ohos.hilog';
60
+
61
+ const DOMAIN: number = 0x0001;
62
+ const TAG: string = 'MyApp_ConfigService';
63
+
64
+ /** 服务配置 */
65
+ export interface ConfigServiceOptions {
66
+ /** 请求超时(毫秒) */
67
+ timeoutMs: number;
68
+ /** 最大重试次数 */
69
+ maxRetries: number;
70
+ }
71
+
72
+ /** 默认配置 */
73
+ const DEFAULT_OPTIONS: ConfigServiceOptions = {
74
+ timeoutMs: 5000,
75
+ maxRetries: 3,
76
+ };
77
+
78
+ /** 服务状态 */
79
+ export const enum ServiceState {
80
+ IDLE = 0,
81
+ RUNNING = 1,
82
+ FINISHED = 2,
83
+ FAILED = 3,
84
+ }
85
+
86
+ /**
87
+ * 配置加载服务:管理状态机、异步操作与日志
88
+ */
89
+ export class ConfigService {
90
+ private readonly options: ConfigServiceOptions;
91
+ private state: ServiceState = ServiceState.IDLE;
92
+
93
+ constructor(options: ConfigServiceOptions = DEFAULT_OPTIONS) {
94
+ this.options = options;
95
+ }
96
+
97
+ /** 获取当前状态 */
98
+ getState(): ServiceState {
99
+ return this.state;
100
+ }
101
+
102
+ /**
103
+ * 执行业务操作(示例骨架,替换为实际逻辑)
104
+ * @param input - 输入参数
105
+ * @returns 处理结果
106
+ */
107
+ async execute(input: string): Promise<string> {
108
+ hilog.info(DOMAIN, TAG, 'execute start, input length=%{public}d', input.length);
109
+ this.state = ServiceState.RUNNING;
110
+ try {
111
+ // TODO: 替换为实际业务逻辑(系统 API 须经文档查证,见 API_VERIFICATION.md)
112
+ const result: string = input.trim();
113
+ this.state = ServiceState.FINISHED;
114
+ hilog.info(DOMAIN, TAG, 'execute success');
115
+ return result;
116
+ } catch (e) {
117
+ this.state = ServiceState.FAILED;
118
+ const err: Error = e instanceof Error ? e : new Error(String(e));
119
+ hilog.error(DOMAIN, TAG, 'execute failed: %{public}s', err.message);
120
+ throw err;
121
+ }
122
+ }
123
+ }
124
+ ```
125
+
126
+ ---
127
+
128
+ ## 三、页面模板(codeType: page)
129
+
130
+ 文件:`pages/ExamplePage.ets`(须注册到 `resources/base/profile/main_pages.json`)
131
+
132
+ ```typescript
133
+ import hilog from '@ohos.hilog';
134
+ import { ConfigService } from '../service/ConfigService';
135
+
136
+ const DOMAIN: number = 0x0001;
137
+ const TAG: string = 'MyApp_ExamplePage';
138
+
139
+ /**
140
+ * 示例页面:演示状态驱动 UI 与资源清理
141
+ */
142
+ @Entry
143
+ @Component
144
+ struct ExamplePage {
145
+ @State message: string = 'ready';
146
+ @State isLoading: boolean = false;
147
+ private service: ConfigService = new ConfigService();
148
+ private timerId: number = -1;
149
+
150
+ aboutToAppear(): void {
151
+ hilog.info(DOMAIN, TAG, 'page appear');
152
+ }
153
+
154
+ aboutToDisappear(): void {
155
+ // 清理页面持有的 Timer / 订阅等资源
156
+ if (this.timerId >= 0) {
157
+ clearInterval(this.timerId);
158
+ this.timerId = -1;
159
+ }
160
+ hilog.info(DOMAIN, TAG, 'page disappear');
161
+ }
162
+
163
+ private async onRunClicked(): Promise<void> {
164
+ this.isLoading = true;
165
+ try {
166
+ const result: string = await this.service.execute(' demo input ');
167
+ this.message = `result: ${result}`;
168
+ } catch (e) {
169
+ this.message = `failed: ${(e as Error).message}`;
170
+ } finally {
171
+ this.isLoading = false;
172
+ }
173
+ }
174
+
175
+ build() {
176
+ Column({ space: 12 }) {
177
+ Text(this.message)
178
+ .fontSize(16)
179
+ .width('90%')
180
+ .textAlign(TextAlign.Center)
181
+
182
+ if (this.isLoading) {
183
+ LoadingProgress()
184
+ .width(36)
185
+ .height(36)
186
+ } else {
187
+ Button('run')
188
+ .width('60%')
189
+ .onClick(() => {
190
+ this.onRunClicked();
191
+ })
192
+ }
193
+ }
194
+ .width('100%')
195
+ .height('100%')
196
+ .justifyContent(FlexAlign.Center)
197
+ }
198
+ }
199
+ ```
200
+
201
+ ---
202
+
203
+ ## 四、自定义组件模板(codeType: component)
204
+
205
+ 文件:`components/StatusCard.ets`
206
+
207
+ ```typescript
208
+ /**
209
+ * 状态卡片组件:父组件传 @Prop 单向数据,@Link 双向同步计数
210
+ */
211
+ @Component
212
+ export struct StatusCard {
213
+ @Prop title: string = '';
214
+ @Link count: number;
215
+ private onCountChanged: ((count: number) => void) | null = null;
216
+
217
+ build() {
218
+ Column({ space: 8 }) {
219
+ Text(this.title)
220
+ .fontSize(16)
221
+ .fontWeight(FontWeight.Medium)
222
+
223
+ Text(`count: ${this.count}`)
224
+ .fontSize(20)
225
+
226
+ Row({ space: 12 }) {
227
+ Button('+')
228
+ .width(44)
229
+ .height(44)
230
+ .onClick(() => {
231
+ this.count += 1;
232
+ if (this.onCountChanged !== null) {
233
+ this.onCountChanged(this.count);
234
+ }
235
+ })
236
+ Button('-')
237
+ .width(44)
238
+ .height(44)
239
+ .onClick(() => {
240
+ this.count -= 1;
241
+ if (this.onCountChanged !== null) {
242
+ this.onCountChanged(this.count);
243
+ }
244
+ })
245
+ }
246
+ }
247
+ .padding(12)
248
+ .borderRadius(12)
249
+ .backgroundColor('#F1F3F5')
250
+ .width('90%')
251
+ }
252
+ }
253
+ ```
254
+
255
+ > 组件内回调属性(如 `onCountChanged`)须显式声明类型;父组件使用:`StatusCard({ title: 'demo', count: $count, onCountChanged: (c: number) => {} })`
256
+
257
+ ---
258
+
259
+ ## 五、HTTP 服务类模板(网络场景常用)
260
+
261
+ 文件:`service/HttpService.ets`。须在 `module.json5` 声明 `ohos.permission.INTERNET`。
262
+
263
+ ```typescript
264
+ import { http } from '@kit.NetworkKit';
265
+ import hilog from '@ohos.hilog';
266
+
267
+ const DOMAIN: number = 0x0001;
268
+ const TAG: string = 'MyApp_HttpService';
269
+
270
+ /** 请求配置 */
271
+ export interface HttpServiceOptions {
272
+ connectTimeoutMs: number;
273
+ readTimeoutMs: number;
274
+ }
275
+
276
+ /** 响应封装 */
277
+ export interface ApiResponse {
278
+ statusCode: number;
279
+ body: string;
280
+ }
281
+
282
+ const MAX_RESPONSE_BYTES: number = 5 * 1024 * 1024;
283
+
284
+ /**
285
+ * HTTP 服务:每次请求独立 HttpRequest,try/finally 释放
286
+ */
287
+ export class HttpService {
288
+ private readonly options: HttpServiceOptions;
289
+
290
+ constructor(options: HttpServiceOptions) {
291
+ this.options = options;
292
+ }
293
+
294
+ /**
295
+ * 发起 GET 请求
296
+ * @param url - 目标地址(https 优先)
297
+ * @returns 状态码与响应体
298
+ */
299
+ async get(url: string): Promise<ApiResponse> {
300
+ const httpRequest: http.HttpRequest = http.createHttp();
301
+ try {
302
+ const response: http.HttpResponse = await httpRequest.request(url, {
303
+ method: http.RequestMethod.GET,
304
+ connectTimeout: this.options.connectTimeoutMs,
305
+ readTimeout: this.options.readTimeoutMs,
306
+ });
307
+ if (typeof response.result !== 'string') {
308
+ throw new Error('unexpected response type');
309
+ }
310
+ if (response.result.length > MAX_RESPONSE_BYTES) {
311
+ throw new Error(`response too large: ${response.result.length} bytes`);
312
+ }
313
+ hilog.info(DOMAIN, TAG, 'GET %{public}s -> %{public}d', url, response.responseCode);
314
+ return { statusCode: response.responseCode, body: response.result };
315
+ } finally {
316
+ httpRequest.destroy();
317
+ }
318
+ }
319
+ }
320
+ ```
321
+
322
+ ---
323
+
324
+ ## 六、模块导出模板(index.ets)
325
+
326
+ ```typescript
327
+ // library/src/main/ets/index.ets 或模块入口
328
+ export { StringValidator } from './utils/StringValidator';
329
+ export { ConfigService } from './service/ConfigService';
330
+ export type { ConfigServiceOptions } from './service/ConfigService';
331
+ export { ServiceState } from './service/ConfigService';
332
+ export { HttpService } from './service/HttpService';
333
+ export type { HttpServiceOptions, ApiResponse } from './service/HttpService';
334
+ ```
335
+
336
+ > 仅 `export` 的符号对外可见;`interface`/`type` 导出用 `export type`。
337
+
338
+ ---
339
+
340
+ ## 七、main_pages.json 注册模板
341
+
342
+ `entry/src/main/resources/base/profile/main_pages.json`:
343
+
344
+ ```json
345
+ {
346
+ "src": [
347
+ "pages/Index",
348
+ "pages/ExamplePage"
349
+ ]
350
+ }
351
+ ```
352
+
353
+ ## 八、module.json5 权限声明模板
354
+
355
+ `entry/src/main/module.json5`(module 节点内):
356
+
357
+ ```json
358
+ {
359
+ "module": {
360
+ "requestPermissions": [
361
+ { "name": "ohos.permission.INTERNET" }
362
+ ]
363
+ }
364
+ }
365
+ ```
366
+
367
+ > user_grant 级权限(如 LOCATION)声明后还须运行时申请,参见 [代码模式 §五](../references/CODE_PATTERNS.md)。
@@ -0,0 +1,144 @@
1
+ # API 查证指南
2
+
3
+ > 编写 ArkTS 代码前,所有系统 API 的 import 路径、方法签名、权限、API Level 必须通过官方文档查证。本文档说明查证工具的使用方法与领域关键词速查。
4
+
5
+ ---
6
+
7
+ ## 一、查证工具
8
+
9
+ ### 1.1 首选:MCP Gateway `script_deveco_docs`
10
+
11
+ MCP Gateway 运行时,`script_deveco_docs` 工具封装了 `devecocli docs`,可直接检索与精读 HarmonyOS 官方 API 文档。
12
+
13
+ **按关键词检索(action=search)**:
14
+
15
+ ```json
16
+ {
17
+ "action": "search",
18
+ "keywords": "http createHttp request",
19
+ "catalog": "harmonyos-references",
20
+ "limit": 5
21
+ }
22
+ ```
23
+
24
+ | 参数 | 说明 |
25
+ |------|------|
26
+ | `action` | `search`(检索)或 `read`(读全文) |
27
+ | `keywords` | 空格分隔的关键词,建议 2-4 个(API 名 + 模块名 + 功能词) |
28
+ | `catalog` | 默认 `harmonyos-references`(API 参考);指南类用 `harmonyos-guides` |
29
+ | `limit` | 返回条数,默认 10 |
30
+
31
+ 返回字段:`title`(文档标题)、`documentId`(用于 read)、`sectionTitle`(命中小节)、`snippet`(摘要)。
32
+
33
+ **按 documentId 精读(action=read)**:
34
+
35
+ ```json
36
+ {
37
+ "action": "read",
38
+ "documentId": "API参考/网络/Network_Kit_网络服务/ArkTS_API/ohos_net_http_数据请求_/js-apis-http",
39
+ "section": "HttpRequest"
40
+ }
41
+ ```
42
+
43
+ `section` 可选,指定后只返回该小节(推荐,节省 token)。文档正文包含:方法签名、参数表、返回值、`权限`、`系统能力`(SystemCapability)、`起始版本`(since)、`废弃`(deprecated)标注、错误码。
44
+
45
+ ### 1.2 备选:`devecocli docs`(终端)
46
+
47
+ MCP 不可用时直接使用 CLI:
48
+
49
+ ```bash
50
+ # 检索(匹配任一关键词)
51
+ devecocli docs search "http createHttp" --limit 5
52
+
53
+ # 按文档 ID 精读
54
+ devecocli docs read "API参考/网络/Network_Kit_网络服务/ArkTS_API/ohos_net_http_数据请求_/js-apis-http"
55
+
56
+ # 查看可用文档目录
57
+ devecocli docs catalog
58
+ ```
59
+
60
+ ### 1.3 补充:知识库(最佳实践/平台陷阱)
61
+
62
+ MCP Gateway 的 `kb_search`(内置)或 `kb-server_search_knowledge`(下游)可检索鸿蒙知识库中的最佳实践与实战经验(如平台陷阱、性能优化),适合在方案设计阶段补充查询,不适合替代官方 API 参考。
63
+
64
+ ---
65
+
66
+ ## 二、三步查询法
67
+
68
+ 对每个涉及的系统 API 依次执行:
69
+
70
+ ```
71
+ Step 1 宽泛定位:用功能关键词检索,确认可用的模块/类
72
+ 例:keywords = "video player"
73
+ Step 2 精确签名:read 文档定位到具体类/方法小节,记录完整签名
74
+ 例:documentId = "...js-apis-media", section = "createAVPlayer"
75
+ Step 3 权限与版本:确认该 API 的「权限」「起始版本」「废弃」标注
76
+ - 权限 → 记入 module.json5 声明清单
77
+ - since > 目标 API Level → 加 canIUse()/sdkApiVersion 守卫或换旧接口
78
+ - deprecated → 检索替代接口(keywords 加 "alternative" 或直接搜新接口名)
79
+ ```
80
+
81
+ ---
82
+
83
+ ## 三、领域关键词速查
84
+
85
+ | 领域 | 功能 | 检索关键词 |
86
+ |------|------|-----------|
87
+ | 网络 | HTTP 请求 | `http createHttp request` |
88
+ | 网络 | WebSocket | `webSocket connect` |
89
+ | 网络 | 网络状态 | `network connection` |
90
+ | 存储 | KV 偏好 | `preferences data` |
91
+ | 存储 | 关系型数据库 | `relationalStore` |
92
+ | 存储 | 文件读写 | `file fs openSync readSync` |
93
+ | 存储 | 用户文件选择 | `file picker` |
94
+ | UI | 页面路由 | `Navigation NavDestination router` |
95
+ | UI | 列表懒加载 | `LazyForEach IDataSource` |
96
+ | UI | 动画 | `animateTo animation` |
97
+ | UI | 弹窗 | `CustomDialog AlertDialog` |
98
+ | 多媒体 | 视频播放 | `AVPlayer media` |
99
+ | 多媒体 | 音频播放/录制 | `AudioRenderer AudioCapturer` |
100
+ | 多媒体 | 图片处理 | `ImageSource PixelMap` |
101
+ | 设备 | 定位 | `geoLocationManager` |
102
+ | 设备 | 蓝牙 BLE | `bluetooth ble` |
103
+ | 设备 | 传感器 | `sensor accelerometer` |
104
+ | 设备 | 振动 | `vibrator` |
105
+ | 安全 | 对称加密 | `cryptoFramework AES Cipher` |
106
+ | 安全 | 摘要/HMAC | `cryptoFramework hash hmac` |
107
+ | 安全 | 密钥管理 | `huks` |
108
+ | 并发 | 任务池 | `taskpool execute Concurrent` |
109
+ | 并发 | Worker | `worker ThreadWorker` |
110
+ | 事件 | 事件总线 | `emitter on emit off` |
111
+ | 权限 | 运行时申请 | `requestPermissionsFromUser abilityAccessCtrl` |
112
+ | 应用 | 应用上下文 | `common UIAbilityContext` |
113
+ | 应用 | 弹框申请 | `requestPermissionsFromUser` |
114
+
115
+ ---
116
+
117
+ ## 四、API Level 对照
118
+
119
+ | API Level | 系统版本 | 说明 |
120
+ |-----------|---------|------|
121
+ | 9 | HarmonyOS 3.2 | 基础 API |
122
+ | 10 | HarmonyOS 4.0 | — |
123
+ | 11 | HarmonyOS 4.1 | Stage 模型完善 |
124
+ | 12 | HarmonyOS 5.0 (NEXT) | NEXT 正式版本 |
125
+ | 13+ | 5.x 后续 | 持续演进 |
126
+
127
+ **规则**:
128
+ - 工程模式:目标 API Level 以目标工程 `build-profile.json5` 的 `compatibleSdkVersion` 为准(先读取再写代码)
129
+ - 独立模式:默认按 API 12+ 编写;`since` > 12 的接口必须加版本守卫
130
+ - 优先使用非废弃接口;文档明确标注 `废弃` 的禁止使用
131
+
132
+ ---
133
+
134
+ ## 五、查证结论记录格式
135
+
136
+ 每个功能点查证后立即记录,作为 Phase 3 编码依据:
137
+
138
+ | 功能点 | import 路径 | 关键 API 与签名 | 权限 | since | 结论 |
139
+ |--------|------------|----------------|------|-------|------|
140
+ | 发起 GET 请求 | `@kit.NetworkKit` (`http`) | `http.createHttp(): HttpRequest`、`request(url, options): Promise<HttpResponse>` | `ohos.permission.INTERNET` | 8 | ✅ |
141
+ | 后台计算校验和 | `@ohos.taskpool` | `@Concurrent` 函数 + `taskpool.execute(task)` | 无 | 9 | ✅ |
142
+ | 蓝牙扫描 | `@ohos.bluetooth.ble` | `startScan(filters)` | `ohos.permission.ACCESS_BLUETOOTH` | 10 | ⚠️ 需 canIUse 守卫 |
143
+
144
+ > 未出现在该表中的系统 API 不允许出现在最终代码里。