@openreachtech/hora-skills-ort-renchan 0.0.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.
Files changed (126) hide show
  1. package/LICENSE +201 -0
  2. package/README.ja.md +135 -0
  3. package/README.md +135 -0
  4. package/dist/skills/hor-agent-loop/SKILL.md +123 -0
  5. package/dist/skills/hor-agent-loop/references/core.md +485 -0
  6. package/dist/skills/hor-agent-loop/references/graphql-integration.md +178 -0
  7. package/dist/skills/hor-agent-loop/references/renchan-job-integration.md +368 -0
  8. package/dist/skills/hor-agent-loop/references/testing.md +492 -0
  9. package/dist/skills/hor-ai-agent-structure/SKILL.md +403 -0
  10. package/dist/skills/hor-ai-agent-structure/references/loop-and-actions.md +100 -0
  11. package/dist/skills/hor-ai-prompt-document-store/SKILL.md +220 -0
  12. package/dist/skills/hor-ai-prompt-document-store/references/models-and-composition.md +156 -0
  13. package/dist/skills/hor-backend-testing/SKILL.md +118 -0
  14. package/dist/skills/hor-backend-testing/references/placement-and-ordering.md +89 -0
  15. package/dist/skills/hor-backend-testing/references/purity-and-mocks.md +82 -0
  16. package/dist/skills/hor-backend-testing/references/running-tests.md +186 -0
  17. package/dist/skills/hor-bank-id/SKILL.md +91 -0
  18. package/dist/skills/hor-build-e2e-test-environment/SKILL.md +609 -0
  19. package/dist/skills/hor-build-e2e-test-environment/references/compose-definition.md +368 -0
  20. package/dist/skills/hor-build-e2e-test-environment/references/edge-and-proxy.md +287 -0
  21. package/dist/skills/hor-build-e2e-test-environment/references/environment-and-ports.md +201 -0
  22. package/dist/skills/hor-build-e2e-test-environment/references/runner-and-lifecycle.md +330 -0
  23. package/dist/skills/hor-build-e2e-test-environment/references/seed-data.md +145 -0
  24. package/dist/skills/hor-build-e2e-test-environment/references/windows-runner.md +146 -0
  25. package/dist/skills/hor-constant-definition/SKILL.md +139 -0
  26. package/dist/skills/hor-cookie-authentication/SKILL.md +33 -0
  27. package/dist/skills/hor-cookie-authentication/references/auth-filter.md +55 -0
  28. package/dist/skills/hor-cookie-authentication/references/cookie-context.md +53 -0
  29. package/dist/skills/hor-cookie-authentication/references/dev-login-seeder.md +22 -0
  30. package/dist/skills/hor-cookie-authentication/references/environment.md +64 -0
  31. package/dist/skills/hor-cookie-authentication/references/error-codes.md +24 -0
  32. package/dist/skills/hor-cookie-authentication/references/migrations.md +18 -0
  33. package/dist/skills/hor-cookie-authentication/references/resolvers.md +97 -0
  34. package/dist/skills/hor-cookie-authentication/references/session-clerk.md +41 -0
  35. package/dist/skills/hor-cookie-authentication/references/token-models.md +125 -0
  36. package/dist/skills/hor-database-design/SKILL.md +54 -0
  37. package/dist/skills/hor-database-design/references/column-types.md +92 -0
  38. package/dist/skills/hor-database-design/references/datetimes.md +88 -0
  39. package/dist/skills/hor-database-design/references/master-tables.md +117 -0
  40. package/dist/skills/hor-database-design/references/normalization.md +40 -0
  41. package/dist/skills/hor-database-design/references/update-history.md +35 -0
  42. package/dist/skills/hor-execution-placement-pattern/SKILL.md +216 -0
  43. package/dist/skills/hor-external-api-client/SKILL.md +99 -0
  44. package/dist/skills/hor-external-api-client/references/architecture.md +127 -0
  45. package/dist/skills/hor-external-api-client/references/authorization.md +105 -0
  46. package/dist/skills/hor-external-api-client/references/capsule.md +130 -0
  47. package/dist/skills/hor-external-api-client/references/conventions.md +68 -0
  48. package/dist/skills/hor-external-api-client/references/launcher.md +138 -0
  49. package/dist/skills/hor-external-api-client/references/payload.md +176 -0
  50. package/dist/skills/hor-external-api-client/references/sdk-wrapper.md +291 -0
  51. package/dist/skills/hor-external-api-client/references/testing.md +130 -0
  52. package/dist/skills/hor-external-api-client/references/usage.md +152 -0
  53. package/dist/skills/hor-graphql-schema/SKILL.md +360 -0
  54. package/dist/skills/hor-graphql-server-engine/SKILL.md +356 -0
  55. package/dist/skills/hor-light-rag/SKILL.md +242 -0
  56. package/dist/skills/hor-light-rag/references/retrieval-internals.md +143 -0
  57. package/dist/skills/hor-multi-llm-provider/SKILL.md +288 -0
  58. package/dist/skills/hor-multi-llm-provider/references/provider-internals.md +153 -0
  59. package/dist/skills/hor-mutation-resolver/SKILL.md +360 -0
  60. package/dist/skills/hor-mutation-resolver/references/dependency-injection.md +148 -0
  61. package/dist/skills/hor-mutation-resolver/references/errors.md +120 -0
  62. package/dist/skills/hor-mutation-resolver/references/resolve-flow.md +275 -0
  63. package/dist/skills/hor-mutation-resolver/references/testing.md +125 -0
  64. package/dist/skills/hor-mutation-resolver/references/transaction.md +197 -0
  65. package/dist/skills/hor-post-worker/SKILL.md +320 -0
  66. package/dist/skills/hor-query-resolver/SKILL.md +246 -0
  67. package/dist/skills/hor-query-resolver/references/anatomy.md +384 -0
  68. package/dist/skills/hor-query-resolver/references/data-access.md +248 -0
  69. package/dist/skills/hor-query-resolver/references/errors-and-context.md +172 -0
  70. package/dist/skills/hor-query-resolver/references/testing.md +241 -0
  71. package/dist/skills/hor-renchan-job-bullmq/SKILL.md +178 -0
  72. package/dist/skills/hor-renchan-job-bullmq/references/daemon-and-scheduler.md +182 -0
  73. package/dist/skills/hor-renchan-job-bullmq/references/engine-and-infra.md +106 -0
  74. package/dist/skills/hor-renchan-job-bullmq/references/job-triple.md +189 -0
  75. package/dist/skills/hor-renchan-job-bullmq/references/queues.md +74 -0
  76. package/dist/skills/hor-renchan-job-bullmq/references/subscriptions.md +113 -0
  77. package/dist/skills/hor-resolver-share/SKILL.md +262 -0
  78. package/dist/skills/hor-resolver-validator/SKILL.md +194 -0
  79. package/dist/skills/hor-resolver-validator/references/inspector-api.md +115 -0
  80. package/dist/skills/hor-resolver-validator/references/validator-pattern.md +281 -0
  81. package/dist/skills/hor-restfulapi-architecture/SKILL.md +275 -0
  82. package/dist/skills/hor-restfulapi-architecture/references/engine-and-context.md +192 -0
  83. package/dist/skills/hor-restfulapi-architecture/references/renderers.md +204 -0
  84. package/dist/skills/hor-restfulapi-architecture/references/response-and-flusher.md +118 -0
  85. package/dist/skills/hor-restfulapi-architecture/references/validation.md +229 -0
  86. package/dist/skills/hor-security-audit/SKILL.md +110 -0
  87. package/dist/skills/hor-security-audit/references/application-surface.md +90 -0
  88. package/dist/skills/hor-security-audit/references/auth-and-transport.md +147 -0
  89. package/dist/skills/hor-security-audit/references/code-safety.md +74 -0
  90. package/dist/skills/hor-security-audit/references/dependencies.md +72 -0
  91. package/dist/skills/hor-security-audit/references/network-and-logging.md +56 -0
  92. package/dist/skills/hor-security-audit/references/secrets.md +95 -0
  93. package/dist/skills/hor-sequelize-migration/SKILL.md +336 -0
  94. package/dist/skills/hor-sequelize-migration/references/alter-table.md +147 -0
  95. package/dist/skills/hor-sequelize-migration/references/foreign-keys.md +107 -0
  96. package/dist/skills/hor-sequelize-migration/references/indexes.md +149 -0
  97. package/dist/skills/hor-sequelize-migration/references/notation.md +215 -0
  98. package/dist/skills/hor-sequelize-model/SKILL.md +69 -0
  99. package/dist/skills/hor-sequelize-model/references/associations.md +218 -0
  100. package/dist/skills/hor-sequelize-model/references/default-methods.md +244 -0
  101. package/dist/skills/hor-sequelize-model/references/mixins.md +247 -0
  102. package/dist/skills/hor-sequelize-model/references/notation.md +225 -0
  103. package/dist/skills/hor-sequelize-model/references/timestamps.md +74 -0
  104. package/dist/skills/hor-sequelize-seeder/SKILL.md +275 -0
  105. package/dist/skills/hor-sequelize-seeder/references/development-coverage.md +74 -0
  106. package/dist/skills/hor-sequelize-seeder/references/directory-structure.md +113 -0
  107. package/dist/skills/hor-sequelize-seeder/references/id-numbering.md +133 -0
  108. package/dist/skills/hor-sequelize-seeder/references/naming.md +59 -0
  109. package/dist/skills/hor-sequelize-seeder/references/notation.md +170 -0
  110. package/dist/skills/hor-sequelize-subquery/SKILL.md +369 -0
  111. package/dist/skills/hor-strategy-pattern/SKILL.md +371 -0
  112. package/dist/skills/hor-stub-api/SKILL.md +330 -0
  113. package/dist/skills/hor-subscription-resolver/SKILL.md +105 -0
  114. package/dist/skills/hor-subscription-resolver/references/authentication.md +99 -0
  115. package/dist/skills/hor-subscription-resolver/references/basic-notation.md +116 -0
  116. package/dist/skills/hor-subscription-resolver/references/design-philosophy.md +68 -0
  117. package/dist/skills/hor-type-interface/SKILL.md +200 -0
  118. package/docs/skills.ja.md +40 -0
  119. package/docs/skills.md +40 -0
  120. package/lib/equip/CommandLineArguments.js +178 -0
  121. package/lib/equip/HoraSkillsCli.js +590 -0
  122. package/lib/equip/SkillsInstaller.js +443 -0
  123. package/lib/equip/SkillsManifestFile.js +260 -0
  124. package/lib/equip/constants/CLI_COMMAND.js +8 -0
  125. package/lib/equip/hora-skills-ort-renchan.js +8 -0
  126. package/package.json +51 -0
@@ -0,0 +1,145 @@
1
+ # Seed data for the E2E environment
2
+
3
+ The two seeder directories the E2E stack owns, why they are separate from the unit-test fixtures, how
4
+ their ids are allocated, and the artifacts a seeder cannot carry. Referenced from §6 of
5
+ [SKILL.md](../SKILL.md). `<stack-env>` stands for the E2E stack's own environment name —
6
+ `live-local` is the recommended name, giving `live-local-master/` and `live-local/`; ids,
7
+ directory names and values are **illustrative examples**.
8
+
9
+ > Everything here is about the **system of record's rows** and is the least stack-dependent part of the
10
+ > skill: the tooling shown is Sequelize's CLI and the read model is a search index, but the rules
11
+ > below hold for any store and any seeding tool.
12
+
13
+ ## Two directories of its own
14
+
15
+ | Directory | Holds | Applied by | Corresponds to |
16
+ | --- | --- | --- | --- |
17
+ | `sequelize/seeders/<stack-env>-master/` | the master / metadata rows the stack requires to run, **re-exported** from the production master, plus E2E-only master samples | `db:seed:<stack-env>-master` | the dev-master set |
18
+ | `sequelize/seeders/<stack-env>/` | the operational rows the environment is filled with, including the accounts the operator signs in with | `db:seed:<stack-env>` | the development set |
19
+
20
+ ```json
21
+ {
22
+ "db:seed:<stack-env>-master": "export NODE_ENV=<stack-env>; sequelize-cli db:seed:all --seeders-path sequelize/seeders/<stack-env>-master --debug",
23
+ "db:seed:<stack-env>": "export NODE_ENV=<stack-env>; sequelize-cli db:seed:all --seeders-path sequelize/seeders/<stack-env> --debug"
24
+ }
25
+ ```
26
+
27
+ - **The master directory is named `<stack-env>-master`, never `master-<stack-env>`.** In the
28
+ project's seeder convention, `master-*` is the release-split **production** master namespace
29
+ (`master-000001/`, `master-000002/`, …), applied in ascending order by `db:seed:prod` — a
30
+ directory named into that pattern gets classified as a production release, and can be picked up by
31
+ the production seed run. The suffix form keeps the environment name first, pairing
32
+ `<stack-env>-master/` with `<stack-env>/` the way `dev-master/` pairs with `development/`.
33
+ - **Write seeders for a single application to an empty schema.** Every row carries an explicit id,
34
+ so applying the set to a database that already holds it collides on insert — and that collision is
35
+ the intended behaviour, not a gap to close. It is the environment saying *you meant `up.sh`*,
36
+ which cleans first. Adding upserts, `IGNORE` or existence checks to make the set survive a second
37
+ application gains nothing and gives up the guarantee that the rows in the database are the rows in
38
+ the file ([runner-and-lifecycle.md](./runner-and-lifecycle.md)).
39
+ - The environment name is set inside the script, so forgetting an export cannot apply the seeders to
40
+ the wrong database.
41
+ - The directory is chosen by `--seeders-path`, exactly as the existing seed sets do; the seeder file
42
+ format stays the same (skeleton, `TimestampSeedsSupplier`, explicit ids, `up`/`down` — follow the
43
+ project's seeder convention).
44
+ - **A file skeleton stays identical to every other seeder.** Only the *directory* says which
45
+ environment the rows are for.
46
+
47
+ ## Why not reuse the unit-test fixtures
48
+
49
+ The two sets are used by tools that need opposite shapes:
50
+
51
+ | | unit-test fixtures | E2E rows |
52
+ | --- | --- | --- |
53
+ | shape | exhaustive — every status, every branch, every null | minimal and **pipeline-shaped**: a few rows that will actually flow end to end |
54
+ | size | as large as coverage needs | as small as possible; every row becomes an entry in the read model and a change to propagate |
55
+ | churn | edited whenever a unit test needs a new case | edited only when the pipeline's shape changes |
56
+
57
+ Sharing one set couples them: a row added to satisfy a validator's edge case becomes another document
58
+ in the index and another line on a screen; a row reshaped for the pipeline breaks a unit test in a
59
+ different directory. **Separate directories make it obvious what a change can break** — and the split
60
+ is the reason the E2E build never applies the development set.
61
+
62
+ ## Master rows are re-exported, never copied
63
+
64
+ Some master ids end up **inside a derived artifact** — an id written into a read-model entry (a search
65
+ document in the example), a key a mapping or a view definition is built from. If those ids differ
66
+ between environments, a read model built in one environment cannot be read or compared in another, and
67
+ rebuilding it silently produces entries that do not match the metadata.
68
+
69
+ So the stack's master set **references** the production master rather than restating it:
70
+
71
+ ```js
72
+ 'use strict'
73
+
74
+ /*
75
+ * Re-export of the production master (the source of truth is
76
+ * sequelize/seeders/<production-master-dir>/<same-name>.cjs).
77
+ * The stack environment must load exactly the production master rows, so the data is
78
+ * referenced, never copied.
79
+ */
80
+
81
+ module.exports = require('../<production-master-dir>/<same-name>.cjs')
82
+ ```
83
+
84
+ - **Keep the filename identical** to the file being re-exported, so the two are obviously a pair and
85
+ the run order matches.
86
+ - **Copy-paste is the failure mode this prevents.** A copied master file diverges the first time a
87
+ column is added to only one of them, and the symptom appears as a search result missing a field —
88
+ nowhere near the seeder.
89
+ - **Stack-only master samples** (rows production creates through an admin screen rather than seeding)
90
+ belong here too, as their own files with their own ids.
91
+
92
+ ## Ids come from a reserved band
93
+
94
+ Follow the project's existing id rule — every row carries an **explicit** id, blocks are 10,000 wide
95
+ — but allocate the stack's blocks from a **band of their own**, starting above every block the other
96
+ seed sets already occupy:
97
+
98
+ | Seed set | Id band | Example bases |
99
+ | --- | --- | --- |
100
+ | unit-test fixtures (the project's ordinary set) | the blocks the project's seeder convention already allocates | `100000`, `110000`, `120000`, … |
101
+ | **E2E fixtures (`<stack-env>/`)** | **a band of their own, above all of those** | `800000`, `810000`, `820000`, … |
102
+ | E2E master samples (`<stack-env>-master/`) | the same band, above their parent's block | |
103
+
104
+ - **A row's origin is then readable from its id.** An id from the E2E band, seen on a screen or in a
105
+ log, says immediately which seed set put it there — worth a lot when the same table is filled by
106
+ two sets in two environments.
107
+ - **The two sets cannot collide on primary key** even if both are somehow applied to one database, so
108
+ the mistake surfaces as unexpected *rows* rather than as an insert failure halfway through.
109
+ - **Foreign-key columns still hold an id from the referenced table's block**, and the band applies to
110
+ the referenced block too — an E2E row points at E2E rows, not at unit-test rows.
111
+ - Re-exported production master files keep the **production** ids (small and meaningful). The band
112
+ applies only to rows this set introduces.
113
+
114
+ ## Seeds insert rows, not files
115
+
116
+ A seeder cannot carry a binary: committing one means maintaining it, and the real assets often
117
+ cannot be committed at all. So the rows say a file is present — a status, a size, a page or item
118
+ count — while the bytes are not on disk, and every request for the file answers 404.
119
+
120
+ A screen that opens such a record then breaks for a reason that has nothing to do with the code.
121
+ **The build therefore has a step that generates the artifacts the seeds promise**, after seeding and
122
+ before the environment is handed over:
123
+
124
+ - Generate from the rows, so the two always match — read the seeded records and write a stand-in for
125
+ each.
126
+ - **Write only what the application actually serves** (the derived artifacts the screens or the API
127
+ hand back). There is no original file for it to reproduce.
128
+ - **Make the stand-in obviously synthetic** — a placeholder that is unmistakable at a glance — so
129
+ nobody takes a fixture for real data on a screen.
130
+ - **Write it under the per-run storage path** (`FILE_STORAGE_PATH` is overridden for the run), not
131
+ into the working tree.
132
+ - **Safe to run again**: rewrite every file from scratch rather than skipping existing ones.
133
+
134
+ ## Keep the set pipeline-shaped
135
+
136
+ A row earns its place here by covering a **path**, not a branch. When adding rows, prefer:
137
+
138
+ - **One complete chain** over many partial ones — a record that has everything the pipeline needs to
139
+ produce a read-model entry, so a single row exercises the whole path.
140
+ - **Rows that make propagation visible** — distinct, recognizable text, so it is obvious at a glance
141
+ whether something arrived rather than something being counted.
142
+ - **A deliberate negative** — one record that must *not* reach the read model (unsynced column,
143
+ excluded category), so the filter's effect is visible too. Without one, propagating everything
144
+ looks exactly like the filter working.
145
+ - **Nothing added just because a unit test wanted it.** That row belongs in the other set.
@@ -0,0 +1,146 @@
1
+ # Running the environment from Windows
2
+
3
+ **Opt-in. Read this only if someone has actually asked for Windows-native scripts.** The default is
4
+ Ubuntu or WSL2, the `.sh` scripts are the real ones, and you need none of this to build the
5
+ environment. Referenced from the machine assumptions in [SKILL.md](../SKILL.md).
6
+
7
+ ## Why there is a default at all
8
+
9
+ Two sets of scripts means making every change twice. Sooner or later one of them gets missed. It
10
+ fails like this: *"the environment comes up ninety percent of the way, but only on Windows"* — which
11
+ is exactly what this skill exists to prevent. So write the second set only when someone has decided
12
+ they need it, and let them carry the cost.
13
+
14
+ **First, look for a way to avoid it.** Anything you move into a container stops depending on the OS.
15
+ `docker compose` behaves the same everywhere. Only the host-side scripts differ. A stack in shape A
16
+ — client, edge and application all in containers
17
+ ([edge-and-proxy.md](./edge-and-proxy.md)) — barely needs host-side scripts at all. That is the real
18
+ fix.
19
+
20
+ ## What differs per machine
21
+
22
+ | | Linux / WSL2 | macOS | Plain Windows |
23
+ | --- | --- | --- | --- |
24
+ | bash | 4 or later | **3.2** — no `declare -A`, `mapfile`, `${x,,}` | none |
25
+ | core tools | GNU | **BSD** — `sed -i` needs an argument, and there is no `timeout`, `date -d` or `grep -P` | none |
26
+ | memory ceiling | the machine's | the Docker VM's share | the WSL2 VM's share, **half the machine by default** |
27
+ | bind-mount speed | native | slower, through VirtioFS | very slow under `/mnt/c`. Keep the repository on the Linux side |
28
+ | line endings | LF | LF | CRLF sneaks in through `core.autocrlf` |
29
+ | `/etc/hosts` | stays as you left it | stays as you left it | WSL2 rewrites it by default |
30
+
31
+ The macOS column is why the scripts target bash 3.2 with no GNU-only options, even though nobody
32
+ chooses 3.2 on purpose.
33
+
34
+ ## Why plain Windows cannot run the `.sh` scripts
35
+
36
+ **The problem is the host-side scripts, not the stack.** Everything compose starts behaves the same
37
+ on every OS. The five scripts are what will not run: `up`, `start`, `seed`, `clean` and `down`.
38
+
39
+ | What they use | For | On plain Windows |
40
+ | --- | --- | --- |
41
+ | shell syntax | `set -euo pipefail`, `trap ... EXIT`, `[[ ]]` | no bash. PowerShell has close equivalents, so this is a rewrite, not a port |
42
+ | background start, and the PID | starting the application and daemons, saving PIDs, stopping them in `down.sh` | `Start-Process` and `Stop-Process` work, but **Windows has no SIGTERM**. You can only force a kill |
43
+ | `trap ... EXIT` | making sure a failed build leaves nothing half-built | `try/finally` is close, but does not cover as much as `EXIT` |
44
+ | host commands | `curl` to wait for health, `grep` / `sed` / `awk` for logs | `curl.exe` exists. `wget` is an alias for `Invoke-WebRequest` with different arguments. The rest are missing |
45
+ | file modes | config permissions, the executable bit | NTFS has neither, and `chmod` does nothing |
46
+ | line endings | scripts, and configs mounted into containers | CRLF shows up inside the container as `bash\r: bad interpreter` |
47
+
48
+ **The second row is the one you cannot write your way around.** `down.sh` stops the processes before
49
+ the containers, and that only helps if the stop is graceful. Where you can only force a kill, a
50
+ worker dies holding its connections and the ordering buys you nothing. Say so, rather than letting
51
+ it look the same.
52
+
53
+ **Git Bash mostly works, and fails quietly.** MSYS rewrites paths on their way to `docker` (turn it
54
+ off with `MSYS_NO_PATHCONV=1`), and processes and signals are still Windows'. Worth knowing about.
55
+ Not a setup to support.
56
+
57
+ ## What to require, if you do write them
58
+
59
+ - **PowerShell 7 or later.** Windows PowerShell 5.1 handles `Invoke-WebRequest` and errors
60
+ differently, so it is out of scope. Say this at the top of every script.
61
+ - **The operator's commands do not change.** `up.ps1`, `start.ps1`, `seed.ps1`, `clean.ps1` and
62
+ `down.ps1` — same names, same jobs, same closing message as the `.sh` scripts. One intention, one
63
+ command, on either OS.
64
+ - **The `.sh` scripts stay the real ones.** Add a step there, then mirror it in the `.ps1` scripts
65
+ **in the same change**. Never one without the other.
66
+ - **Write down the differences you cannot remove**, at the top of the script and in the closing
67
+ message. Never let it behave differently in silence.
68
+ - **Ship nothing you have not run.** Record which Windows build and which PowerShell version you
69
+ tested on. A script nobody has run is not finished — the same rule as checking from the side that
70
+ uses it.
71
+
72
+ ## The same job, in each shell
73
+
74
+ | Job | POSIX (the real one) | PowerShell 7 |
75
+ | --- | --- | --- |
76
+ | stop on the first failure | `set -e` | `$ErrorActionPreference = 'Stop'`, plus checking `$LASTEXITCODE` after **every** native command |
77
+ | fail when a pipe fails | `set -o pipefail` | **nothing equivalent.** Split the pipeline into steps and check `$LASTEXITCODE` at each one |
78
+ | clean up on abort | `trap ... EXIT` | `try { } finally { }` |
79
+ | start in the background, keep the PID | `cmd >log 2>&1 & echo $!` | `Start-Process -PassThru -RedirectStandardOutput -RedirectStandardError`, then `$p.Id`. **The two streams cannot go to one file**, so keep two logs per process |
80
+ | stop a process | `kill` (SIGTERM) | `Stop-Process` (forced). For a graceful stop, give the application its own signal — a file, an endpoint, a queue message |
81
+ | wait for health | `curl` in a loop | `Invoke-WebRequest -UseBasicParsing` in a loop, catching connection failures with `try/catch` |
82
+ | measure a deadline | count elapsed seconds | `[Diagnostics.Stopwatch]` |
83
+ | find the script's folder | a path relative to the script | `$PSScriptRoot` |
84
+
85
+ ## What one script looks like
86
+
87
+ ```powershell
88
+ #Requires -Version 7.0
89
+ # The real version is start.sh. Change both in the same commit.
90
+ # Difference we cannot remove: stop is a forced kill, because Windows has no SIGTERM.
91
+
92
+ $ErrorActionPreference = 'Stop'
93
+ Set-StrictMode -Version Latest
94
+
95
+ $root = Split-Path -Parent $PSScriptRoot
96
+ $logs = Join-Path $PSScriptRoot 'logs'
97
+ New-Item -ItemType Directory -Force -Path $logs | Out-Null
98
+
99
+ try {
100
+ docker compose -f (Join-Path $PSScriptRoot 'docker/compose.yaml') up -d
101
+ if ($LASTEXITCODE -ne 0) { throw 'compose up failed' }
102
+
103
+ # wait for health from the host — the side that will use it
104
+ $deadline = [Diagnostics.Stopwatch]::StartNew()
105
+ while ($true) {
106
+ try {
107
+ Invoke-WebRequest -UseBasicParsing 'http://127.0.0.1:18080/healthz' | Out-Null
108
+ break
109
+ } catch {
110
+ if ($deadline.Elapsed.TotalSeconds -gt 120) {
111
+ throw 'the edge never answered. docker compose logs edge'
112
+ }
113
+ Start-Sleep -Seconds 2
114
+ }
115
+ }
116
+
117
+ $app = Start-Process -PassThru -FilePath 'node' -ArgumentList 'server/index.js' `
118
+ -RedirectStandardOutput (Join-Path $logs 'app.out.log') `
119
+ -RedirectStandardError (Join-Path $logs 'app.err.log')
120
+ $app.Id | Set-Content (Join-Path $logs 'app.pid')
121
+ }
122
+ catch {
123
+ & (Join-Path $PSScriptRoot 'down.ps1') # never clean.ps1
124
+ throw
125
+ }
126
+
127
+ Write-Host "open http://127.0.0.1:18080/ | logs: e2e/logs | stop: e2e/down.ps1"
128
+ ```
129
+
130
+ Notice the two log files for one process, the deadline measured with a stopwatch, the health check
131
+ made from the host, and the abort path calling `down`, never `clean`. Those are the same rules the
132
+ `.sh` scripts follow.
133
+
134
+ ## Recording what you tested
135
+
136
+ Keep this next to the scripts, and update it whenever they change:
137
+
138
+ ```
139
+ Verified on: Windows 11 23H2 / PowerShell 7.4.6 / Docker Desktop 29.5.2
140
+ Date: 2026-08-22
141
+ Scope: up / start / seed / clean / down, full rebuild from nothing
142
+ Not covered: graceful shutdown — Stop-Process is a forced kill
143
+ ```
144
+
145
+ A note with no version and no date is not a record. If nobody can say which build it ran on, it has
146
+ not been tested.
@@ -0,0 +1,139 @@
1
+ ---
2
+ name: hor-constant-definition
3
+ description: >
4
+ Define application constants the Renchan way: one constant (one category) per file, ALWAYS as
5
+ two files — a CommonJS master constants/<name>.cjs (the single source of truth) plus an ESM
6
+ bridge app/constants/<name>.js that re-exports it. Use this skill whenever the user asks to add
7
+ or change a constant — an enum-like value set, a status/category hash, or a master-data id/name
8
+ table.
9
+ ---
10
+
11
+ # Constant Definition
12
+
13
+ A skill for defining **application constants**. There is **one rule and no case-by-case judgment**:
14
+ every constant is defined as **two files** — a CommonJS **master** and an ESM **bridge**. Deciding
15
+ per-constant whether a seeder will ever need it is error-prone, so you skip that decision and always
16
+ provide both.
17
+
18
+ > This skill states a **general, project-independent rule** — a refined best practice, not a
19
+ > description of any one project's current code, so it need not match a given repo's existing
20
+ > notation. The directory and value names in it (`constants/`, `app/constants/`, `memberRankConstants`,
21
+ > …) are **illustrative fakes**; use your project's own names. The two-file rule exists because
22
+ > application code is **ESM** (`import` / `export`) while seeders are **CommonJS** (`.cjs`, loaded with
23
+ > `require`), so a shared constant must be readable from both.
24
+
25
+ ## Grand principle: one category per file, always defined as a `.cjs` master + a `.js` bridge
26
+
27
+ A constant file holds **exactly one category** of values (one hash / one set). For every constant you
28
+ create **both** of these, with the **same base name**:
29
+
30
+ | File | Module system | Role |
31
+ | --- | --- | --- |
32
+ | `constants/<name>.cjs` (repo root) | CommonJS | **Master — the single source of truth.** The actual values. |
33
+ | `app/constants/<name>.js` | ESM | **Bridge — a pure re-export** of the `.cjs` via the custom `require`. |
34
+
35
+ - **Why always both (no per-constant decision).** Master data — ids + names that both **seed rows**
36
+ and **app logic** must agree on — is one source of truth read from two module systems: seeders
37
+ `require` the `.cjs` directly; ESM app code reaches it through the bridge. Predicting up front which
38
+ constants a seeder will *eventually* need is tricky and gets it wrong, so define the pair every
39
+ time. The cost is one trivial six-line bridge; the payoff is any consumer can read any constant.
40
+ - **The `.cjs` is the only copy of the values.** The `.js` bridge never restates them — it just
41
+ crosses the module boundary. Two hand-maintained copies drift; keep exactly one.
42
+ - **Why one category per file.** A category maps to a predictable file name. This mirrors the
43
+ "one file, one class" and "vertical over horizontal" principles — a grab-bag `constants.js` forces
44
+ every reader to scan an unrelated pile.
45
+
46
+ **Comment language**: the `js` examples here use English comments. In the constant files you
47
+ generate, keep structural comments in English and write any domain notes in whatever language the
48
+ project uses for domain prose — match the surrounding files.
49
+
50
+ ## 1. Where the two files live
51
+
52
+ | Directory | Module system | Holds |
53
+ | --- | --- | --- |
54
+ | `constants/` (repo root) | CommonJS (`.cjs`) | The **master** — the file seeders `require` directly. |
55
+ | `app/constants/` | ESM (`.js`) | The **bridge** — the file app code imports. |
56
+
57
+ - **App code always imports the bridge**: `import MEMBER_RANK_CONSTANT_HASH from '../constants/memberRankConstants.js'`. App code never reaches into the root `constants/*.cjs` itself.
58
+ - **Seeders always `require` the master**: `require('../../../constants/memberRankConstants.cjs')` — because seeders are written in CommonJS.
59
+
60
+ ## 2. The `.cjs` master (source of truth)
61
+
62
+ `'use strict'` + `module.exports = { ... }`, a single SCREAMING_SNAKE category. This is the file the
63
+ values actually live in.
64
+
65
+ ```js
66
+ // Good: constants/memberRankConstants.cjs — the single source of truth (CommonJS)
67
+ 'use strict'
68
+
69
+ module.exports = {
70
+ MEMBER_RANK: {
71
+ BRONZE: {
72
+ ID: 1,
73
+ NAME: 'Bronze',
74
+ IS_ACTIVE: true,
75
+ DISPLAY_ORDER: 10,
76
+ },
77
+ SILVER: {
78
+ ID: 2,
79
+ NAME: 'Silver',
80
+ IS_ACTIVE: true,
81
+ DISPLAY_ORDER: 20,
82
+ },
83
+ // ...
84
+ },
85
+ }
86
+ ```
87
+
88
+ ## 3. The `.js` bridge
89
+
90
+ Import the custom `require` from the project's globals module, `require` the sibling `.cjs`, and
91
+ `export default` it. **Same base name** as the `.cjs`. This is the whole file — never more:
92
+
93
+ ```js
94
+ // Good: app/constants/memberRankConstants.js — thin ESM bridge over the .cjs master
95
+ import {
96
+ require,
97
+ } from '../globals/_.js'
98
+
99
+ const MEMBER_RANK_CONSTANT_HASH = require('../../constants/memberRankConstants.cjs')
100
+
101
+ export default MEMBER_RANK_CONSTANT_HASH
102
+ ```
103
+
104
+ - **`require` here is the custom one** — `createRequire(import.meta.url)`, re-exported from the
105
+ project's globals module (here `../globals/_.js`). It lets an ESM file load a `.cjs`; there is no
106
+ native `require` in ESM.
107
+ - The bridge is a **pure re-export** — no reshaping, no merging, no extra keys. If you find yourself
108
+ transforming the value in the bridge, that logic belongs elsewhere.
109
+ - The two consumers then read the **one** source:
110
+
111
+ ```js
112
+ // seeder (.cjs) — requires the master directly
113
+ const { MEMBER_RANK } = require('../../../constants/memberRankConstants.cjs')
114
+
115
+ // app (ESM) — imports the bridge
116
+ import MEMBER_RANK_CONSTANT_HASH from '../constants/memberRankConstants.js'
117
+ ```
118
+
119
+ ```js
120
+ // Avoid: stopping at an ESM-only definition (no .cjs master)
121
+ export default { MEMBER_RANK: { /* ... */ } } // a seeder (.cjs) cannot import this; always add the .cjs master
122
+ ```
123
+
124
+ ## 4. Naming
125
+
126
+ - **File**: camelCase, named after the category (`memberRankConstants`, `userPermission`). The `.cjs`
127
+ master and its `.js` bridge share the **same base name**.
128
+ - **Exported constant**: `SCREAMING_SNAKE_CASE` (`MEMBER_RANK_CONSTANT_HASH`, `USER_PERMISSION`). A
129
+ `_HASH` / `_CONSTANTS` suffix is common for a lookup hash but not mandatory — name it for the
130
+ category, not the type, and follow the Renchan naming rules (no forbidden suffixes such as
131
+ `info` / `data` / `list`).
132
+ - **One category per file** — if tempted to add a second, unrelated set, make another pair of files.
133
+
134
+ ## Finishing checklist
135
+
136
+ - [ ] **Both files exist** with the same base name: `constants/<name>.cjs` (master) **and** `app/constants/<name>.js` (bridge).
137
+ - [ ] The values live **only** in the `.cjs`; the `.js` is a pure re-export via the custom `require` (no reshaping, no duplication) ([§3](#3-the-js-bridge)).
138
+ - [ ] The file holds **one category**, exported SCREAMING_SNAKE (default export).
139
+ - [ ] App code imports the `.js`; seeders `require` the `.cjs` ([§1](#1-where-the-two-files-live)).
@@ -0,0 +1,33 @@
1
+ ---
2
+ name: hor-cookie-authentication
3
+ description: "Cookie-based authentication for a renchan backend, per actor: the credential and token models (password hash, access + rotating refresh tokens with reuse detection), the refresh-token HttpOnly cookie, the signIn / signUp / signOut / renewAccessToken resolvers, and the engine's public-operation policy. Use when adding cookie auth to an actor/role. Boundary: models, migrations and seeders follow their own conventions; this replaces the older access-token-only flow."
4
+ metadata:
5
+ author: OpenReachTech
6
+ version: "2026.08.18"
7
+ ---
8
+
9
+ # Cookie Authentication (Backend)
10
+
11
+ Use this skill when adding cookie-based authentication to a renchan backend — storing an actor's credential and tokens, the sign-in / sign-out / renew operations, the refresh-token cookie, and deciding which operations are public.
12
+
13
+ An authenticated actor (a role such as `user`, `customer`, `admin`, or `tenant`) keeps its password as a hash and authenticates with two tokens: a short-lived **access token** the client sends as a header, and a long-lived **refresh token** kept in the DB and handed to the browser as an **HttpOnly cookie**. `signIn` issues both; `renewAccessToken` reads the cookie, rotates the refresh token (detecting reuse of a retired one), and returns a fresh access token; `signOut` revokes the series and clears the cookie. Only `renewAccessToken` and `signOut` authenticate by the cookie — every other operation authenticates by the access-token header.
14
+
15
+ You build this **per actor**, on top of the boilerplate's base classes — it is not shipped in the boilerplate; each app builds it for the actors its spec declares. Design the actor entity and its profile first with [[hor-database-design]] / [[hor-sequelize-model]]; this skill adds the credential, tokens, operations, and cookie to it. It says what the auth cluster contains and how the pieces fit — writing each piece follows its own convention ([[hor-sequelize-model]], [[hor-sequelize-seeder]], [[hor-mutation-resolver]], [[hor-type-interface]]), and the engine is [[hor-graphql-server-engine]].
16
+
17
+ > **This replaces the older access-token-only flow.** In the old flow the access token was the durable credential — stored on the client and sent on every request, with no refresh cookie. Here the access token is short-lived and held only in memory on the client; durability comes from the refresh cookie. Do not mix the two: when this skill applies, there is no long-lived access token. The frontend half is [[hof-cookie-authentication]].
18
+
19
+ > Snippets throughout use `<Actor>` for the role being authenticated — substitute your own (`Member`, `Operator`, `Account`, …). Not every app has a "customer"; the reference implementation these snippets are drawn from happens to use `Customer` and `Admin`.
20
+
21
+ ## Core
22
+
23
+ | Topic | Description | Reference |
24
+ | --- | --- | --- |
25
+ | Environment & config | Step-by-step setup: the `cookie` dependency, the `AUTH_*` env vars + facade, the per-actor cookie-name constant, and the engine's refresh-token cookie config | [environment](references/environment.md) |
26
+ | Token & credential models | Per actor: the password-hash model and the access / refresh token models, with `sessionKey` rotation columns and the backup mixin | [token-models](references/token-models.md) |
27
+ | Migrations | The create-table migrations for the credential and token tables | [migrations](references/migrations.md) |
28
+ | Session clerk | `SessionClerk` — the injected orchestrator over the token tables (`saveSession` / `rotateSession` / `revokeSession` / `findRefreshToken`), returning throwable-save result objects | [session-clerk](references/session-clerk.md) |
29
+ | Refresh-token cookie | The HttpOnly cookie clerk and reading / setting the cookie in the GraphQL context | [cookie-context](references/cookie-context.md) |
30
+ | Auth resolvers | `signIn` / `signUp` / `signOut` / `renewAccessToken` — token issue, rotation, and reuse detection | [resolvers](references/resolvers.md) |
31
+ | Auth-filter policy | `schemasToSkipFiltering` + `generateFilterHandler` — which operations are public (cookie) vs header-guarded | [auth-filter](references/auth-filter.md) |
32
+ | Error codes | The `Unauthenticated` and `RefreshTokenReused` codes and where they are thrown | [error-codes](references/error-codes.md) |
33
+ | Dev-login seeder | A development seeder so `npm run dev` can sign in against real data | [dev-login-seeder](references/dev-login-seeder.md) |
@@ -0,0 +1,55 @@
1
+ # Auth-filter policy
2
+
3
+ The engine decides which operations are public and how the rest authenticate. Set this on the audience's `*GraphqlServerEngine` ([[hor-graphql-server-engine]]).
4
+
5
+ ## Public operations
6
+
7
+ The auth operations skip the header filter. `renewAccessToken` runs when the access token is already expired, so it cannot require the header; `signIn` / `signUp` authenticate by credentials; `signOut` and `renewAccessToken` authenticate by the refresh **cookie** inside the resolver ([cookie-context](./cookie-context.md)).
8
+
9
+ ```js
10
+ get schemasToSkipFiltering () {
11
+ return [
12
+ 'signUp',
13
+ 'signIn',
14
+ 'renewAccessToken',
15
+ 'signOut',
16
+
17
+ 'healthCheck', // fully public
18
+ ]
19
+ }
20
+ ```
21
+
22
+ ## Everything else — the access-token header
23
+
24
+ Every operation not on that list goes through the filter, which authenticates by the `x-renchan-access-token` header. The context resolves the actor from the header token; the filter then checks the visas:
25
+
26
+ ```js
27
+ generateFilterHandler () {
28
+ return async ({ information, context }) => {
29
+ const schema = information.fieldName
30
+
31
+ if (context.canResolve({ schema })) {
32
+ return // a skip-list operation
33
+ }
34
+
35
+ if (!context.hasAuthenticated()) {
36
+ throw this.errorHash.Unauthenticated.create()
37
+ }
38
+
39
+ if (!context.hasAuthorized()) {
40
+ throw this.errorHash.Unauthorized.create()
41
+ }
42
+
43
+ // ... schema-permission check ...
44
+ }
45
+ }
46
+ ```
47
+
48
+ ## Resolving the actor from the header
49
+
50
+ The context turns the header access token into the actor entity, and the visa issuers read that:
51
+
52
+ - `Context.findUser({ accessToken, ... })` — look the access token up and return the actor entity (or `null`).
53
+ - `visaIssuers.hasAuthenticated` — `userEntity !== null`.
54
+
55
+ So the access token is only ever a header credential; the refresh token is only ever a cookie credential, and only for the two skip-listed operations.
@@ -0,0 +1,53 @@
1
+ # Refresh-token cookie
2
+
3
+ The refresh token reaches the browser only as an `HttpOnly` cookie, so no page script can read it. All cookie logic lives in `RefreshTokenExpressCookieClerk` (`server/graphql/contexts/tools/`), not on the context — the context stays a plain DTO. A session resolver builds a clerk from the `context` it receives in `resolve()`; every other resolver never touches it.
4
+
5
+ ```js
6
+ const cookieClerk = RefreshTokenExpressCookieClerk.create({ context })
7
+
8
+ cookieClerk.saveRefreshTokenCookie({ refreshToken }) // sign-in / renew
9
+ cookieClerk.clearRefreshTokenCookie() // sign-out, or not-found
10
+ const presented = cookieClerk.extractRefreshToken() // renew / sign-out only
11
+ ```
12
+
13
+ ## Config comes from the engine
14
+
15
+ Cookie name, lifetime, `secure`, `sameSite`, `httpOnly` are read from the engine config the context carries, so they change in one place — the engine. The path is the engine's GraphQL endpoint, so the cookie stays off every other route.
16
+
17
+ ```js
18
+ get refreshTokenCookieConfig () {
19
+ return this.context.config.refreshTokenCookie
20
+ }
21
+
22
+ get refreshTokenCookiePath () {
23
+ return this.context.config.graphqlEndpoint // cookie scoped to this endpoint only
24
+ }
25
+ ```
26
+
27
+ The engine supplies that config per audience — the cookie name differs per actor ([auth-filter](./auth-filter.md) for where it is set):
28
+
29
+ ```js
30
+ static buildRefreshTokenCookieConfig () {
31
+ return {
32
+ ...this.refreshTokenCookieConfig,
33
+ name: REFRESH_TOKEN_COOKIE.<ACTOR>.NAME,
34
+ }
35
+ }
36
+ ```
37
+
38
+ ## Clearing must match the write
39
+
40
+ Clearing presents the same attributes as the write, minus the lifetime. The write uses the attributes plus `maxAge`; clearing uses the attributes alone. A mismatch leaves the browser holding the original cookie, and the session appears to survive sign-out.
41
+
42
+ ```js
43
+ buildRefreshTokenCookieOptionHash () {
44
+ return {
45
+ ...this.buildRefreshTokenCookieAttributeHash(), // httpOnly, secure, sameSite, path
46
+ maxAge: this.refreshTokenMaxAgeMilliseconds,
47
+ }
48
+ }
49
+ ```
50
+
51
+ ## Reading is not authenticating
52
+
53
+ `extractRefreshToken()` only reads the value. **Only `renewAccessToken` and `signOut` may treat it as a credential** — every other operation authenticates by the access-token header ([auth-filter](./auth-filter.md)).
@@ -0,0 +1,22 @@
1
+ # Dev-login seeder
2
+
3
+ Removing the sample actor domain also removes the seeder that let `npm run dev` sign in. An app that adds cookie auth needs a **development** seeder (the `development/` directory, not `master/`) that inserts at least one actor with a known password, so a developer — and the E2E sign-in flow — can log in. Write it with [[hor-sequelize-seeder]] for the mechanics (directory choice, id-block numbering, `TimestampSeedsSupplier`).
4
+
5
+ For one actor, the seeder inserts the whole credential cluster ([token-models](./token-models.md)):
6
+
7
+ - the entity row (`<actor>s`),
8
+ - its secret row (`<actor>_secrets`) with the sign-in `email`,
9
+ - its password-hash row (`<actor>_password_hashes`).
10
+
11
+ The stored `password_hash` **must be produced by the same enciphering `verifiesPassword` compares against** — insert a pre-hashed digest of a known dev password, not the plaintext, or the login never matches.
12
+
13
+ ```js
14
+ // pseudo — one dev <actor> whose password is a known, obviously-fake dev value
15
+ // password_hash = <digest of 'password-dev-0001' via the project's Encipher>
16
+ // bulkInsert:
17
+ // <actor>s → id, ...
18
+ // <actor>_secrets → <actor>_id, email: '<actor>-dev-0001@example.com'
19
+ // <actor>_password_hashes → <actor>_id, password_hash, saved_at
20
+ ```
21
+
22
+ Keep every seeded value unique and obviously fake (the seeder convention). Do **not** seed tokens — access and refresh tokens are created by signing in ([session-clerk](./session-clerk.md)); the seeder only provides the credential to sign in with.
@@ -0,0 +1,64 @@
1
+ # Environment & config
2
+
3
+ Set these up once per project, before (or alongside) building the auth cluster. Steps:
4
+
5
+ ## 1. Dependency
6
+
7
+ The cookie clerk ([cookie-context](./cookie-context.md)) parses and writes cookies with the `cookie` package. Add it:
8
+
9
+ ```
10
+ npm install cookie
11
+ ```
12
+
13
+ ## 2. Auth env vars
14
+
15
+ Cookie attributes and the refresh-token lifetime are environment-driven, so they change per deploy with no code change. Add to each `.env.*` (left empty in the boilerplate; each app fills them):
16
+
17
+ ```
18
+ AUTH_REFRESH_TOKEN_TTL_DAYS=
19
+ AUTH_COOKIE_SECURE=
20
+ AUTH_COOKIE_SAME_SITE=
21
+ AUTH_COOKIE_PATH=
22
+ AUTH_COOKIE_DOMAIN=
23
+ ```
24
+
25
+ Declare them on the env-facade typedef (`app/globals/env.js` + `env.cjs`) and read them **through the facade** (`env.AUTH_*`), never `process.env` directly. The refresh-token model reads the TTL from it, with a fallback default:
26
+
27
+ ```js
28
+ static get ttlDays () {
29
+ return Number(env.AUTH_REFRESH_TOKEN_TTL_DAYS)
30
+ || DEFAULT_REFRESH_TOKEN_TTL_DAYS // 14
31
+ }
32
+ ```
33
+
34
+ The access-token lifetime is **not** env-driven — it is a fixed short module constant (15 minutes) in the access-token model ([token-models](./token-models.md)).
35
+
36
+ ## 3. Cookie-name constant, per actor
37
+
38
+ Each actor's refresh cookie has its own name so audiences never collide. Define it as a constant ([[hor-constant-definition]]) — a CommonJS master under `constants/` plus its ESM bridge:
39
+
40
+ ```js
41
+ // constants/authConstants.cjs
42
+ REFRESH_TOKEN_COOKIE: {
43
+ <ACTOR>: {
44
+ NAME: '<actor>_refresh_token',
45
+ },
46
+ }
47
+ ```
48
+
49
+ ## 4. Engine cookie config
50
+
51
+ The engine assembles the cookie config the context and clerk read — env-driven attributes plus the per-actor name ([cookie-context](./cookie-context.md), [auth-filter](./auth-filter.md)):
52
+
53
+ ```js
54
+ static buildRefreshTokenCookieConfig () {
55
+ return {
56
+ ...this.refreshTokenCookieConfig, // secure / sameSite / httpOnly / lifetimeDays, from env
57
+ name: REFRESH_TOKEN_COOKIE.<ACTOR>.NAME,
58
+ }
59
+ }
60
+ ```
61
+
62
+ ## 5. TLS
63
+
64
+ `AUTH_COOKIE_SECURE=true` requires HTTPS — over plain HTTP the browser drops a `Secure` cookie, so dev usually runs it off. It pairs with serving the frontend same-origin ([[hof-cookie-authentication]]).