homeyform 0.0.0-stage → 0.3.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.
- package/CHANGELOG.md +136 -0
- package/CONTRIBUTING.md +96 -0
- package/LICENSE +18 -0
- package/README.md +566 -2
- package/SECURITY.md +25 -0
- package/dist/src/core/address.js +42 -0
- package/dist/src/core/ai-guide.js +88 -0
- package/dist/src/core/alarms.js +46 -0
- package/dist/src/core/apply-order.js +86 -0
- package/dist/src/core/card-keys.js +62 -0
- package/dist/src/core/cards.js +135 -0
- package/dist/src/core/check.js +137 -0
- package/dist/src/core/config.js +57 -0
- package/dist/src/core/context.js +137 -0
- package/dist/src/core/devices.js +68 -0
- package/dist/src/core/drivers.js +14 -0
- package/dist/src/core/export-tree.js +147 -0
- package/dist/src/core/file-name.js +47 -0
- package/dist/src/core/flow-path.js +5 -0
- package/dist/src/core/flow-values.js +170 -0
- package/dist/src/core/flows.js +178 -0
- package/dist/src/core/grid.js +9 -0
- package/dist/src/core/headers.js +11 -0
- package/dist/src/core/hidden-input.js +28 -0
- package/dist/src/core/init-files.js +139 -0
- package/dist/src/core/json.js +41 -0
- package/dist/src/core/literal-secrets.js +158 -0
- package/dist/src/core/plan/compare-flow.js +133 -0
- package/dist/src/core/plan/compute-plan.js +153 -0
- package/dist/src/core/plan/diff.js +83 -0
- package/dist/src/core/plan/plan-alarms.js +72 -0
- package/dist/src/core/plan/plan-devices.js +267 -0
- package/dist/src/core/plan/plan-flows.js +237 -0
- package/dist/src/core/plan/plan-folders.js +79 -0
- package/dist/src/core/plan/plan-scripts.js +125 -0
- package/dist/src/core/plan/plan-variables.js +74 -0
- package/dist/src/core/plan/plan-zones.js +121 -0
- package/dist/src/core/plan/prune-guard.js +55 -0
- package/dist/src/core/plan/references.js +86 -0
- package/dist/src/core/plan/render.js +52 -0
- package/dist/src/core/plan/resolve-flows.js +156 -0
- package/dist/src/core/plan/selector.js +56 -0
- package/dist/src/core/plan/step.js +23 -0
- package/dist/src/core/plan/types.js +3 -0
- package/dist/src/core/raw.js +2 -0
- package/dist/src/core/redact.js +11 -0
- package/dist/src/core/repo.js +2 -0
- package/dist/src/core/result.js +20 -0
- package/dist/src/core/scopes.js +116 -0
- package/dist/src/core/scripts.js +24 -0
- package/dist/src/core/secret-env.js +45 -0
- package/dist/src/core/secret-rules.js +53 -0
- package/dist/src/core/secret-suggestions.js +133 -0
- package/dist/src/core/secret.js +11 -0
- package/dist/src/core/tokens.js +42 -0
- package/dist/src/core/variables.js +38 -0
- package/dist/src/core/write-policy.js +110 -0
- package/dist/src/core/yaml.js +129 -0
- package/dist/src/core/zones.js +54 -0
- package/dist/src/shell/check-command.js +59 -0
- package/dist/src/shell/commands.js +185 -0
- package/dist/src/shell/errors.js +8 -0
- package/dist/src/shell/execute-plan.js +357 -0
- package/dist/src/shell/export-messages.js +90 -0
- package/dist/src/shell/init-command.js +337 -0
- package/dist/src/shell/main.js +244 -0
- package/dist/src/shell/prompt.js +51 -0
- package/dist/src/shell/read-client.js +122 -0
- package/dist/src/shell/repo-files.js +169 -0
- package/dist/src/shell/write-client.js +58 -0
- package/package.json +66 -4
- package/templates/AI_GUIDE.md +81 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to homeyform are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and versions follow
|
|
5
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## 0.3.0 - 2026-12-01
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `--prune-many` (plan and apply; implies `--prune`): apply refuses `--prune` when it would delete
|
|
12
|
+
more than 10 objects, or more than a quarter of a kind the Homey has (a single delete never
|
|
13
|
+
counts), unless it is given. plan shows the refusal as a warning.
|
|
14
|
+
- **flows.lock.yml records each Flow's id on the Homey** (both types; a standard Flow's entry is
|
|
15
|
+
its id alone). plan uses it to refuse a file whose Flow was renamed in the Homey app since the
|
|
16
|
+
last export ("export first"), and labels a delete candidate the lock has never seen "created in
|
|
17
|
+
the Homey app since the last export". A lock without ids still works; apply fills them in, and
|
|
18
|
+
the next export rewrites `flows.lock.yml` once with them.
|
|
19
|
+
- plan and export warn when `flows.lock.yml` is missing but there are Advanced Flow files (every
|
|
20
|
+
card would be new: new keys on export, new uuids on apply).
|
|
21
|
+
- **`homeyform check`**: one read per kind plan reads, with OK, the scope a refusal means, or why
|
|
22
|
+
the Homey is not reachable (an `https://` address that fails on the certificate gets a hint to
|
|
23
|
+
use `http://<ip>`), then whether export and plan would work (on a line each when a key that
|
|
24
|
+
may not read HomeyScript stops plan in a repository with scripts, but not export) and which
|
|
25
|
+
scopes apply needs. A key refused on every request (401) is one line (mistyped, deleted or
|
|
26
|
+
expired) rather than a scope per row. It never writes. Exit 0 ready, 1 not.
|
|
27
|
+
- **`homeyform init [dir]`**: a new repository, in four numbered steps: the address, a key to
|
|
28
|
+
create (only the read-only boxes and _Apps_ for HomeyScript; the full table after the run and
|
|
29
|
+
in `init --help`), the key pasted without echo (never a flag, never written), then check,
|
|
30
|
+
`homey.yml` and `.gitignore`, the AI guide if wanted (`--ai claude|cursor|agents|none`, written
|
|
31
|
+
where the assistant reads it, never over an existing file), export, a git commit if wanted, and
|
|
32
|
+
plan. On a terminal, a `HOMEY_ADDRESS` or `HOMEY_TOKEN` already set is asked about before use.
|
|
33
|
+
Literal secrets on the first export become a question: add the suggested rules to `homey.yml`
|
|
34
|
+
(comments kept) and export again. A directory holding only what init writes (and `.env`, `.git`)
|
|
35
|
+
is continued, keeping `homey.yml`. The next steps show how to keep the key for later runs
|
|
36
|
+
(`read -rs`, or a `chmod 600` `.env`). Without a terminal: `--address` and `HOMEY_TOKEN`,
|
|
37
|
+
`--git`.
|
|
38
|
+
- `templates/` is in the npm package (for `init --ai`), and so are `CONTRIBUTING.md` and
|
|
39
|
+
`SECURITY.md`, which the README links to.
|
|
40
|
+
- The AI guide and the README advise a read-only key for an AI assistant, with `apply` run by a
|
|
41
|
+
human with a separate key, and say why HomeyScript's `homey.app` weakens that.
|
|
42
|
+
|
|
43
|
+
### Changed
|
|
44
|
+
|
|
45
|
+
- **Flows and flow folders are managed only when `flows/` exists**, like every other kind: a
|
|
46
|
+
missing `flows/` no longer makes every Flow and folder on the Homey a delete candidate.
|
|
47
|
+
- **File names work on Windows too:** `:*?"<>|` in a Flow's, folder's or script's name become `_`,
|
|
48
|
+
and a name Windows reserves gets a `_` after it (`CON` → `CON_`). The next export renames such
|
|
49
|
+
files once; **run export before the first plan or apply after upgrading** -- until then plan
|
|
50
|
+
refuses a folder directory or script file whose name export no longer writes. Two Flows,
|
|
51
|
+
folders or scripts whose files differ only in case or Unicode normalisation are an export error
|
|
52
|
+
(one file on macOS and Windows), and export deletes before it writes, so a Flow renamed in case
|
|
53
|
+
only is no longer lost there.
|
|
54
|
+
- **export goes on past a Flow it cannot read** (a card's device gone, an ambiguous device name,
|
|
55
|
+
an id left after normalisation): a warning names the Flow and why, and its file and lock entry
|
|
56
|
+
are left as they are. plan and apply leave such a Flow alone -- never compared, written or
|
|
57
|
+
deleted, even with `--prune` -- and say so. One such card used to fail the whole export.
|
|
58
|
+
- **`--prune` never deletes what a Flow still uses:** a variable, alarm, virtual device, group or
|
|
59
|
+
script named in any Flow file, or held by a Homey Flow this apply does not write from a file, is
|
|
60
|
+
kept and listed with the reason. A Flow file among the paths that names a variable, alarm, device
|
|
61
|
+
or group the Homey has but its file lacks is a plan error rather than a reference about to
|
|
62
|
+
dangle.
|
|
63
|
+
- apply refuses `--prune` in a directory that has neither `zones.yml` nor `flows.lock.yml` (not
|
|
64
|
+
one homeyform exported).
|
|
65
|
+
- `zones.yml`, `variables.yml`, `devices.yml` or `alarms.yml` that parses to something other than a
|
|
66
|
+
list (or a zone whose `zones:` is not a list) is a plan error; it used to read as "none" and made
|
|
67
|
+
everything of the kind a delete candidate.
|
|
68
|
+
- A zone is kept while a subzone of it stays, as while it holds a device; the root zone is never a
|
|
69
|
+
delete candidate.
|
|
70
|
+
- apply refuses a `!secret NAME` whose environment variable is set but empty, as it refuses an
|
|
71
|
+
unset one: an empty credential is never written to the Homey.
|
|
72
|
+
- `npm run build` makes `dist/src/shell/main.js` executable, so a checkout or `npm link` runs it
|
|
73
|
+
by its path.
|
|
74
|
+
- The docs and messages name the address as `http://<the Homey's IP address>`: `https://` fails on
|
|
75
|
+
the Homey's certificate.
|
|
76
|
+
- The header comment of `zones.yml`, `devices.yml`, `variables.yml` and `flows.lock.yml` points to
|
|
77
|
+
the README's section on the file: the next export (or apply, for `flows.lock.yml`) rewrites
|
|
78
|
+
those headers once.
|
|
79
|
+
- Updating a script (`PUT {code}`, no `version`) and the `{ id, name }` script arg of a `run`
|
|
80
|
+
card are now measured on a Homey, no longer only taken from the specification.
|
|
81
|
+
|
|
82
|
+
## 0.2.0 - 2026-12-01
|
|
83
|
+
|
|
84
|
+
### Added
|
|
85
|
+
|
|
86
|
+
- **HomeyScript scripts are managed by plan and apply**, not only exported: `<scriptsDir>/<name>.js`
|
|
87
|
+
is a script's code, matched by name. apply creates a script from a new file, updates a changed
|
|
88
|
+
one's code, and deletes a script that has no file with `--prune` (never Athom's `example-*`
|
|
89
|
+
scripts, nor a script a Flow file still runs). Scripts are written after alarms and before the
|
|
90
|
+
Flows, so a Flow can run a script the same apply creates. Without a scripts directory, scripts
|
|
91
|
+
are not managed. The key needs `homey.app` for scripts, for reading too; create and delete are
|
|
92
|
+
measured on a Homey, update is not yet.
|
|
93
|
+
- **`@script(<name>)`:** a HomeyScript `run`/`runWithArg` card's `script` arg is written as
|
|
94
|
+
`@script(<name>)` and resolved back on plan and apply; a script that is neither on the Homey nor
|
|
95
|
+
in the files is a plan error.
|
|
96
|
+
- **`scriptsDir`** in `homey.yml`: the directory of HomeyScript's files (default `scripts`), for a
|
|
97
|
+
repository whose `scripts/` holds something else. Scripts an earlier export wrote to `scripts/`
|
|
98
|
+
stay there when you set it: move them (`git mv scripts/<name>.js <scriptsDir>/`).
|
|
99
|
+
|
|
100
|
+
### Changed
|
|
101
|
+
|
|
102
|
+
- plan and apply now read HomeyScript. When the key may not (403), script files among the paths
|
|
103
|
+
and Flows that run a script are an error rather than skipped; otherwise plan warns. apply needs
|
|
104
|
+
a key that may also write HomeyScript to change scripts (README, "API key").
|
|
105
|
+
- A Flow that runs a script (`run`/`runWithArg`) exports its arg as `@script(<name>)` instead of
|
|
106
|
+
the raw `{ id, name, … }` object: the next export changes such Flow files once.
|
|
107
|
+
|
|
108
|
+
## 0.1.0 - 2026-11-29
|
|
109
|
+
|
|
110
|
+
The first release.
|
|
111
|
+
|
|
112
|
+
### Added
|
|
113
|
+
|
|
114
|
+
- `homeyform export`: a Homey's logic as readable YAML files -- Flows and Advanced Flows (one file
|
|
115
|
+
per Flow, the directory is its folder), Logic variables, zones, flow folders, virtual devices,
|
|
116
|
+
device groups and alarms -- with every id replaced by a name, and lock files that keep the ids
|
|
117
|
+
and an Advanced Flow's card keys stable.
|
|
118
|
+
- `homeyform plan`: the difference between the files and the Homey, in the files' terms; nothing
|
|
119
|
+
is written. Exit 2 when apply would write something.
|
|
120
|
+
- `homeyform apply`: the same plan, then the writes after you confirm. Paired hardware is never
|
|
121
|
+
written; deletes need `--prune`.
|
|
122
|
+
- Literal secrets are refused at export: a value matching a `secrets:` rule in `homey.yml`, or a
|
|
123
|
+
credential the built-in rules recognise, is written as `!secret NAME` or stops the export.
|
|
124
|
+
- Node.js 22 or newer; one runtime dependency (`yaml`).
|
|
125
|
+
|
|
126
|
+
### Settings
|
|
127
|
+
|
|
128
|
+
- **`HOMEY_ADDRESS` is required.** There is no default address; set it to the Homey's local Web
|
|
129
|
+
API (`http://<address>[:port]`).
|
|
130
|
+
- **One API key, `HOMEY_TOKEN`,** for reading and writing alike. Give it the read scopes, plus the
|
|
131
|
+
write scopes if you use `apply` (README, "API key").
|
|
132
|
+
- **Secrets come from the environment.** `!secret NAME` is read from the environment variable
|
|
133
|
+
`NAME` at apply time; homeyform decrypts nothing itself. A `homey.yml` with a `secretsFile`
|
|
134
|
+
setting is an error that says what to do instead (README, "Secrets").
|
|
135
|
+
- **`standardFlowFolder` is a setting.** The folder where standard Flows are expected is named in
|
|
136
|
+
`homey.yml`; unset, there is no warning about standard Flows at all.
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
homeyform lives at [github.com/crusaider/homeyform](https://github.com/crusaider/homeyform). Bug
|
|
4
|
+
reports go to its issues (the form asks for what a report needs); for anything larger than a fix,
|
|
5
|
+
open an issue first so we can agree on the approach. Never paste an API key, an IP address or an
|
|
6
|
+
unredacted export anywhere; security issues go through [SECURITY.md](SECURITY.md).
|
|
7
|
+
|
|
8
|
+
## Setup
|
|
9
|
+
|
|
10
|
+
Node.js 22 or newer (CI runs 22 and 24 on Linux, macOS and Windows).
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm ci
|
|
14
|
+
npm run check # type check, lint, format check, tests: the gate CI runs
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
| Script | What it does |
|
|
18
|
+
| ------------------- | ------------------------------------------------------------------ |
|
|
19
|
+
| `npm run build` | `tsc` to `dist/` (sources and tests) |
|
|
20
|
+
| `npm test` | build, then `node --test` on `dist/test/**/*.test.js` |
|
|
21
|
+
| `npm run typecheck` | `tsc --noEmit` |
|
|
22
|
+
| `npm run lint` | ESLint (typescript-eslint, flat config: `eslint.config.js`) |
|
|
23
|
+
| `npm run format` | Prettier, applied |
|
|
24
|
+
| `npm run check` | all of the above but `format`; must be green before a pull request |
|
|
25
|
+
|
|
26
|
+
The tests need no Homey: plan and apply run against an in-memory fake (`test/support/fake-homey.ts`).
|
|
27
|
+
To try the CLI against a real Homey, set `HOMEY_ADDRESS` and `HOMEY_TOKEN` and run
|
|
28
|
+
`node dist/src/shell/main.js export --out /tmp/scratch` — into a scratch directory.
|
|
29
|
+
|
|
30
|
+
## Style
|
|
31
|
+
|
|
32
|
+
- **A pure core, a thin shell.** `src/core` does no I/O (no `node:*` imports, enforced by ESLint)
|
|
33
|
+
and returns expected failures as values (`Result`, `src/core/result.ts`). `src/shell` does the
|
|
34
|
+
I/O (the Homey's API, the files, the terminal) and is the only place an exception is thrown.
|
|
35
|
+
`src/core/plan/` computes a plan; `src/shell/execute-plan.ts` carries it out.
|
|
36
|
+
- **Functional, in plain TypeScript.** No classes. `readonly` data; never change an argument or
|
|
37
|
+
module state; `const` (no `let` in the core). Discriminated unions with exhaustive `switch`. No
|
|
38
|
+
FP library: a reader should need nothing but TypeScript.
|
|
39
|
+
- **Small modules with one job,** names that say what they do, and a comment where the _why_ is not
|
|
40
|
+
obvious — especially a fact about the Homey's API: say whether it was measured on a Homey or taken
|
|
41
|
+
from Athom's specification.
|
|
42
|
+
- **One runtime dependency, `yaml`,** pinned exactly: the files' text depends on it. Add another only
|
|
43
|
+
with a reason in the commit message.
|
|
44
|
+
- **TypeScript is strict**, with `noUncheckedIndexedAccess` and `exactOptionalPropertyTypes`.
|
|
45
|
+
- **Two clients.** Reads go through a client that sends nothing but GET; every write apply may make
|
|
46
|
+
is on the write client's list (`src/core/write-policy.ts`). A new kind of write is a new entry
|
|
47
|
+
there, with a test.
|
|
48
|
+
|
|
49
|
+
## Tests and fixtures
|
|
50
|
+
|
|
51
|
+
- Every behaviour has a test; a change to the file format changes `test/fixtures/expected/` in the
|
|
52
|
+
same commit, deliberately.
|
|
53
|
+
- **No data from a real house**, ever, not even in a commit you revert later: no real device, zone,
|
|
54
|
+
Flow or variable names or ids, no addresses or host names, no person's names, no radio codes, no
|
|
55
|
+
keys. Fixtures use invented names (see `test/fixtures/sample/` and `test/support/synthetic.ts`). A
|
|
56
|
+
credential-like test value is assembled at run time, as `AUTH_VALUE` is.
|
|
57
|
+
|
|
58
|
+
## Commits and pull requests
|
|
59
|
+
|
|
60
|
+
Small and focused, with a message that says why. A pull request needs a green CI (`ci`); add a line
|
|
61
|
+
under "Unreleased" in `CHANGELOG.md` for a change users notice.
|
|
62
|
+
|
|
63
|
+
## Releasing
|
|
64
|
+
|
|
65
|
+
A release is a tag; the `release` workflow (`.github/workflows/release.yml`) publishes it to npmjs.
|
|
66
|
+
|
|
67
|
+
1. In a pull request: bump `version` in `package.json` (`npm version X.Y.Z --no-git-tag-version`,
|
|
68
|
+
which updates `package-lock.json` too) and move `CHANGELOG.md`'s "Unreleased" entries under a
|
|
69
|
+
heading `X.Y.Z - <date>`.
|
|
70
|
+
2. Merge it to `main`; CI must be green.
|
|
71
|
+
3. Tag the merge on `main` and push the tag:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
git switch main && git pull
|
|
75
|
+
git tag -a vX.Y.Z -m "homeyform X.Y.Z"
|
|
76
|
+
git push origin vX.Y.Z
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The workflow checks that the tag is `v` + `package.json`'s version (and fails otherwise), runs
|
|
80
|
+
`npm ci && npm run check`, and runs `npm publish --provenance --access public`; `prepack` builds
|
|
81
|
+
`dist/` afresh, so the tarball never holds a stale build. To see what a tarball will hold:
|
|
82
|
+
`npm pack --dry-run`. A version that is already published cannot be published again; a failed or
|
|
83
|
+
wrong release is fixed with a new version.
|
|
84
|
+
|
|
85
|
+
### What publishing needs
|
|
86
|
+
|
|
87
|
+
Publishing uses npm's [trusted publishing](https://docs.npmjs.com/trusted-publishers): the
|
|
88
|
+
workflow proves its identity to npmjs with GitHub's OIDC token, and no npm token is stored.
|
|
89
|
+
|
|
90
|
+
- **On npmjs**, in the `homeyform` package's settings, a trusted publisher of type GitHub Actions:
|
|
91
|
+
owner `crusaider`, repository `homeyform`, workflow file `release.yml`, environment `npm`.
|
|
92
|
+
Whether a package that does not exist on npmjs yet can be given a trusted publisher before its
|
|
93
|
+
first version, or needs one manual first publish, check npm's documentation at the time.
|
|
94
|
+
- **On GitHub**, in the repository's settings, an environment named `npm`. Restrict it to tags
|
|
95
|
+
`v*` (deployment branches and tags) so that only a release tag can publish.
|
|
96
|
+
- Nothing else: no `NPM_TOKEN` secret. The job has `id-token: write` only for itself.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jonas Andreasson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
15
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
16
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|