canopycms 0.0.65 → 0.0.66-int.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -3
- package/dist/ai/generate.d.ts +13 -0
- package/dist/ai/generate.js +9 -3
- package/dist/ai/to-plain-text.js +4 -0
- package/dist/ai/types.d.ts +20 -1
- package/dist/api/admin-branch-health.js +13 -12
- package/dist/api/branch.js +2 -2
- package/dist/branch-health.js +1 -1
- package/dist/branch-metadata-file.d.ts +58 -0
- package/dist/branch-metadata-file.js +65 -0
- package/dist/branch-metadata.d.ts +2 -26
- package/dist/branch-metadata.js +6 -33
- package/dist/branch-registry.js +4 -2
- package/dist/build/generate-ai-content.js +103 -0
- package/dist/cli/cli.js +432 -317
- package/dist/cli/generate-ai-content.js +264 -160
- package/dist/content-id-index.js +22 -0
- package/dist/content-listing.js +3 -0
- package/dist/content-reader.d.ts +25 -1
- package/dist/content-reader.js +15 -0
- package/dist/content-store.d.ts +50 -1
- package/dist/content-store.js +102 -4
- package/dist/context.d.ts +36 -4
- package/dist/context.js +15 -4
- package/dist/editor/admin/SystemHealthPanel.js +2 -2
- package/dist/entry-schema.d.ts +22 -0
- package/dist/git-manager.d.ts +9 -8
- package/dist/git-manager.js +35 -9
- package/dist/github-service.d.ts +1 -1
- package/dist/github-service.js +1 -1
- package/dist/paths/branch-name.d.ts +1 -1
- package/dist/paths/branch-name.js +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +1 -1
- package/dist/schema/meta-loader.js +1 -1
- package/dist/services.d.ts +22 -0
- package/dist/types.d.ts +1 -1
- package/dist/url-exclusivity-fixtures.d.ts +76 -0
- package/dist/url-exclusivity-fixtures.js +119 -0
- package/dist/url-path-resolver.js +8 -4
- package/dist/utils/content-write-lock.d.ts +2 -1
- package/dist/utils/content-write-lock.js +2 -1
- package/dist/utils/error.d.ts +17 -0
- package/dist/utils/error.js +17 -0
- package/dist/utils/git.d.ts +1 -1
- package/dist/utils/git.js +1 -1
- package/dist/utils/occ-json-write.js +1 -1
- package/dist/worker/cms-worker.d.ts +22 -288
- package/dist/worker/cms-worker.js +118 -1995
- package/dist/worker/git-sync.d.ts +166 -0
- package/dist/worker/git-sync.js +554 -0
- package/dist/worker/history-rewrite.d.ts +129 -0
- package/dist/worker/history-rewrite.js +216 -0
- package/dist/worker/rebase.d.ts +171 -0
- package/dist/worker/rebase.js +859 -0
- package/dist/worker/task-runner.d.ts +93 -0
- package/dist/worker/task-runner.js +529 -0
- package/dist/worker/worker-context.d.ts +133 -0
- package/dist/worker/worker-context.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { Octokit } from '@octokit/rest';
|
|
2
|
+
import type { SanitizedBranchName } from '../paths/types.js';
|
|
3
|
+
import type { Task, TaskQueueLogger } from './task-queue.js';
|
|
4
|
+
import type { WorkerStatusReport } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* The slice of {@link import('./cms-worker.js').CmsWorker} that its extracted
|
|
7
|
+
* clusters (task-runner.ts, git-sync.ts, rebase.ts, history-rewrite.ts) are
|
|
8
|
+
* allowed to reach.
|
|
9
|
+
*
|
|
10
|
+
* `CmsWorker` used to be 2,949 lines holding four disjoint call trees under one
|
|
11
|
+
* entry point, sharing six helper methods and a 16-field config. The clusters
|
|
12
|
+
* now live in their own modules as free functions taking this context, and the
|
|
13
|
+
* class keeps thin delegating methods. This interface is what makes the sharing
|
|
14
|
+
* explicit: it is the ONLY channel between the class and the extracted code, so
|
|
15
|
+
* "what does the rebase loop actually need from the worker?" has an answer you
|
|
16
|
+
* can read, rather than being whatever `this.` happens to resolve to.
|
|
17
|
+
*
|
|
18
|
+
* Each module narrows it further with a `Pick<WorkerContext, ...>` alias, so a
|
|
19
|
+
* function's signature names its real dependency set rather than the union.
|
|
20
|
+
*
|
|
21
|
+
* ## Why the second group are FUNCTIONS, not fields
|
|
22
|
+
*
|
|
23
|
+
* Everything below the divider is resolved by CALLING back onto the live
|
|
24
|
+
* `CmsWorker` instance, never snapshotted into the context object. That is
|
|
25
|
+
* load-bearing, not stylistic. The worker's eight test files drive it by
|
|
26
|
+
* reaching through the instance:
|
|
27
|
+
*
|
|
28
|
+
* - `cms-worker.test.ts` and `cms-worker-sync-reconcile.test.ts` REPLACE
|
|
29
|
+
* `buildGitHubUrl` on the instance to redirect pushes at a local fixture repo
|
|
30
|
+
* instead of github.com;
|
|
31
|
+
* - `cms-worker-merge-poll.test.ts` and `cms-worker.test.ts` ASSIGN a mock over
|
|
32
|
+
* the `octokit` field;
|
|
33
|
+
* - `cms-worker.test.ts` REPLACES `executeTask` (to drive the retry/timeout
|
|
34
|
+
* paths without real work) and `pushBranchToGitHub` (to exercise the PR
|
|
35
|
+
* actions with no git remote), then asserts on the replacement;
|
|
36
|
+
* - several set `running` directly instead of calling `start()`;
|
|
37
|
+
* - `cms-worker-content-lock.test.ts` SUBCLASSES `CmsWorker` to override the two
|
|
38
|
+
* `afterConflictDetectedForTesting`/`afterRebaseCompletedForTesting` hooks.
|
|
39
|
+
*
|
|
40
|
+
* A context built with `octokit: this.octokit` would capture the real Octokit
|
|
41
|
+
* before the test ever installs its mock, and a captured `buildGitHubUrl` string
|
|
42
|
+
* would send a test's push to github.com for real. Writing them as functions
|
|
43
|
+
* (`ctx.octokit()`, `ctx.buildGitHubUrl()`) makes the late binding visible at
|
|
44
|
+
* every call site, which a getter would hide. `CmsWorker.ctx()` builds a fresh
|
|
45
|
+
* context per call for the same reason — there is no long-lived object for a
|
|
46
|
+
* stale reference to hide in.
|
|
47
|
+
*/
|
|
48
|
+
export interface WorkerContext {
|
|
49
|
+
/** GitHub owner, e.g. 'safeinsights'. */
|
|
50
|
+
readonly githubOwner: string;
|
|
51
|
+
/** GitHub repo name. */
|
|
52
|
+
readonly githubRepo: string;
|
|
53
|
+
/**
|
|
54
|
+
* The base branch's RAW git ref name. Git refs (fetch/rev-list/merge against
|
|
55
|
+
* it) must use this; filesystem paths must use `sanitizedBaseBranch`.
|
|
56
|
+
*/
|
|
57
|
+
readonly baseBranch: string;
|
|
58
|
+
/**
|
|
59
|
+
* The base branch's workspace DIRECTORY name. Computed once so every
|
|
60
|
+
* filesystem call site agrees instead of re-deriving it and risking drift.
|
|
61
|
+
*/
|
|
62
|
+
readonly sanitizedBaseBranch: SanitizedBranchName;
|
|
63
|
+
/** `{workspacePath}/.tasks` — the task queue and worker-status.json. */
|
|
64
|
+
readonly taskDir: string;
|
|
65
|
+
/** `{workspacePath}/remote.git` — the shared bare repo. */
|
|
66
|
+
readonly remoteGitPath: string;
|
|
67
|
+
/** `{workspacePath}/content-branches` — the branch workspace root. */
|
|
68
|
+
readonly contentBranchesPath: string;
|
|
69
|
+
/** Content root directory name relative to repo root (default: 'content'). */
|
|
70
|
+
readonly contentRoot: string;
|
|
71
|
+
/** Per-task timeout in ms; also simple-git's inactivity block timeout. */
|
|
72
|
+
readonly taskTimeoutMs: number;
|
|
73
|
+
/** Max tasks to process per `processTaskQueue` cycle. */
|
|
74
|
+
readonly maxTasksPerCycle: number;
|
|
75
|
+
/** Default max retries for a failed task that does not carry its own. */
|
|
76
|
+
readonly maxRetries: number;
|
|
77
|
+
/** Task-queue debug logger. */
|
|
78
|
+
readonly log: TaskQueueLogger;
|
|
79
|
+
/** The worker's Octokit client, read at call time (tests replace it). */
|
|
80
|
+
octokit(): Octokit;
|
|
81
|
+
/**
|
|
82
|
+
* The tokenized GitHub clone URL, read at call time (tests replace this
|
|
83
|
+
* method to point at a local fixture repo).
|
|
84
|
+
*
|
|
85
|
+
* Anything derived from it can embed the bot token, so a message that reaches
|
|
86
|
+
* worker-status.json, branch.json or a task file must go through
|
|
87
|
+
* `redactCredentials` first.
|
|
88
|
+
*/
|
|
89
|
+
buildGitHubUrl(): string;
|
|
90
|
+
/**
|
|
91
|
+
* Workspace directory for a branch named by its GIT REF name — the form task
|
|
92
|
+
* payloads carry. Sanitizes; `feature/x` lives in `feature-x`.
|
|
93
|
+
*/
|
|
94
|
+
branchWorkspacePath(branchRefName: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* Run one task, read at call time.
|
|
97
|
+
*
|
|
98
|
+
* Routed back through the instance even though the implementation lives in
|
|
99
|
+
* task-runner.ts beside its only caller, because cms-worker.test.ts REPLACES
|
|
100
|
+
* this method on the instance to drive the retry and timeout paths without
|
|
101
|
+
* doing real work. `executeTaskWithTimeout` must therefore call
|
|
102
|
+
* `ctx.executeTask(...)`, never the module-level function directly -- doing
|
|
103
|
+
* the latter silently bypasses the stub and the tests go red.
|
|
104
|
+
*/
|
|
105
|
+
executeTask(task: Task, signal: AbortSignal): Promise<Record<string, unknown>>;
|
|
106
|
+
/**
|
|
107
|
+
* Push a branch from remote.git to GitHub, read at call time.
|
|
108
|
+
*
|
|
109
|
+
* Routed through the instance for the same reason as `executeTask`:
|
|
110
|
+
* cms-worker.test.ts replaces it with a spy so the PR actions can be
|
|
111
|
+
* exercised with no git remote, and then asserts the spy was NOT called on
|
|
112
|
+
* the base-branch-refusal path.
|
|
113
|
+
*/
|
|
114
|
+
pushBranchToGitHub(branch: string): Promise<void>;
|
|
115
|
+
/** Whether the worker is still running; both poll loops bail when false. */
|
|
116
|
+
isRunning(): boolean;
|
|
117
|
+
/** The worker's self-reported status object, lazily initialized. */
|
|
118
|
+
ensureStatusReport(): WorkerStatusReport;
|
|
119
|
+
/** This deployment's own settings branch name. Throws on an invalid name. */
|
|
120
|
+
ensureSettingsBranch(): string;
|
|
121
|
+
/**
|
|
122
|
+
* Test hook: fires when the rebase has reported conflicted files and is about
|
|
123
|
+
* to `checkout --theirs` them. No-op in production; overridden by a subclass
|
|
124
|
+
* in cms-worker-content-lock.test.ts.
|
|
125
|
+
*/
|
|
126
|
+
afterConflictDetectedForTesting(): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Test hook: fires after the rebase round loop completes, deliberately
|
|
129
|
+
* OUTSIDE its try/catch so a throwing hook can never be misread as a rebase
|
|
130
|
+
* error. No-op in production.
|
|
131
|
+
*/
|
|
132
|
+
afterRebaseCompletedForTesting(): Promise<void>;
|
|
133
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"//": "@codemirror/language, @lezer/highlight: workaround — @mdxeditor/editor uses cm6-theme-basic-light which peer-requires these but mdxeditor doesn't declare them as dependencies",
|
|
3
3
|
"name": "canopycms",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.66-int.82",
|
|
5
5
|
"description": "CanopyCMS core package: schema-driven content, branch-aware editing, and editor UI for Next.js.",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|