Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ permissions:
jobs:
platforms:
name: test (${{ matrix.os }})
# Windows: where DevEco users work, and where the LSP client's drive-letter URIs, node.exe lookup and process
# handling differ.
# Windows: where DevEco users work, and where file paths (drive letters, backslashes) and the ripgrep lookup differ.
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ This file is the map for every coding agent (opencode and Codex read `AGENTS.md`
| `docs/exec-plans/tech-debt-tracker.md` | known gaps (`@ObjectLink`, nested-write citation, unimplemented judge chain, ...) |
| `docs/design-docs/index.md` | design docs with status: decisions, core beliefs, agentic plugin, parked ideas |
| `docs/design-docs/decisions.md` | decisions made (judge chain, scope, repos, docs) |
| `sandbox/demo/` | the demo project (R1, R2 and R3 pages) and `DEMO.md`, the demo kit for opencode and DevEco Code; the rest of `sandbox/` is ignored scratch |
| `sandbox/demo/` | the demo project (R1–R4 pages) and `DEMO.md`, the demo kit for opencode and DevEco Code; the rest of `sandbox/` is ignored scratch |
| `bench/` (private) | `bench/README.md` (layout), `bench/docs/RESULTS.md` (results, evaluation status), `bench/docs/evaluation-method.md`, eval scripts |

## Keeping docs fresh
Expand Down
15 changes: 6 additions & 9 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sandbox/demo/ the demo project (opencode): R1 pages i
sandbox/* everything else is local scratch (ignored), e.g. a DevEco Code copy of the demo
arkui-sem/ the linter (opencode plugin, package arkui-sem 0.2.0, ESM, TypeScript)
README.md, AGENTS.md
src/opencode.ts plugin: tool.execute.after feedback, session.idle gate, tool arkui_check, language server lifecycle
src/opencode.ts plugin: tool.execute.after feedback, session.idle gate, tool arkui_check
src/facts.ts the fact model: what the extractor records per file, and the cross-file lookup interfaces
src/queries.ts queries derived from the facts: paths, rendering reads, declared types, class hierarchies
src/files.ts .ets discovery under a path; the files an agent's edit touched
Expand All @@ -64,7 +64,7 @@ arkui-sem/ the linter (opencode plugin, package ar
src/ets/types.ts type annotations → TypeRef, object literals, per-type records (classes, interfaces, aliases)
src/ets/syntax.ts, scan.ts, modules.ts, directives.ts, lifecycle.ts node helpers, file context, imports/exports,
disable comments, lifecycle hook names
src/sdk.ts DevEco Studio and HarmonyOS SDK lookup (parser options, ace-server)
src/sdk.ts DevEco Studio and HarmonyOS SDK lookup (parser options)
src/project.ts project index for the rules: imported name → declaring file (relative imports, packages from
oh-package.json5 local dependencies and build-profile.json5 modules, Index.ets re-exports), caches;
call-site edges: a project scan resolving each file's component uses (callSites), or for one
Expand All @@ -75,13 +75,10 @@ arkui-sem/ the linter (opencode plugin, package ar
src/engine.ts candidates → slices → judge → finding/question bands (thresholds 0.8 / 0.5); agent formatting;
KINDS: one entry per candidate kind (judge or facts-only, evidence and fix, disable-comment hint)
src/config.ts defaults < ~/.config/arkui-sem/config.json < .opencode/arkui-sem.json < env < plugin options
src/cli.ts arkui-sem check | config | lsp (default backend: clef)
src/lsp/ utility client for ace-server (ArkTS language server): definition, references, call hierarchy;
warm.ts keeps one server per project running for the plugin (started on the first .ets edit,
sent each edited file, asked within a time budget, stopped on dispose; setting lsp: auto | off)
test/ node:test, run from src/ via tsx (npm test, offline): rules/R<n>.test.ts, one file
per module (config, engine, deepseek, openrouter, opencode, lsp, project, callsites, search, loops, inputs), helpers.ts; test/fixtures/:
Counter, Feed, Profile (R1), Ticker (R3), fake-ace-server.mjs (both LSP protocols), project/
src/cli.ts arkui-sem check | config (default backend: clef)
test/ node:test, run from src/ via tsx (npm test, offline): rules/R<n>*.test.ts, one file
per module or feature (test/<name>.test.ts), helpers.ts; test/fixtures/:
Counter, Feed, Profile (R1), Ticker (R3), project/
(two-module DevEco project: entry imports common by package name)
scripts/install.mjs
scripts/compare-callsites.mjs searched call sites against the whole-project scan on a project or a generated one, with timings
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# arkui-sem

Semantic linting of ArkTS/ArkUI declarative state inside coding agents. A fact extractor finds candidate bugs
(a field that is written and rendered but not reactive, a nested write the state decorator does not observe, a
resource that is never released), and a small "System One" decision model (Cloudflare Clef, TypeSafe Jev, DeepSeek
(a field that is written and rendered but not reactive, a nested write the state decorator does not observe, a list
row that keeps stale content, an event or input wired one way only, a resource that is never released), and a small "System One" decision model (Cloudflare Clef, TypeSafe Jev, DeepSeek
flash as System One, ...) judges each one. Confident verdicts go back to the agent as findings, uncertain ones as
questions. It ships as an [opencode](https://opencode.ai) plugin and a CLI. **Prototype.**

Expand Down
7 changes: 3 additions & 4 deletions arkui-sem/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ Semantic lint for ArkTS/ArkUI declarative state (opencode v1 plugin + CLI). See
- `src/facts.ts`: the fact model (of the linter's model and rules, `src/ets/` imports only this); `src/queries.ts`: queries derived from facts (`rowReads`: what a loop row renders, through builders and children); `src/files.ts`: `.ets` discovery.
- `src/rules/`: one module per rule (`R1.ts`, `R2.ts`, `R3.ts`, `R4.ts`), `candidate.ts` (kinds, fingerprint), `index.ts` (`candidates()`). R2 event-unwired takes call sites from the engine.
- `src/ets/`: the ArkTS parser (ohos-typescript, options from the SDK or `options.json`, regenerated by `scripts/ets-options.mjs`) and the fact extractor on its syntax tree (`extract.ts` orchestrates; `component.ts`, `resources.ts`, `types.ts`, `uses.ts`, `loops.ts`, `rebuilt.ts`, `inputs.ts` hold the facts; `callbacks.ts` tells handler closures from drawing ones).
- `src/sdk.ts`: DevEco Studio and HarmonyOS SDK lookup, shared by the parser and the LSP client.
- `src/sdk.ts`: DevEco Studio and HarmonyOS SDK lookup, for the parser.
- `src/project.ts`: project index for cross-file rules (package lookup from oh-package.json5 and build-profile.json5, re-exports, file cache) and call-site edges (`callSites`: whole-project scan; `searchCallSites`: one struct, from a text search).
- `src/search.ts`: the text search behind `searchCallSites` (ripgrep, else Node). `scripts/compare-callsites.mjs` checks the search against the scan.
- `src/judge.ts`: System One backends, questions, slices; the backend registry (`BACKENDS`).
- `src/engine.ts`: candidates → slices → judge → findings (≥ 0.8) and questions (0.5–0.8). A kind is the rule that emits it plus one entry in `KINDS` and one in `FIELD_SLICE` (`judge.ts`); the compiler checks both.
- `src/opencode.ts`: the plugin (post-edit feedback, idle gate, tool `arkui_check`, language server lifecycle).
- `src/config.ts`: settings merge order; `src/cli.ts`: `check`, `config`, `lsp`.
- `src/lsp/`: ace-server client (definition, references, call hierarchy) and `warm.ts`, which keeps one server per project running for the plugin (started on the first edit, stopped on dispose); tests use `test/fixtures/fake-ace-server.mjs`.
- `src/opencode.ts`: the plugin (post-edit feedback, idle gate, tool `arkui_check`).
- `src/config.ts`: settings merge order; `src/cli.ts`: `check`, `config`.
- `scripts/install.mjs`: installs the plugin into an opencode or DevEco Code project, or globally.

## Conventions
Expand Down
28 changes: 10 additions & 18 deletions arkui-sem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ Semantic lint for ArkTS/ArkUI declarative state, built for the coding-agent loop
[opencode](https://opencode.ai) v1 plugin and a CLI. Prototype.

It targets UI state desynchronization: a field that is written and rendered but not reactive, a nested write
that V1 `@State` does not observe, a callback or `@Event` a child calls and no parent passes, a resource that
that V1 `@State` does not observe, a list that doesn't redraw what changed (a `ForEach` that replaces items
under an unchanged key or keys rows by index over items that change, a `LazyForEach` whose data source is
created while drawing or reassigned), a callback or `@Event` a child calls and no parent passes, a resource that
is never released, a text input wired to its field one way (the field is set by code but not shown, or
typed into but read nowhere). A fact extractor finds candidates; a small "System One" judge model scores each one; scores
of 0.8 and above become findings, scores from 0.5 to 0.8 become questions back to the agent. The unwired
callback and the input wiring are decided by the facts alone, with no judge call; an input nothing reads is asked
as a question.
typed into but read nowhere), a selection the rows compare against that nothing sets. A fact extractor finds
candidates; a small "System One" judge model scores each one; scores of 0.8 and above become findings, scores
from 0.5 to 0.8 become questions back to the agent. The list kinds, the unwired callback and the input and
selection wiring are decided by the facts alone, with no judge call; some of them are asked as questions (an
input nothing reads, a selection nothing sets).

## Build and test

Expand Down Expand Up @@ -37,21 +40,8 @@ edits after each tool call, gates the session once on idle while findings remain
```sh
node dist/cli.js check <file.ets|dir>... [--format agent|json] [--backend <name>]
node dist/cli.js config [--init] # prints masked key fragments
node dist/cli.js lsp <definition|references|callers|callees> <file.ets> <line:col> [--project <dir>] [--ace-server <dir>] [--sdk <dir>] [--node <path>] [--verbose]
```

`lsp` queries Huawei's ArkTS language server (ace-server, not bundled): DevEco Studio's own (default install on Windows
and macOS), or the build `ARKUI_SEM_ACE_SERVER` / `--ace-server` points to; a build with `out/standardIndex/index.js`
(DevEco 26+) is driven over standard LSP. The SDK comes from DevEco Studio or `ARKUI_SEM_SDK`; `ARKUI_SEM_LSP_NODE`
picks the node that runs the server.

The plugin starts the same server in the background on the first `.ets` edit of a project, sends it each edited
file, and stops it when opencode disposes the plugin. Nothing waits for it: without a server, or while it starts, checks
run as before. No rule asks it anything so far. `"lsp": "off"` in a config file, or `ARKUI_SEM_LSP=off`, keeps it
from starting (default `auto`); on a large project the server takes minutes and several GB to start.
The server follows imports by package name only in a project with `oh_modules` links (after a DevEco sync or
`ohpm install`); the rules don't depend on that, they use the project index.

## Backends and configuration

| Backend | What it is |
Expand All @@ -69,3 +59,5 @@ Any backend can be tried on your own files: `node dist/cli.js check <file.ets> -
Settings merge in this order: defaults < `~/.config/arkui-sem/config.json` < `.opencode/arkui-sem.json`
(or `.deveco/arkui-sem.json` when only that one exists) < environment (`ARKUI_SEM_*`; `ARKUI_SEM_CONFIG` points at another config file) < plugin options.
API keys belong in the user config file only; `node dist/cli.js config --init` writes a starter file.
The parser takes its ArkTS options from the HarmonyOS SDK: `ARKUI_SEM_SDK`, else DevEco Studio's (default install, or
`DEVECO_STUDIO`); without one it uses the options bundled with the linter.
69 changes: 0 additions & 69 deletions arkui-sem/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ import {
import { checkFiles, formatForAgent } from './engine.js';
import { absolute, etsFiles } from './files.js';
import { createBackend } from './judge.js';
import { type ArktsLsp, startArktsLsp } from './lsp/client.js';
import { projectRootFor } from './lsp/project.js';

const USAGE = `usage:
arkui-sem check <file.ets|dir>... [--format agent|json] [--backend <name>]
arkui-sem config [--init]
arkui-sem lsp <definition|references|callers|callees> <file.ets> <line:col> [--project <dir>] [--ace-server <dir>]
[--sdk <dir>] [--node <path>] [--verbose]
`;
const FORMATS = new Set(['agent', 'json']);

Expand Down Expand Up @@ -89,76 +85,11 @@ function config(rest: string[]) {
);
}

const LSP_ACTIONS = ['definition', 'references', 'callers', 'callees'] as const;
type LspAction = (typeof LSP_ACTIONS)[number];
const LSP_VALUE_FLAGS = ['--project', '--ace-server', '--sdk', '--node'];

function isLspAction(a: string | undefined): a is LspAction {
return LSP_ACTIONS.some((action) => action === a);
}

// Asks ace-server (ArkTS language server); line:col are 1-based, output is JSON.
async function lsp(rest: string[]) {
const args: string[] = [];
const flags = new Map<string, string>();
for (let i = 0; i < rest.length; i++) {
const arg = rest[i];
if (arg === '--verbose') {
flags.set(arg, '');
continue;
}
if (!LSP_VALUE_FLAGS.includes(arg)) {
args.push(arg);
continue;
}
const value = rest[++i];
if (value === undefined) {
process.stderr.write(`arkui-sem: ${arg} needs a value\n${USAGE}`);
process.exit(2);
}
flags.set(arg, value);
}
const [action, file, at] = args;
const position = /^(\d+):(\d+)$/.exec(at ?? '');
if (!isLspAction(action) || !file || !position || Number(position[1]) < 1 || Number(position[2]) < 1) {
process.stderr.write(USAGE);
process.exit(2);
}
const started = Date.now();
let server: ArktsLsp | undefined;
try {
server = await startArktsLsp(flags.get('--project') ?? projectRootFor(file), {
aceServer: flags.get('--ace-server'),
sdk: flags.get('--sdk'),
node: flags.get('--node'),
log: flags.has('--verbose') ? (line) => process.stderr.write(`${line}\n`) : undefined,
});
const initMs = Date.now() - started;
server.open(file);
const result = await server[action](file, { line: Number(position[1]) - 1, character: Number(position[2]) - 1 });
const output = {
protocol: server.protocol,
server: server.paths.server.entry,
initMs,
totalMs: Date.now() - started,
result,
};
process.stdout.write(`${JSON.stringify(output, null, 2)}\n`);
} catch (e) {
process.stderr.write(`arkui-sem lsp: ${(e as Error).message}\n`);
process.exitCode = 1;
} finally {
await server?.stop();
}
}

const [command, ...rest] = process.argv.slice(2);
if (command === 'check') {
await check(rest);
} else if (command === 'config') {
config(rest);
} else if (command === 'lsp') {
await lsp(rest);
} else {
process.stderr.write(USAGE);
process.exit(2);
Expand Down
13 changes: 0 additions & 13 deletions arkui-sem/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@ export interface Settings {
gate: boolean;
thresholds: { finding: number; question: number };
judgeTimeoutMs: number;
/** auto: the plugin starts ace-server on the first .ets edit when one is installed; off: never. */
lsp: LspMode;
dataDir: string;
credentials: Credentials;
sources: string[];
warnings: string[];
}

export type LspMode = 'auto' | 'off';

export interface ConfigFile {
backend?: string;
lsp?: string;
gate?: boolean;
findingThreshold?: number;
questionThreshold?: number;
Expand All @@ -55,7 +50,6 @@ const SCHEMA: Record<string, 'string' | 'boolean' | 'number' | Record<string, 's
findingThreshold: 'number',
questionThreshold: 'number',
judgeTimeoutMs: 'number',
lsp: 'string',
dataDir: 'string',
deepseek: { apiKey: 'string', baseUrl: 'string' },
typesafe: { apiKey: 'string' },
Expand Down Expand Up @@ -159,11 +153,6 @@ export function loadSettings(options: Record<string, unknown> = {}, projectDir:
const user = read(userConfigPath(), 'user');
const project = read(projectConfigPath(projectDir), 'project');
const o = options as ConfigFile;
const lsp = first(o.lsp, env('ARKUI_SEM_LSP'), project.lsp, user.lsp) ?? 'auto';
if (lsp !== 'auto' && lsp !== 'off') {
warnings.push(`lsp should be "auto" or "off", not "${lsp}"; using "auto"`);
}

return {
backend: first(o.backend, env('ARKUI_SEM_BACKEND'), project.backend, user.backend) ?? 'clef',
gate: first(bool(o.gate), bool(env('ARKUI_SEM_GATE')), project.gate, user.gate) ?? true,
Expand All @@ -190,7 +179,6 @@ export function loadSettings(options: Record<string, unknown> = {}, projectDir:
project.judgeTimeoutMs,
user.judgeTimeoutMs,
) ?? 8000,
lsp: lsp === 'off' ? 'off' : 'auto',
dataDir:
first(o.dataDir, env('ARKUI_SEM_DATA_DIR'), project.dataDir, user.dataDir) ??
join(homedir(), '.cache', 'arkui-sem'),
Expand Down Expand Up @@ -261,7 +249,6 @@ export function describeSettings(s: Settings): Record<string, unknown> {
gate: s.gate,
thresholds: s.thresholds,
judgeTimeoutMs: s.judgeTimeoutMs,
lsp: s.lsp,
dataDir: s.dataDir,
credentials: {
deepseekApiKey: mask(c.deepseekApiKey),
Expand Down
Loading
Loading