@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,368 @@
1
+ # renchan-job Integration (`@openreachtech/mentsu-agent-loop-renchan-job`)
2
+
3
+ Rules for the adapter that runs a core loop (any Runnable) **as a Redis job** inside a renchan-job-bullmq
4
+ Worker and publishes progress. Referenced from `SKILL.md`. The core side is [core.md](./core.md), GraphQL
5
+ launch/subscribe is [graphql-integration.md](./graphql-integration.md), and testing is
6
+ [testing.md](./testing.md).
7
+
8
+ The point of this adapter is to move in-process execution onto Redis job execution **without changing any
9
+ action or loop code**. Queues, the worker pool, Redis, retry, shutdown, and logging are all delegated to
10
+ renchan-job-bullmq; the adapter bridges only **executeJob → `loop.run` / onProgress →
11
+ `job.updateProgress` / lifecycle → publish**.
12
+
13
+ ## Classes and the overall wiring
14
+
15
+ | Class | Extends | What the app overrides |
16
+ | --- | --- | --- |
17
+ | `BaseAgentJobWorker` | renchan-job `BaseJobWorker` | `static get AgentLoopCtor` / `get channel` / `createAgentContext` |
18
+ | `BaseAgentJobDispatcher` | renchan-job `BaseJobDispatcher` | `static get EngineCtor` / `static get ManifestCtor` |
19
+ | `JobAgentRunner` | core `BaseAgentRunner` | (none; use it via `create({ DispatcherCtor })`) |
20
+
21
+ Combine these with the renchan-job-bullmq **Engine / Share / Context / Manifest** (provided by the app).
22
+ If an existing renchan-job setup is present, you can **ride along** on it (just do not reuse a `jobName`
23
+ of an existing job).
24
+
25
+ ## Worker: `BaseAgentJobWorker`
26
+
27
+ The core that runs the loop inside the job. **The app implements only three abstract members**; the
28
+ `executeJob` body, progress bundling, publish, and parallelism control are already implemented by the
29
+ adapter base.
30
+
31
+ | Member | Kind | Description |
32
+ | --- | --- | --- |
33
+ | `static get AgentLoopCtor()` | abstract | The Ctor of the Runnable (Loop / Pipeline / Composite) to run |
34
+ | `get channel()` | abstract | The progress publish channel name (**same as the Subscription resolver's**) |
35
+ | `createAgentContext({ context, parcel })` | abstract | Build the agent-loop context (DI seam) from the renchan-job context |
36
+ | `buildScope({ jobModel })` | hook | The scope that namespaces the channel (default `null`) |
37
+ | `static get AgentTopicCtor()` | hook | Default `AgentTopic`. Override to change the naming rule |
38
+ | `get subscriptionBroker()` | hook | Default `this.engine.subscriptionBroker` |
39
+ | `publishProgress({ topic, event })` | hook | Default `this.subscriptionBroker.publish(topic, event)` |
40
+ | `buildOptionHash()` | implemented | Forwards `concurrency` / `limiter` to the BullMQ Worker (the base only passes `connection`) |
41
+ | `executeJob` / `onJobProgress` / `onJobCompleted` / `onJobFailed` / `onWorkerError` | implemented | Execution and publish |
42
+
43
+ What `executeJob({ body, context, parcel })` does (implemented by the base):
44
+
45
+ ```
46
+ createAgentContext({ context, parcel }) ← assemble the DI seam
47
+ AgentLoopCtor.create({ context: agentContext })
48
+ .run({ input: body, onProgress: buildProgressSink({ parcel }) })
49
+ └ buildProgressSink = event => parcel.jobModel.job.updateProgress(event)
50
+ ```
51
+
52
+ After that, BullMQ's progress/completed/failed events call `onJobProgress` / `onJobCompleted` /
53
+ `onJobFailed`, each publishing to the channel `buildTopic({ scope: buildScope({ jobModel }) })`
54
+ (completed publishes `{ phase: 'done', payload: result }`, failed publishes
55
+ `{ phase: 'error', payload: { message } }`).
56
+
57
+ ```js
58
+ import {
59
+ BaseAgentJobWorker,
60
+ } from '@openreachtech/mentsu-agent-loop-renchan-job'
61
+
62
+ import ResearchPipeline from '../../agentLoops/ResearchPipeline.js'
63
+ import ResearchJobManifest from './ResearchJobManifest.js'
64
+
65
+ /**
66
+ * @extends {BaseAgentJobWorker}
67
+ */
68
+ export default class ResearchJobWorker extends BaseAgentJobWorker {
69
+ /** @override */
70
+ static get ManifestCtor () {
71
+ return ResearchJobManifest
72
+ }
73
+
74
+ /** @override */
75
+ static get AgentLoopCtor () {
76
+ return ResearchPipeline
77
+ }
78
+
79
+ /** @override */
80
+ get channel () {
81
+ return 'researchProgress' // ← must be the same string as the Subscription resolver
82
+ }
83
+
84
+ /**
85
+ * Build the agent-loop context (DI seam) from the renchan-job context.
86
+ *
87
+ * @override
88
+ */
89
+ createAgentContext ({
90
+ context,
91
+ }) {
92
+ return {
93
+ // context exposes delegating getters, so this is a 1-hop read (Demeter).
94
+ aiAgent: context.aiAgent,
95
+ searchClient: context.searchClient,
96
+ }
97
+ }
98
+ }
99
+ ```
100
+
101
+ ### `createAgentContext` must do synchronous "wiring" only
102
+
103
+ `createAgentContext` is the **synchronous wiring** that maps the renchan-job context onto the agent-loop
104
+ context. **Do not do async work (DB loads, external calls) eagerly here.**
105
+
106
+ - **Why synchronous**: the base's `executeJob` calls `createAgentContext(...)` **without `await`**.
107
+ Returning a Promise here corrupts the context. If you need async resource acquisition, put a
108
+ **lazily-resolving getter/method** on `context` and let the **action call it through `context` at run
109
+ time**. This avoids overriding `executeJob` and keeps the iteration logic in the "fetch from context
110
+ when needed" shape.
111
+
112
+ ```js
113
+ // Good: createAgentContext is synchronous wiring; async is passed as a context method the action awaits
114
+ /** @override */
115
+ createAgentContext ({
116
+ context,
117
+ }) {
118
+ return {
119
+ resolveAiAgent: params => context.resolveAiAgent(params), // actual resolution is awaited inside the action
120
+ }
121
+ }
122
+ ```
123
+
124
+ ```js
125
+ // Avoid: making createAgentContext async so it carries a DB load
126
+ // → the base executeJob does not await it, so the context becomes a Promise and breaks. Forces an executeJob override.
127
+ async createAgentContext ({
128
+ context,
129
+ }) { // ← NG
130
+ const record = await context.loadRecord(...) // eager async
131
+
132
+ return {
133
+ record,
134
+ }
135
+ }
136
+ ```
137
+
138
+ ### Keep the progress channel identical on the publish and subscribe sides
139
+
140
+ The publish side (the Worker's `channel` + `buildScope`) and the subscribe side (the Subscription's
141
+ `channel` + `generateChannelQuery`) must use the **same `channel` string and the same scope keys**.
142
+
143
+ - **Why**: `AgentTopic` guarantees the channel **format** matches, but the **`channel` string itself and
144
+ the scope key set** are the app's responsibility to align. A mismatch here is a silent "dropped
145
+ progress" (e.g. the Worker publishes with a `{ jobId }` scope while the Subscription subscribes to
146
+ `{ userId }`).
147
+ - Define the `channel` string in **one place (a shared constant, etc.)** and have the Worker and the
148
+ Subscription reference the same value. Do not duplicate the literal in several places (a source of
149
+ drift).
150
+ - Make the key set returned by `buildScope` match the key set returned by the Subscription's
151
+ `generateChannelQuery` ([graphql-integration.md](./graphql-integration.md)). Do not publish a scope
152
+ that nothing subscribes to.
153
+
154
+ ### Parallelism and rate limiting
155
+
156
+ `concurrency` (loops one Worker runs at once) and `limiter` (per-window ceiling) are forwarded to the
157
+ BullMQ Worker by `buildOptionHash()` (required, because the base renchan-job only passes `connection`).
158
+ The app just writes `concurrency` / `limiter` into the Worker's config seam.
159
+
160
+ ```js
161
+ /** @override */
162
+ static get additionalConfig () {
163
+ return {
164
+ concurrency: 3, // ← number of Agent Loops one Worker runs at once
165
+ limiter: { // ← rate limit (guards an external AI API ceiling; optional)
166
+ max: 10,
167
+ duration: 1000,
168
+ },
169
+ }
170
+ }
171
+ ```
172
+
173
+ - **Why set it**: if the loop hits an AI / external API, unbounded parallelism causes rate overruns and
174
+ memory exhaustion. For loops with external I/O, keep `concurrency` finite and add a `limiter` when
175
+ needed. Scale horizontally (number of Worker processes) on the operations side.
176
+
177
+ ## Dispatcher: `BaseAgentJobDispatcher`
178
+
179
+ The enqueue side. A thin wrapper over renchan-job's dispatcher; the app just points to `EngineCtor` /
180
+ `ManifestCtor`. It provides the `dispatchAgentJob({ input, optionHash })` alias that enqueues the loop
181
+ input as the job body (`dispatchJob` / `createAsync` / `teardown` are inherited from the renchan-job
182
+ base as-is).
183
+
184
+ ```js
185
+ import {
186
+ BaseAgentJobDispatcher,
187
+ } from '@openreachtech/mentsu-agent-loop-renchan-job'
188
+
189
+ import ResearchJobEngine from './ResearchJobEngine.js'
190
+ import ResearchJobManifest from './ResearchJobManifest.js'
191
+
192
+ /**
193
+ * @extends {BaseAgentJobDispatcher}
194
+ */
195
+ export default class ResearchJobDispatcher extends BaseAgentJobDispatcher {
196
+ /** @override */
197
+ static get EngineCtor () {
198
+ return ResearchJobEngine
199
+ }
200
+
201
+ /** @override */
202
+ static get ManifestCtor () {
203
+ return ResearchJobManifest
204
+ }
205
+
206
+ /** @override */
207
+ static get optionHash () {
208
+ return {
209
+ defaultJobOptions: {
210
+ attempts: 2, // ← job-axis retry (distinct from the loop's maxIterations)
211
+ backoff: {
212
+ type: 'exponential',
213
+ delay: 30000,
214
+ },
215
+ },
216
+ }
217
+ }
218
+ }
219
+ ```
220
+
221
+ - To share `EngineCtor` across several jobs, make one **app-wide Dispatcher base** that returns only
222
+ `EngineCtor`, and have each job Dispatcher return only `ManifestCtor` (avoids duplicated wiring).
223
+
224
+ ## Manifest (input schema = loop input)
225
+
226
+ Extend renchan-job-bullmq's `BaseJobManifest` and return `jobName` (the queue name) and `bodySchema`
227
+ (= the loop input). Keep the body **minimal (ids, tokens)**.
228
+
229
+ ```js
230
+ import {
231
+ BaseJobManifest,
232
+ } from '@openreachtech/renchan-job-bullmq'
233
+
234
+ import {
235
+ ScalarHash,
236
+ } from '@openreachtech/mentsu-schema'
237
+
238
+ const {
239
+ Integer,
240
+ } = ScalarHash
241
+
242
+ /**
243
+ * @extends {BaseJobManifest}
244
+ */
245
+ export default class ResearchJobManifest extends BaseJobManifest {
246
+ /** @override */
247
+ static get jobName () {
248
+ return 'research'
249
+ }
250
+
251
+ /** @override */
252
+ static get bodySchema () {
253
+ return {
254
+ jobId: Integer,
255
+ }
256
+ }
257
+ }
258
+ ```
259
+
260
+ ## Engine / Share / Context (renchan-job-bullmq; one set per app)
261
+
262
+ The Redis connection, worker discovery, and shared DI live in the renchan-job-bullmq Engine / Share /
263
+ Context. Reuse existing ones if present; otherwise provide them. **The progress-publish broker is held
264
+ by the Share and exposed by the Engine via a delegating getter.**
265
+
266
+ - **Engine** (`extends BaseJobEngine`): `config` (`workersPath` / `redisConfig`, etc.), `ShareCtor` /
267
+ `ContextCtor`, `createAsync({ subscriptionBroker })`, and the delegating `get subscriptionBroker()`.
268
+ - **Share** (`extends BaseJobShare`; shared across the process): holds `subscriptionBroker` and shared
269
+ clients (AI, DB, etc.).
270
+ - **Context** (`extends BaseJobContext`; per job): exposes the dependencies `createAgentContext` reads
271
+ via **delegating getters** (`get aiAgent()` → `this.share.aiAgent`, etc.; a 1-hop Demeter read).
272
+
273
+ ```js
274
+ // Engine (excerpt): inject subscriptionBroker and expose it via a delegating getter for 1-hop access from the Worker.
275
+ /** @override */
276
+ static async createAsync ({
277
+ config = this.config,
278
+ subscriptionBroker,
279
+ } = {}) {
280
+ const share = await this.ShareCtor.createAsync({
281
+ subscriptionBroker,
282
+ })
283
+
284
+ return this.create({
285
+ config,
286
+ share,
287
+ })
288
+ }
289
+
290
+ /** @override */
291
+ get subscriptionBroker () {
292
+ return this.share.subscriptionBroker
293
+ }
294
+ ```
295
+
296
+ ### If you use renchan's SubscriptionBroker, match `publishProgress` to it
297
+
298
+ The adapter base's `publishProgress` defaults to calling **`this.subscriptionBroker.publish(topic,
299
+ event)` (positional args)**. If the broker you use has a different signature (e.g. renchan's
300
+ `SubscriptionBroker` takes `publish({ channel, message })`), override `publishProgress` to match the
301
+ shape.
302
+
303
+ ```js
304
+ // Good: adapt publishProgress to renchan SubscriptionBroker's signature
305
+ /** @override */
306
+ publishProgress ({
307
+ topic,
308
+ event,
309
+ }) {
310
+ return this.subscriptionBroker.publish({
311
+ channel: topic,
312
+ message: event,
313
+ })
314
+ }
315
+ ```
316
+
317
+ - **Why absorb it here**: the broker's call shape is a transport difference and must not leak into
318
+ actions/loops. Absorbing it in the Worker's `publishProgress` (and, if needed, `get
319
+ subscriptionBroker()`) in one place lets the rest of the progress path (`buildTopic` / `onJobProgress`)
320
+ stay untouched.
321
+
322
+ ## Startup and enqueue
323
+
324
+ - **Daemon**: build the `SubscriptionBroker`, inject it via `Engine.createAsync({ subscriptionBroker })`,
325
+ and start the Workers under `workersPath` with renchan-job's `JobWorkersDaemon`. In enqueue-only
326
+ processes (which do not publish progress), pass no broker and publish becomes a no-op.
327
+ - **Enqueue (request-based)**: enqueue from a GraphQL/REST handler via the Dispatcher. The standard for
328
+ GraphQL launch is `BaseRequestAgentMutationResolver` in
329
+ [graphql-integration.md](./graphql-integration.md). To enqueue directly inside a handler, use
330
+ `dispatcher.dispatchJob({ body })` (or `dispatchAgentJob({ input })`).
331
+
332
+ ## Idempotency (assume BullMQ retries)
333
+
334
+ Setting `optionHash.attempts` means the job may re-run. **Make `executeJob` idempotent.**
335
+
336
+ - **Why**: so a retry re-running from the middle does not cause double writes or duplicated side effects.
337
+ - To carry intermediate results across retries, **do not reimplement `run()` or `executeJob`**; handle
338
+ it via the loop's state and persistence hooks through `context` (saving/reading a checkpoint), so the
339
+ base's iteration and payload merge stay intact (see `BaseAgentPipeline` in [core.md](./core.md)).
340
+
341
+ ## Switching execution mode (in-process ⇔ Redis)
342
+
343
+ Make the caller depend only on `BaseAgentRunner#request` and swap the concrete by `env`, etc. Actions
344
+ and loops do not change at all.
345
+
346
+ ```js
347
+ import {
348
+ InlineAgentRunner,
349
+ } from '@openreachtech/mentsu-agent-loop-core'
350
+
351
+ import {
352
+ JobAgentRunner,
353
+ } from '@openreachtech/mentsu-agent-loop-renchan-job'
354
+
355
+ const runner = env.USE_REDIS
356
+ ? JobAgentRunner.create({ // Redis (async; returns { accepted, jobId })
357
+ DispatcherCtor: ResearchJobDispatcher,
358
+ })
359
+ : InlineAgentRunner.create({ // in-process (sync; returns the final result)
360
+ AgentLoopCtor: ResearchPipeline,
361
+ context: agentContext,
362
+ })
363
+ ```
364
+
365
+ | Mode | `request` returns | Progress | Use |
366
+ | --- | --- | --- | --- |
367
+ | `InlineAgentRunner` (core) | The loop's final result | in-process (`onProgress` immediately) | dev / test / CLI / synchronous work |
368
+ | `JobAgentRunner` (this adapter) | `{ accepted, jobId }` | over a Subscription | production / long-running / horizontal scale |