@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,72 @@
1
+ # Dependencies & install hygiene (checks 16–18)
2
+
3
+ Vulnerable packages, lockfile / version-pinning / registry-token hygiene, and reproducible installs.
4
+ Referenced from [SKILL.md](../SKILL.md).
5
+
6
+ First detect the package manager from the committed lockfile: `package-lock.json` → npm,
7
+ `pnpm-lock.yaml` → pnpm, `yarn.lock` → Yarn, `bun.lockb` → Bun. Use that manager's commands below.
8
+
9
+ ## 16. No vulnerable dependencies (advisory audit)
10
+
11
+ ```bash
12
+ # npm:
13
+ npm audit --omit=dev 2>/dev/null || npm audit 2>/dev/null # registry metadata only; no repo upload
14
+ # pnpm: pnpm audit --prod 2>/dev/null
15
+ # yarn: yarn npm audit --environment production 2>/dev/null (Berry) | yarn audit (classic)
16
+ ```
17
+
18
+ - **FINDING (severity = the advisory's):** report each **high / critical** advisory — package,
19
+ installed version, advisory title, and the fixed version. Summarize moderate / low as counts.
20
+ - **Remediation guidance to include per advisory:**
21
+ - If a non-breaking fix exists (patch / minor within the current range), recommend the manager's
22
+ safe upgrade — e.g. `npm audit fix` (no `--force`), which respects semver ranges.
23
+ - If the only fix is a **major** bump or requires `--force`, do **not** recommend applying it
24
+ blindly — call it out as a breaking change needing a compatibility review and testing.
25
+ - If the vulnerable package is transitive, recommend upgrading the parent, or a pin / override
26
+ (`overrides` in npm, `resolutions` in Yarn, `pnpm.overrides`) as a stopgap.
27
+ - **PASS:** no high / critical advisories.
28
+ - If the audit cannot reach the registry (offline / private-registry auth), say so and mark the check
29
+ **BLOCKED** rather than PASS.
30
+
31
+ ## 17. Lockfile committed + version-pinning delay + no committed registry tokens
32
+
33
+ ```bash
34
+ git ls-files | grep -E 'package-lock\.json|pnpm-lock\.yaml|yarn\.lock|bun\.lockb' # a lockfile must be tracked
35
+ cat .npmrc 2>/dev/null; cat .yarnrc.yml 2>/dev/null # registry / install config
36
+ git grep -nE "min-release-age|minimumReleaseAge|_authToken|_auth=|npmAuthToken|NPM_TOKEN=" -- '.npmrc' '.yarnrc*' '*.npmrc'
37
+ ```
38
+
39
+ - **Lockfile committed** — required for reproducible / clean installs (check 18). Missing lockfile →
40
+ **MEDIUM**.
41
+ - **Version-pinning delay** — a cooldown before installing a just-published version weakens a class
42
+ of supply-chain attacks (a malicious release pulled before it is caught). npm supports
43
+ `min-release-age`; pnpm supports `minimumReleaseAge`. **Recommend ≥ 7 days** where the manager
44
+ supports it. Missing / `< 7` → **LOW**.
45
+ - **No committed registry credentials** — a private-registry token (`_authToken`, `_auth`,
46
+ `npmAuthToken`, an inline `NPM_TOKEN=`) committed in `.npmrc` / `.yarnrc.yml` is a **HIGH** finding;
47
+ such tokens must come from env / CI, not the repo.
48
+ - **PASS:** lockfile tracked, cooldown set (where supported), no committed tokens.
49
+
50
+ ## 18. Reproducible installs (clean / locked install, not mutating)
51
+
52
+ CI, container builds, and production installs should use the manager's **clean, lockfile-exact**
53
+ install — which fails if the lockfile is out of sync and does not mutate it — rather than a plain
54
+ install that can update the lockfile and pull unpinned versions.
55
+
56
+ | Manager | Reproducible install | Avoid in CI/build |
57
+ | --- | --- | --- |
58
+ | npm | `npm ci` | `npm install` / `npm i` |
59
+ | pnpm | `pnpm install --frozen-lockfile` | `pnpm install` (writable) |
60
+ | Yarn Berry | `yarn install --immutable` | writable `yarn install` |
61
+ | Yarn classic | `yarn install --frozen-lockfile` | writable `yarn install` |
62
+
63
+ ```bash
64
+ # Where installs happen — CI workflows, scripts, containers, docs:
65
+ git grep -nE "npm (ci|i|install)|pnpm install|yarn install|--frozen-lockfile|--immutable" -- '.github/**' '*.sh' 'package.json' 'Dockerfile*' 'docker-compose*' 'docs/**' 2>/dev/null
66
+ ```
67
+
68
+ - **FINDING (LOW/MEDIUM):** a mutating install used in CI, a container build, or a deploy / setup
69
+ script where the clean/locked variant is appropriate. Local first-time-setup docs using a plain
70
+ install are usually acceptable — note but don't over-flag.
71
+ - **PASS:** CI / build / deploy paths use the clean / locked install, and the lockfile is committed
72
+ (check 17).
@@ -0,0 +1,56 @@
1
+ # Network exposure & logging (checks 4–5)
2
+
3
+ Externally reachable ports / processes, and production logging (redaction / PII). Referenced from
4
+ [SKILL.md](../SKILL.md).
5
+
6
+ ## 4. Exposed ports / bind address / datastore exposure
7
+
8
+ Find every port reachable from outside and confirm each is intended. Cover container definitions, the
9
+ process/service manager, and the server's bind address. The key risk is a **datastore or internal
10
+ service bound to a public interface** (`0.0.0.0`) instead of loopback / a private network.
11
+
12
+ ```bash
13
+ # Container / orchestration definitions:
14
+ find . -maxdepth 3 \( -iname "Dockerfile*" -o -iname "docker-compose*" -o -iname "compose*.y*ml" -o -iname "*.k8s.y*ml" \) -not -path "*/node_modules/*" 2>/dev/null
15
+ grep -rniE "^EXPOSE |ports:|- \"?[0-9]+:[0-9]+|0\.0\.0\.0" Dockerfile* docker-compose* compose*.y*ml 2>/dev/null
16
+ # What the app / services listen on (bind host + port). Also check the process/service manager
17
+ # config the project uses (e.g. a PM2/systemd/procfile-style file), if present:
18
+ git grep -nE "listen\(|\.PORT|host:|hostname|0\.0\.0\.0|127\.0\.0\.1" -- '*.js' '*.ts' '*.cjs' | head
19
+ # Datastore host/port settings in env files (should point at localhost / a private host):
20
+ grep -rniE "REDIS_HOST|REDIS_PORT|DB_HOST|DB_PORT|DATABASE_HOST|DATABASE_PORT|MONGO|AMQP|QUEUE_HOST" .env* 2>/dev/null
21
+ ```
22
+
23
+ - **FINDING (HIGH):** a datastore (DB / Redis / Mongo / message queue) or an internal-only service
24
+ published on `0.0.0.0` / a public interface, or a container `ports:` mapping binding a host port
25
+ with no restriction. Datastores should bind to loopback / a private network only.
26
+ - **FINDING (MEDIUM):** an app port exposed more broadly than needed, or an `EXPOSE` of a debug /
27
+ admin port.
28
+ - **N/A:** no container / manager files (note it) — but still check the server bind address.
29
+ - List every listening port + its bind scope so a human can confirm each is intentional.
30
+
31
+ ## 5. Production logging via a redacting logger; no PII
32
+
33
+ Production logs should flow through the project's **structured / redacting logger** (whatever it
34
+ uses), not raw `console.*`. Wherever logging does **not** go through that logger, confirm **no PII is
35
+ written** — email, password, tokens, phone, full name are forbidden; opaque ids and non-personal
36
+ identifiers are OK.
37
+
38
+ ```bash
39
+ # First identify the logger the project uses (pino, winston, bunyan, a wrapper, etc.):
40
+ git grep -nE "require\(['\"].*log.*['\"]\)|from ['\"].*log.*['\"]|pino|winston|bunyan|createLogger" -- '*.js' '*.ts' '*.cjs' | head
41
+ # Raw console logging on production code paths (exclude tests):
42
+ git grep -nE "console\.(log|info|warn|error|debug)" -- '*.js' '*.ts' '*.cjs' \
43
+ | grep -viE "test|\.spec\.|__tests__|/scripts/|/bin/"
44
+ # PII appearing near a log call:
45
+ git grep -nE "(console|logger|log|error|warn|info)\b[^\"'\`]{0,80}\b(email|password|passwd|accessToken|token|secret|phone|fullName|firstName|lastName|ssn|creditCard)\b" -- '*.js' '*.ts' '*.cjs' \
46
+ | grep -viE "test|__tests__" | head
47
+ ```
48
+
49
+ - **FINDING (MEDIUM):** raw `console.*` on a production code path (bypasses the logger's redaction /
50
+ sinks). Recommend routing through the project logger.
51
+ - **FINDING (HIGH):** any log call (logger or not) that writes **PII** (email, password, token,
52
+ phone, name, and similar). Recommend logging a non-personal id instead.
53
+ - **PASS:** production logging goes through the redacting logger and no PII is logged; logging ids
54
+ only is fine.
55
+ - If the project's framework logs via an injected logger, treat that as compliant — but still scan
56
+ those calls for PII in their payloads.
@@ -0,0 +1,95 @@
1
+ # Secrets (checks 12–15)
2
+
3
+ `.gitignore` coverage of env files, secrets in committed env files, hardcoded secrets in code, and
4
+ plaintext passwords in seed / fixture data. Referenced from [SKILL.md](../SKILL.md). **Mask every
5
+ secret value in the report.**
6
+
7
+ ## 12. Env files covered by `.gitignore` (all variants)
8
+
9
+ A `.gitignore` with a bare `.env` line matches **only** a file named exactly `.env` — it does **not**
10
+ match `.env.development`, `.env.staging`, `.env.production`, `.env.local`, etc. Those variants stay
11
+ trackable and are easily committed with real secrets.
12
+
13
+ ```bash
14
+ ls -a | grep -E '^\.env' # which env files exist on disk
15
+ git check-ignore -v .env .env.* 2>/dev/null # prints the matching rule for each IGNORED file
16
+ git ls-files | grep -E '(^|/)\.env' # env files TRACKED in git (should usually be only a template)
17
+ ```
18
+
19
+ - **Important:** adding a pattern to `.gitignore` does **not** untrack a file that is already
20
+ committed — `.gitignore` only affects untracked files. If an env file is already tracked, it must be
21
+ removed from the index with `git rm --cached <file>` (and the secret rotated). Verify with
22
+ `git ls-files`, not just by reading `.gitignore`.
23
+ - **FINDING (HIGH if the tracked file holds real secrets, else MEDIUM):** any `.env*` file with
24
+ secrets is **tracked** or **not ignored**. Recommend a broad ignore (e.g. `.env*` with a
25
+ `!.env.example` negation), `git rm --cached` for anything already tracked, and — if a secret was
26
+ ever committed — rotating it and purging history.
27
+ - **PASS:** every secret-bearing env file is ignored; only a secret-free template is tracked.
28
+
29
+ ## 13. No secrets in committed env files; secret-free template present
30
+
31
+ Committed env files (a template, or any per-env file that is tracked) must not carry real secret
32
+ **values**. Inspect key names and whether their values are populated — **do not echo the values**;
33
+ grep key names and mask.
34
+
35
+ ```bash
36
+ # For each TRACKED env file (from check 12), list secret-bearing key NAMES only:
37
+ git ls-files | grep -E '(^|/)\.env' | while read f; do echo "== $f =="; \
38
+ grep -oE '^[A-Za-z0-9_]+=' "$f" 2>/dev/null | grep -iE 'PASSWORD|SECRET|TOKEN|API_?KEY|PRIVATE|CREDENTIAL|_KEY|DSN|CONNECTION'; done
39
+ # For each such key, check ONLY whether a value is present, and MASK it, e.g.:
40
+ # grep -E '^SOME_API_KEY=' <file> | sed -E 's/=.{0,4}.*/=****(masked)/'
41
+ ```
42
+
43
+ - **FINDING (HIGH):** a real secret value sits in a committed env file. Recommend replacing it with a
44
+ placeholder, moving the real value to an untracked file / secret manager, and rotating.
45
+ - **Best practice to recommend:** keep exactly one committed, **secret-free** template (e.g.
46
+ `.env.example`) listing every required key with placeholder values, and source **all** real
47
+ credentials for non-local environments from env / a secret manager — never commit them, and do
48
+ not leave per-env files (`.env.staging`, `.env.production`) tracked.
49
+ - **PASS:** values are empty / obvious placeholders (`your-key-here`, `changeme`, `xxxx`), and a
50
+ secret-free template exists.
51
+
52
+ ## 14. No hardcoded secrets in code / config
53
+
54
+ Search source and non-env config for inline credentials and known key shapes.
55
+
56
+ ```bash
57
+ # Inline credential assignments (exclude ones sourced from env / set to null):
58
+ git grep -nE "(password|passwd|secret|api_?key|apikey|access_?token|client_?secret|private_?key)\s*[:=]\s*['\"][^'\"]+['\"]" -- '*.js' '*.ts' '*.cjs' '*.json' '*.yml' '*.yaml' \
59
+ | grep -viE "process\.env|env\.|= *null|: *null|placeholder|example|changeme|xxxx"
60
+ # Known provider key prefixes / private keys, anywhere in tracked files:
61
+ git grep -nE "AIza[0-9A-Za-z_-]{20,}|sk-[A-Za-z0-9]{20,}|ghp_[A-Za-z0-9]{20,}|AKIA[0-9A-Z]{16}|-----BEGIN [A-Z ]*PRIVATE KEY-----"
62
+ ```
63
+
64
+ - **Pay special attention to connection / datastore config files** — per-environment blocks commonly
65
+ carry hardcoded `username` / `password`. Hardcoded credentials in a committed config file are a
66
+ finding **even if they look like placeholders**, because they normalize the pattern; production
67
+ credentials should come from env / a secret manager.
68
+ - **FINDING (HIGH real / MEDIUM placeholder):** a literal credential in tracked code / config.
69
+ Recommend sourcing from env / a secret manager; rotate if real.
70
+ - **PASS:** credentials only ever come from `process.env` / a config facade.
71
+
72
+ ## 15. No plaintext passwords / secrets in seed / fixture data
73
+
74
+ Seed / fixture data that provisions accounts or reference data must not contain plaintext passwords
75
+ or secrets. Distinguish two cases:
76
+
77
+ - **Production / master seed data** (data that ships to real environments) must contain **no**
78
+ credentials at all — production accounts are provisioned out-of-band, not seeded.
79
+ - **Development / test fixtures** may create login accounts, but any password must be **hashed**
80
+ (through the app's real hashing path), never stored as plaintext that reaches the datastore.
81
+
82
+ ```bash
83
+ # Locate seed / fixture directories (names vary: seeders, seeds, fixtures, factories):
84
+ find . -type d \( -iname 'seed*' -o -iname 'fixture*' -o -iname 'factories' \) -not -path '*/node_modules/*' 2>/dev/null
85
+ # Secrets in seed/fixture files (point at the dirs found above):
86
+ git grep -nE "password|passwd|secret|api_?key|token|raw_password" -- '*seed*' '*fixture*' '*factor*' | head
87
+ # Confirm dev fixtures hash rather than store plaintext:
88
+ git grep -nE "hash|bcrypt|argon2|scrypt|pbkdf2|password_hash" -- '*seed*' '*fixture*' | head
89
+ ```
90
+
91
+ - **FINDING (HIGH):** a plaintext `password` / secret literal in production / master seed data.
92
+ Recommend removing it (provision production credentials out-of-band).
93
+ - **FINDING (MEDIUM):** a dev / test fixture stores a plaintext password that reaches the datastore
94
+ unhashed.
95
+ - **PASS:** production seeds hold only non-secret reference data; dev fixtures hash any password.
@@ -0,0 +1,336 @@
1
+ ---
2
+ name: hor-sequelize-migration
3
+ description: >
4
+ Write and edit renchan/Sequelize migration files (sequelize/migrations/*.cjs). Use this skill
5
+ whenever the user asks to create or update a migration — creating a table (createTable), adding
6
+ or removing a column (addColumn / removeColumn), declaring an index or a unique constraint
7
+ (addIndex), naming an index, or deciding whether to add a foreign-key column.
8
+ ---
9
+
10
+ # Sequelize Migration
11
+
12
+ A skill for writing the `sequelize/migrations/*.cjs` files. It defines the **physical schema**
13
+ (tables, columns, indexes); the **logical declarations** layered on top (attributes / association
14
+ / scope / hook) are written by `hor-sequelize-model`. Keep the two in one-to-one correspondence —
15
+ when you add a column in the migration, add the matching attribute in the model (and vice versa).
16
+ The conventions are split across the detail files below.
17
+
18
+ This repo does **not** `sync`. The schema is **built entirely by migrations** (dev = SQLite /
19
+ staging = MySQL / live = MariaDB — the dialects differ). A model's `unique: true` and the like are
20
+ only declarations; **the real object is always created by the migration**.
21
+
22
+ ## Grand principle: a migration is a filled-in template
23
+
24
+ Every migration has the **same skeleton**: `'use strict'` → `require` the factory → `TABLE_NAME` /
25
+ `COLUMN_NAME` constants → `module.exports = { up, down }`, where `up` runs
26
+ `createTable(...factory.ID_BIGINT, <columns>, ...factory.TIMESTAMPS)` → `addIndex`, and `down`
27
+ closes with `dropTable`. This is the same idea as "a model is a filled-in template" in
28
+ `hor-sequelize-model`: keep the skeleton identical so review attention
29
+ goes straight to the **file-specific differences (columns / indexes)**. Do not write it cleverly;
30
+ lean toward the layout of the existing migrations.
31
+
32
+ - **Comments: English for structural conventions, the surrounding language for domain notes.** A
33
+ convention comment such as `// ForeignKey must start with upper case.` is written in English (the
34
+ existing migrations do this, and it matches the model skill). Domain-explanation comments tied to
35
+ a ticket or a spec are often written in Japanese in this repo — match the surrounding files.
36
+
37
+ ## 1. File skeleton and constants (TABLE_NAME / COLUMN_NAME)
38
+
39
+ One migration = one file placed directly under `sequelize/migrations/`. The filename is
40
+ `{timestamp}-{seq}-<operation>-<table>[-<column>].cjs`.
41
+
42
+ - `{timestamp}` is the creation time `YYYYMMDDHHmmss` (14 digits; `date +%Y%m%d%H%M%S`). Files are
43
+ applied in ascending timestamp order — i.e. in creation-time order.
44
+ - `{seq}` is a **6-digit, zero-padded running number** (`000001`, `000002`, ...). It doubles as the
45
+ ordering within the same timestamp and as a human-facing identifier.
46
+ - The operation is `create_table` (create a table) / `alter_table` (add / remove / change columns
47
+ on an existing table).
48
+ - Examples: `20260717135803-000001-create_table-content_generations.cjs` /
49
+ `20260717140512-000002-alter_table-content_generation_jobs-webhook_url.cjs`
50
+ - `.cjs` (CommonJS). Start with `'use strict'` and `require` the factory, then declare `TABLE_NAME`
51
+ and `COLUMN_NAME` (the **single source of truth** for physical column names). `COLUMN_NAME` keys
52
+ are `SCREAMING_SNAKE`, values are the physical names (snake_case). This value is referenced by
53
+ both the column's `field:` and the index name.
54
+ - Older migrations predate this and use the `<8-digit-seq>-create_table-...` form (no timestamp).
55
+ Write new files in the new form above.
56
+
57
+ ```js
58
+ // Good example (the whole shape of a create-table migration)
59
+ 'use strict'
60
+
61
+ const MigrationAttributeFactory = require('@openreachtech/renchan-sequelize/lib/tools/MigrationAttributeFactory.cjs')
62
+
63
+ const TABLE_NAME = 'content_generations'
64
+ const COLUMN_NAME = {
65
+ CONTENT_GENERATION_JOB_ID: 'content_generation_job_id',
66
+ RESULT_JSON: 'result_json',
67
+ MODEL: 'model',
68
+ }
69
+
70
+ // Define an initialism only for a column whose index name would run long (§4).
71
+ const SHORT_COLUMN_NAME = {
72
+ CONTENT_GENERATION_JOB_ID: 'cgji',
73
+ }
74
+
75
+ module.exports = {
76
+ async up (
77
+ queryInterface,
78
+ Sequelize
79
+ ) {
80
+ const factory = MigrationAttributeFactory.create(Sequelize)
81
+
82
+ await queryInterface.createTable(TABLE_NAME, {
83
+ ...factory.ID_BIGINT,
84
+
85
+ // ForeignKey must start with upper case.
86
+ ContentGenerationJobId: {
87
+ type: Sequelize.BIGINT,
88
+ field: COLUMN_NAME.CONTENT_GENERATION_JOB_ID,
89
+ allowNull: false,
90
+ },
91
+ resultJson: {
92
+ type: Sequelize.JSON,
93
+ field: COLUMN_NAME.RESULT_JSON,
94
+ allowNull: true,
95
+ },
96
+ model: {
97
+ type: Sequelize.STRING(64),
98
+ field: COLUMN_NAME.MODEL,
99
+ allowNull: false,
100
+ },
101
+
102
+ ...factory.TIMESTAMPS,
103
+ })
104
+
105
+ // A 1:1 relation is enforced by a UNIQUE index (no DB FK).
106
+ await queryInterface.addIndex(TABLE_NAME, [
107
+ COLUMN_NAME.CONTENT_GENERATION_JOB_ID,
108
+ ], {
109
+ unique: true,
110
+ name: [
111
+ TABLE_NAME,
112
+ SHORT_COLUMN_NAME.CONTENT_GENERATION_JOB_ID,
113
+ 'unique',
114
+ ].join('_'),
115
+ })
116
+
117
+ return Promise.resolve()
118
+ },
119
+
120
+ async down (
121
+ queryInterface,
122
+ Sequelize
123
+ ) {
124
+ return queryInterface.dropTable(TABLE_NAME)
125
+ },
126
+ }
127
+ ```
128
+
129
+ - `up (queryInterface, Sequelize)` / `down (queryInterface, Sequelize)` take those two arguments in
130
+ that order. `up` runs `factory.create(Sequelize)` → `createTable` → `addIndex` →
131
+ `return Promise.resolve()`; `down` is `return queryInterface.dropTable(TABLE_NAME)`.
132
+ - **Each column** is declared with a camelCase key + `field: COLUMN_NAME.X` (the snake physical
133
+ name). **Always** declare `allowNull`, and add `defaultValue` when the column has a default. The
134
+ type is `Sequelize.X` (`BIGINT` / `INTEGER` / `STRING(n)` / `TEXT` (long items: `TEXT('medium')`) /
135
+ `DATE(3)` / `BOOLEAN` / `JSON` / `DECIMAL(p,s)` / `BLOB('long')`). Avoid `ENUM`; use a domain
136
+ constant + `STRING(n)`.
137
+ Datetimes default to `DATE(3)`. Keep `allowNull` / `defaultValue` in sync with the same-named
138
+ column on the model side.
139
+
140
+ For the constants' rationale, the DataTypes table, and file naming, see
141
+ [notation.md](./references/notation.md).
142
+
143
+ ## 2. created_at / updated_at come from the shared preset
144
+
145
+ Do not hand-write `created_at` / `updated_at`; spread `...factory.TIMESTAMPS` at the **end** of the
146
+ `createTable` object. The PK follows the same idea — spread `...factory.ID_BIGINT` (or
147
+ `...factory.ID_INTEGER` for an integer PK) at the **top**. Never hand-write `id`.
148
+
149
+ - `factory.TIMESTAMPS` = `created_at` / `updated_at` (both `DATE(3)`, `allowNull: false`).
150
+ - `factory.TIMESTAMPS_WITH_DELETED_AT` = the above + `deleted_at`. Use it on tables that
151
+ **soft-delete**, paired with `paranoid: true` on the model side (see the default-methods of
152
+ `hor-sequelize-model`).
153
+ - `factory.ID_BIGINT` = the four-piece set `bigint` / `autoIncrement` / `primaryKey` /
154
+ `allowNull:false`.
155
+
156
+ ```js
157
+ // Good example (PK at the top, timestamps at the end — both from the shared preset)
158
+ await queryInterface.createTable(TABLE_NAME, {
159
+ ...factory.ID_BIGINT,
160
+
161
+ // ... business columns ...
162
+
163
+ ...factory.TIMESTAMPS_WITH_DELETED_AT, // also creates deleted_at (model side: paranoid:true)
164
+ })
165
+ ```
166
+
167
+ - **Why**: `created_at` / `updated_at` / `deleted_at` are audit / framework-operational columns, and
168
+ their values are supplied by the model's `timestamps: true`. Routing the column definitions
169
+ through the shared preset keeps millisecond precision (`DATE(3)`), NOT NULL, and the column names
170
+ aligned across every table. The model side does **not** put these in its attributes (see the
171
+ timestamps of `hor-sequelize-model`); only the migration creates the
172
+ columns.
173
+
174
+ ## 3. FK-like columns (no DB foreign-key constraint)
175
+
176
+ Create the **FK-like column** (a column holding another table's id), but **do not add a DB
177
+ foreign-key constraint**.
178
+
179
+ Make the FK-like column's key **start with an uppercase letter** (`ContentGenerationJobId` /
180
+ `CustomerId`) and write `// ForeignKey must start with upper case.` in English immediately above it.
181
+ The type is `BIGINT`.
182
+
183
+ ```js
184
+ // Good example (an FK-like column — column + comment only, no constraint)
185
+ // ForeignKey must start with upper case.
186
+ CustomerId: {
187
+ type: Sequelize.BIGINT,
188
+ field: COLUMN_NAME.CUSTOMER_ID,
189
+ allowNull: false,
190
+ },
191
+ ```
192
+
193
+ - **Why the uppercase start**: the model's association resolves the FK name by the convention
194
+ "`<associated model name>` + `Id`" (see `hor-sequelize-model`). `field:`
195
+ maps it to snake (`..._id`).
196
+
197
+ **Do not write foreign-key constraints.** No `references` on the column, no `onDelete` / `onUpdate`,
198
+ and no `addConstraint` to add an FK constraint (there is not a single FK constraint in the existing
199
+ migrations).
200
+
201
+ - **1:1** is enforced by a **UNIQUE index**, not an FK (§4).
202
+ `// A 1:1 relation is enforced by a UNIQUE index (no DB FK).`
203
+ - **Circular FKs** and optional relations are **column-only and nullable** (`content_sessions` ⇄
204
+ `content_generation_jobs`; `// ForeignKey must start with upper case. (circular FK, column
205
+ only)`).
206
+ - A set of ids you do not want to make FKs is held as a `JSON` array (`optionIdsJson` /
207
+ `// An array of ids without an FK.`).
208
+ - FK columns usually get a (plain) index for lookups (§4). The meaning of the relation is left to
209
+ the model's association.
210
+
211
+ - **Why**: dev = SQLite / staging = MySQL / live = MariaDB differ, and there is no `sync`. A DB FK
212
+ constraint pins insert order and makes cloning into backup (`*_bk`) tables and handling circular
213
+ references awkward. Referential integrity is enforced in the **app layer** (associations,
214
+ transactions, existence checks). See [foreign-keys.md](./references/foreign-keys.md); for the
215
+ column notation see [notation.md](./references/notation.md).
216
+
217
+ ## 4. Index naming
218
+
219
+ Add an index with `queryInterface.addIndex(TABLE_NAME, [columns...], { name, unique? })`. Build the
220
+ `name` by `.join('_')` on an array: **a plain index ends in `'index'`, a UNIQUE one adds
221
+ `unique: true` and ends in `'unique'`**.
222
+
223
+ ```js
224
+ // Good example (a plain index and a UNIQUE one; wrap multiples in Promise.all)
225
+ await Promise.all([
226
+ queryInterface.addIndex(TABLE_NAME, [
227
+ COLUMN_NAME.ACCESS_TOKEN,
228
+ ], {
229
+ unique: true,
230
+ name: [TABLE_NAME, COLUMN_NAME.ACCESS_TOKEN, 'unique'].join('_'),
231
+ }),
232
+ queryInterface.addIndex(TABLE_NAME, [
233
+ COLUMN_NAME.STATUS,
234
+ COLUMN_NAME.EXPIRES_AT,
235
+ ], {
236
+ name: [TABLE_NAME, COLUMN_NAME.STATUS, COLUMN_NAME.EXPIRES_AT, 'index'].join('_'),
237
+ }),
238
+ ])
239
+ ```
240
+
241
+ - One index: `await` it directly. Multiple: wrap them in `Promise.all([...])`.
242
+ - For a composite index, list the columns (`..._status_expires_at_index`) or fold them into a
243
+ meaningful label (`'plan_tier_currency_effective_at'` / `'job_package'`).
244
+ - A UNIQUE named index is the **actual constraint** behind a 1:1 relation or a natural key. A
245
+ model's `unique: true` is only a declaration (see `hor-sequelize-model`).
246
+
247
+ ### Shortening a long index name (over ~50 chars)
248
+
249
+ The DB identifier limit is 64 characters. As a safety margin, shorten once a name would run past
250
+ **~50 characters**. Shorten in the **following priority order**, taking the **initial of each
251
+ word**:
252
+
253
+ 1. **First shorten the column name(s)** (`SHORT_COLUMN_NAME`), keeping the table name in full.
254
+ e.g. `content_generations` + `cgji` (= content_generation_job_id) + `unique`
255
+ → `content_generations_cgji_unique`
256
+ 2. **Only if it is still too long, shorten the table name too** (`SHORT_TABLE_NAME`).
257
+ e.g. `cgrf` (= content_generation_requirement_files) + `cgji` + `index`
258
+ → `cgrf_cgji_index`
259
+
260
+ Initialism examples: `content_generation_job_id`→`cgji`, `chat_room_id`→`cri`,
261
+ `customer_id`→`ci`, `content_generation_requirement_files`→`cgrf`, `content_plan_rates`→`err`.
262
+ Put the abbreviations in `SHORT_COLUMN_NAME` / `SHORT_TABLE_NAME` constants and reference them from
263
+ the `addIndex` `name`. Details and a table of real abbreviations are in
264
+ [indexes.md](./references/indexes.md).
265
+
266
+ ## 5. Adding / removing columns (alter_table)
267
+
268
+ Add a column to an existing table with `addColumn`, and drop the same column symmetrically in
269
+ `down`. The filename is `{timestamp}-{seq}-alter_table-<table>-<column>.cjs`.
270
+
271
+ - **Do not use `removeColumn` to drop a column.** Sequelize's `removeColumn` does not work on
272
+ MariaDB (live), so run raw SQL `ALTER TABLE ... DROP COLUMN` via `queryInterface.sequelize.query`
273
+ (in `up` or `down`; quote identifiers with backticks).
274
+ - `up` / `down` are **symmetric** (drop in `down` what `up` added). Column adds can be grouped with
275
+ `Promise.all`, but drops are run as one raw statement per column, sequentially.
276
+ - Put a `/* ... */` block at the top of the file describing the **intent** (ticket number, spec
277
+ reference, backward-compat notes).
278
+ - When adding a column to a table that already has rows, give it `allowNull: true` or a
279
+ `defaultValue` (do not add a NOT NULL column after the fact).
280
+
281
+ ```js
282
+ // Good example (intent comment + symmetric up/down; the drop uses raw SQL DROP COLUMN)
283
+ /*
284
+ * Add webhook_url to content_generation_jobs (TICKET-1234).
285
+ * When unset, the Worker falls back to integration_clients.default_webhook_url.
286
+ */
287
+
288
+ const TABLE_NAME = 'content_generation_jobs'
289
+ const COLUMN_NAME = 'webhook_url'
290
+
291
+ module.exports = {
292
+ async up (
293
+ queryInterface,
294
+ Sequelize
295
+ ) {
296
+ await queryInterface.addColumn(TABLE_NAME, COLUMN_NAME, {
297
+ type: Sequelize.STRING(500),
298
+ allowNull: true,
299
+ })
300
+ },
301
+
302
+ async down (
303
+ queryInterface,
304
+ Sequelize
305
+ ) {
306
+ // removeColumn does not work on MariaDB, so drop via raw SQL DROP COLUMN.
307
+ await queryInterface.sequelize.query(`
308
+ ALTER TABLE \`${TABLE_NAME}\`
309
+ DROP COLUMN \`${COLUMN_NAME}\`
310
+ `)
311
+ },
312
+ }
313
+ ```
314
+
315
+ Details in [alter-table.md](./references/alter-table.md).
316
+
317
+ ## Applying changes to the local DB
318
+
319
+ After adding or changing a migration, rebuild the local DB to apply it. Use the `package.json`
320
+ scripts:
321
+
322
+ - `npm run r` (= `npm run db:refresh`) — with `NODE_ENV=development`, runs teardown → migrate →
323
+ seed:master → seed:dev in one shot. Use this after changing a migration / seeder.
324
+ - Individually: `npm run db:setup` (migrate only) / `npm run db:teardown` (delete the SQLite files).
325
+
326
+ ## Detail files
327
+
328
+ - [notation.md](./references/notation.md) — file skeleton, `TABLE_NAME`/`COLUMN_NAME`, the PK /
329
+ timestamps spread, a column's `field`/`allowNull`/`defaultValue`, DataTypes, uppercase-start FK
330
+ columns (§1–§3)
331
+ - [foreign-keys.md](./references/foreign-keys.md) — why no DB FK, 1:1 via UNIQUE, circular FKs,
332
+ JSON id arrays, indexing FK columns (§3)
333
+ - [indexes.md](./references/indexes.md) — index naming, UNIQUE, `Promise.all`, composite indexes,
334
+ the shortening algorithm for long names with a table of real examples (§4)
335
+ - [alter-table.md](./references/alter-table.md) — `addColumn`, dropping a column with raw
336
+ `DROP COLUMN` (because `removeColumn` fails on MariaDB), symmetric up/down, intent comment (§5)