@localness/cli 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hwacc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,144 @@
1
- # Temporary Holding Version
1
+ # @localness/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Compares and syncs a repository's locale JSON files with a Localness project. For people and for agents: every command has `--json` output and stable exit codes.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add -g @localness/cli # or: npm install -g @localness/cli
9
+ localness --help
10
+ ```
11
+
12
+ A global install puts `localness` on your PATH, which the examples below, the VS Code extension's default `localness.cliCommand` and the Agent Skill expect. To pin a version per repository instead, add it as a dev dependency (`pnpm add -D @localness/cli`) and run it through `pnpm exec localness` or `npx localness`; to try it without installing, `npx @localness/cli diff`.
13
+
14
+ Node 18.3 or later. The token is `LOCALNESS_TOKEN`, read from `.env.local` next to `localness.config.json` first and from the environment otherwise. A read token is enough for `init`, `diff`, `pull`, `push` and `sync`; `apply` and `suggest-name` need a Read & write token. The CLI never uses the VS Code extension's sign-in, and the extension never reads this token: give the CLI (and agents running it) its own token, Read only unless it has to write.
15
+
16
+ ```sh
17
+ # .env.local (keep it out of git)
18
+ LOCALNESS_TOKEN=lnk_...
19
+ ```
20
+
21
+ ## Commands
22
+
23
+ ```sh
24
+ localness init --base-url https://localness.example.com # find the locale files, write localness.config.json
25
+ localness diff # compare the files with the project
26
+ localness pull # write the project's changes into the files
27
+ localness push # plan sending local changes; prints a plan id
28
+ localness apply 3f9a1c2e # write that plan to the project as drafts
29
+ localness sync # pull, then plan a push
30
+ localness match "Save" "Cancel" # existing keys holding these texts
31
+ localness suggest-name "Save changes" # ask the project's AI for a key name
32
+ localness review start texts.json # page to decide keys for extracted texts
33
+ localness review wait 1a2b3c4d # the decisions, once approved
34
+ localness releases use v2.4 # label the keys push creates with release v2.4
35
+ localness skill install # teach coding agents this workflow
36
+ ```
37
+
38
+ | Command | What it does |
39
+ | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
40
+ | `init` | Looks for `dir/{locale}.json` or `dir/{locale}/name.json` layouts, detects flat or nested JSON and writes `localness.config.json`. With `LOCALNESS_TOKEN` set it also fills `project` and maps project locales to file names. |
41
+ | `diff` | Classifies each difference (see below). Read only; never writes the base. |
42
+ | `pull` | Writes `platform-added`, `platform-changed` and `different` into the files and records the base. Local-only keys are kept unless `--prune`. Keys whose path collides with the file's structure are skipped and reported. |
43
+ | `push` | Plans `local-added` and `local-changed` into `.localness/plans/<id>.json` and prints the id. Writes nothing to the project. Keys without source text, with a reserved name, or new keys whose name breaks a strict convention rule (prefix, characters, empty segment) are listed as blocked; new keys off the suggested separator, casing or depth are created and listed as warnings. |
44
+ | `apply [id]` | Re-reads the planned keys; if any changed on the project since the plan, or the plan is over an hour old, deletes the plan and writes nothing. Otherwise creates new keys and writes drafts. No id: lists pending plans. |
45
+ | `sync` | Pulls `platform-added` and `platform-changed`, then plans a push like `push`. Never touches `different` or `conflict`. |
46
+ | `match` | For each text, the keys whose source text (draft or published) equals it after whitespace normalisation, plus keys only in the source-locale file (marked `local`, not pushed yet). Several keys per text are all listed. `--json` adds the project's key convention (prefix, separator, style, max depth, naming guidance) and namespace names, for naming new keys. Read only. |
47
+ | `suggest-name` | Prints the project's suggested key name for a source text. Uses AI quota; writes nothing. |
48
+ | `review` | `start <file>` reads `{ "items": [{ "text", "file", "line", "key" }] }`, looks up each text like `match` and opens a page: a tab in VS Code or Cursor when the Localness extension has the project open (it announces itself in `.localness/editors/`), otherwise a browser page (127.0.0.1, random port, secret token in the URL); `--open browser` or `--open editor` forces one. `--json` prints `{ id, url, rows, openedIn }`, `url` null in the editor. Per text the person picks reuse, new key or skip; new names are checked live against the convention and the existing keys (errors block approval, style suggestions only warn), and checked again on approval. `wait <id> [--timeout <s>]` prints the decisions as JSON, or `status: "pending"` after the timeout (default 90 s). Writes nothing to the project or the code; the browser page stops after approval, cancel or two hours. |
49
+ | `releases` | Lists the project's releases (`*` marks the config's). `use <name>` / `use --none` sets the release new keys get; `create <name> [--use]` adds one (project owners). `add\|remove <release> <key...>` relabels existing keys; `--match <glob>` selects keys and asks before changing them (`--yes` skips the question). |
50
+ | `skill install` | Installs the Agent Skill for coding agents; see [Coding agents](#coding-agents). |
51
+
52
+ `push` and `apply` only write drafts; publishing stays on the platform. A plan holds at most 200 keys.
53
+
54
+ | Kind | Meaning | Handled by |
55
+ | ------------------ | -------------------------------------------------------------- | -------------------- |
56
+ | `platform-added` | The project has text the file lacks | pull, sync |
57
+ | `platform-changed` | The project changed since the base; the file did not | pull, sync |
58
+ | `platform-deleted` | The key left the project; the file still has the base text | `--prune` / by hand |
59
+ | `local-added` | The file has text the project lacks | push, sync |
60
+ | `local-changed` | The file changed since the base; the project did not | push, sync |
61
+ | `local-deleted` | The file dropped a key the project still has unchanged | by hand (no deletes) |
62
+ | `different` | Text differs and there is no base yet | pull, or `--keys` |
63
+ | `conflict` | Both changed, or the push would overwrite someone else's draft | `--keys` |
64
+ | `pending-publish` | The file matches the project's unpublished draft | publish on platform |
65
+
66
+ The base (`.localness/base.json`, next to the config) is the last text the file and the project agreed on; `pull`, `apply` and `sync` update it. Without it, every change is `different`: run `pull` or `sync` once. `.localness/` gets its own `.gitignore`; never commit it.
67
+
68
+ | Option | Commands | Description |
69
+ | ---------------------- | ------------------------------------- | -------------------------------------------------------------------------------------------- |
70
+ | `--config <path>` | all | Config file. Default: nearest `localness.config.json`. |
71
+ | `--keys <a,b>` | diff, pull, push, sync | Only these keys. For `pull` and `push`, take that side even when both changed. |
72
+ | `--locales <en,ja>` | diff, pull, push, sync | Only these platform locales. |
73
+ | `--prune` | pull | Also remove keys the project does not have. |
74
+ | `--dry-run` | init, pull, push, sync, skill install | Show what would happen. |
75
+ | `--json` | all | Machine-readable output on stdout. |
76
+ | `--base-url <url>` | init | Localness instance URL. Required. |
77
+ | `--project <name\|id>` | init | Project. Default: the token's only project. |
78
+ | `--dir <path>` | init | Locale directory, skipping detection. |
79
+ | `--pattern <pattern>` | init | File pattern under `--dir`, for example `{locale}.json`. |
80
+ | `--format <format>` | init | `flat-json` or `nested-json`. |
81
+ | `--force` | init, skill install | Overwrite an existing config, or a hand-edited Skill. |
82
+ | `--agent <a,b>` | skill install | `copilot`, `claude`, `cursor`, `codex` or `all`. Default: the first three. |
83
+ | `--agents-md` | skill install | Also add a block pointing to the Skill in the root `AGENTS.md`. |
84
+ | `--root <path>` | skill install | Install here instead of the git root, for a folder opened on its own. |
85
+ | `--release <name>` | init | Release new keys are labelled with. |
86
+ | `--none` | releases use | No release for new keys. |
87
+ | `--use` | releases create | Also make the new release the config's. |
88
+ | `--match <glob>` | releases add, releases remove | Keys to relabel, e.g. `checkout.*`. |
89
+ | `--timeout <seconds>` | review wait | How long to wait for the decisions. Default 90. |
90
+ | `--open <where>` | review start | `auto` (default: the editor when the extension has the project open), `browser` or `editor`. |
91
+ | `--yes`, `-y` | releases add, releases remove | Skip the confirmation for `--match`. |
92
+
93
+ Exit codes: `0` success (for `diff`: no differences), `1` `diff` found differences, `2` error (including a stale, expired or failed `apply`).
94
+
95
+ Plans are local files in `.localness/plans/`; the platform knows nothing of them. `push`, `sync` and `apply` without an id delete expired plans; deleting a plan by hand is safe too.
96
+
97
+ Writes (`apply`) are labeled in the platform's key history as `cli/<version>`, or `cli/<version>; agent` when the CLI runs under an AI agent. Detection is best-effort from the agent's environment (`AI_AGENT`, `CLAUDECODE`, `CURSOR_AGENT`, `COPILOT_CLI`, `CODEX_SANDBOX`, `GEMINI_CLI`). Set `LOCALNESS_AGENT=1` to force the agent label or `LOCALNESS_AGENT=0` to drop it. The label is informational; permissions come from the token.
98
+
99
+ ## Coding agents
100
+
101
+ `localness skill install` writes an [Agent Skill](https://agentskills.io) at the repository root (the git root above the config) that teaches agents this workflow: `diff --json`, ask a person about conflicts, `pull`, `push --json`, show the plan, and `apply` only after approval. `SKILL.md` holds the rules and points to `references/` for each task (syncing, extracting hardcoded text, releases, JSON output), so an agent reads only what the task needs. Commit the whole folder. If the agents open a subfolder of the repository as their workspace (for example a package inside another repository), pass `--root <that folder>`: agents only look for skills under the folder they opened.
102
+
103
+ | Agent | Reads skills from |
104
+ | -------------- | ---------------------------------------------------- |
105
+ | GitHub Copilot | `.github/skills`, `.claude/skills`, `.agents/skills` |
106
+ | Claude Code | `.claude/skills` |
107
+ | Cursor | `.cursor/skills`, `.claude/skills`, `.agents/skills` |
108
+ | Codex | `.agents/skills` |
109
+
110
+ It writes as few copies as cover the chosen agents, since an agent reading two copies lists the skill twice: the default (Copilot, Claude Code, Cursor) is the single `.claude/skills/localness/SKILL.md`. Claude Code and Codex share no folder, so `--agent all` writes two. Copies already installed in any of these folders are updated too.
111
+
112
+ `SKILL.md` records the CLI version and a hash over every file of the Skill. Reinstalling leaves a copy with any hand-edited file alone unless `--force`. `diff`, `pull`, `push`, `apply` and `sync` print a note on stderr when the installed Skill is from another CLI version. Project-specific conventions belong in the platform's Skills page, not in this file.
113
+
114
+ ## `localness.config.json`
115
+
116
+ Shared with the VS Code extension. Commit it; tokens never go here.
117
+
118
+ ```json
119
+ {
120
+ "baseUrl": "https://localness.example.com",
121
+ "project": "web",
122
+ "files": {
123
+ "dir": "src/locales",
124
+ "pattern": "{locale}.json",
125
+ "format": "nested-json"
126
+ },
127
+ "localeMap": { "zh-CN": "zh_cn" }
128
+ }
129
+ ```
130
+
131
+ | Field | Default | Description |
132
+ | ---------------------------------------------------------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------------- |
133
+ | `baseUrl` | required | Localness instance URL. |
134
+ | `project` | none | Project id or name. Missing: the token's only project. |
135
+ | `files.dir` | required in files | Locale directory, relative to the config file. |
136
+ | `files.pattern` | `{locale}.json` | File path under `dir`; `{locale}` is the file name of the locale. |
137
+ | `files.format` | `nested-json` | `nested-json` (`{ "a": { "b": "…" } }`) or `flat-json` (`{ "a.b": "…" }`). |
138
+ | `locales` | all | Platform locales to sync. |
139
+ | `localeMap` | none | Platform locale → file name, when the file is not named after the locale. |
140
+ | `release` | none | Release the keys `apply` creates are labelled with. Set it with `localness releases use`. Sync is never filtered by release. |
141
+ | `content` | `published` | `published` compares what `/bundle` serves; `draft` previews unpublished edits. |
142
+ | `keyPatterns`, `useDefaultKeyPatterns`, `extractTemplates` | | Used by the VS Code extension. |
143
+
144
+ Keys of unnamed drafts (`__unnamed_…`) are never written.