@crewhaus/tool-lifecycle 0.7.0 → 0.8.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.
- package/LICENSE +201 -0
- package/NOTICE +9 -0
- package/README.md +5 -0
- package/dist/index.js +31 -5
- package/dist/lib/migrate.js +1 -1
- package/dist/lib/result.d.ts +7 -0
- package/dist/lib/result.js +14 -2
- package/dist/lib/tree.js +1 -1
- package/dist/paths.d.ts +21 -2
- package/dist/paths.js +72 -13
- package/package.json +12 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
CrewHaus Factory
|
|
2
|
+
Copyright 2026 Max Meier
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Max Meier
|
|
5
|
+
(operating as StudioMax — https://studiomax.io) and contributors.
|
|
6
|
+
|
|
7
|
+
The CrewHaus name and logo are trademarks of Max Meier. See
|
|
8
|
+
https://github.com/crewhaus/factory/blob/main/TRADEMARK.md for the
|
|
9
|
+
use-of-marks policy.
|
package/README.md
CHANGED
|
@@ -136,6 +136,11 @@ verified.
|
|
|
136
136
|
`wouldWrite`;
|
|
137
137
|
- a destination path that is a symlink leading out of the workspace, with no
|
|
138
138
|
override;
|
|
139
|
+
- a copy that would land in the running harness's own record — its session
|
|
140
|
+
logs, the tool results the runtime saved to a file, or its proof bundles,
|
|
141
|
+
as `to: .crewhaus` would — with no override and in every permission mode
|
|
142
|
+
(0.8.0). The provability gate and `continuity.proof` read that record as
|
|
143
|
+
evidence, so a migration onto it could rewrite the evidence;
|
|
139
144
|
- a `targetVersion` different from the source's, and any `targetVersion` at all
|
|
140
145
|
against a store with no version stamp. See below.
|
|
141
146
|
|
package/dist/index.js
CHANGED
|
@@ -50,6 +50,7 @@ import { existsSync, lstatSync, readdirSync, statSync } from "node:fs";
|
|
|
50
50
|
import * as path from "node:path";
|
|
51
51
|
import { AUDIT_CHAIN_EXCLUSION_REASON, InvalidRetentionDateError, KNOWLEDGE_MARKER_RELPATH, RETENTION_CONFIG_RELPATH, RETIREMENT_LOG_FILENAME, RetentionConfigError, RetireError, SHARED_DIR_DEFAULT, applyPull, applyPush, buildRetirementPlan, formatPlan, fragmentContentHash, harnessOptedIn, openHarnessRecordStore, parseRetentionDate, planPull, planPush, readHarnessGraders, readHarnessMemories, readHarnessPrompts, runRetentionExport, runRetentionPurge, runRetentionSweep, runRetirement, } from "@crewhaus/harness-lifecycle";
|
|
52
52
|
import { buildTool } from "@crewhaus/tool-builder";
|
|
53
|
+
import { protectedRootHolding, protectedRootsOf, protectedWriteRefusal, } from "@crewhaus/tool-safety/fs";
|
|
53
54
|
import { z } from "zod";
|
|
54
55
|
import { NO_PII_PASS_REASON, PULLED_MEMORIES_RELPATH, SHARED_MANIFEST_RELPATH, SHARED_MEMORIES_RELPATH, auditHarnessMemoryFiles, auditSharedFragments, auditSharedMemories, harnessMemoryHashes, landedSharedGraderHashes, makeRedactor, pulledFragmentRelPath, sharedFragmentRelPath, } from "./lib/knowledge";
|
|
55
56
|
import { COVERED_STORE_DIRS, EXPORT_MANIFEST_FILENAME, RECEIPT_FILENAME, RECORD_SHAPE_MIGRATION_UNAVAILABLE, inspectDestination, plannedPaths, readStoreVersion, uncoveredStateEntries, writeReceipt, writtenPaths, } from "./lib/migrate";
|
|
@@ -144,7 +145,12 @@ function probeStateDir(abs) {
|
|
|
144
145
|
// ---------------------------------------------------------------------------
|
|
145
146
|
export const harnessRetire = buildTool({
|
|
146
147
|
name: "HarnessRetire",
|
|
147
|
-
|
|
148
|
+
operativeArgs: [
|
|
149
|
+
{ field: "dir", kind: "path", default: ".", beneath: "all" },
|
|
150
|
+
{ field: "archiveDir", kind: "path", beneath: "all" },
|
|
151
|
+
{ field: "registryDir", kind: "path" },
|
|
152
|
+
],
|
|
153
|
+
description: "Decommission a harness: fingerprint its durable state, archive it, and remove the live copy, writing a retirement log into the archive that records every step and its outcome. Use it when a harness is finished for good; the orchestration, ordering and active-pin refusal are @crewhaus/harness-lifecycle's own. It REFUSES while the spec still has an environment pinned to a registered version, when the registry manifest cannot be read (never treated as 'no pins'), when the archive directory already holds an archived state (it would be replaced), and when the archive directory overlaps the state directory. It does NOT verify the audit chain (run AuditVerify first) or collect a compliance-evidence bundle, and reports both as not performed, so a real run needs acceptUnverified:true. dryRun defaults to true and touches nothing; the preview fingerprints the state so it can warn in advance about files it will not be able to read.",
|
|
148
154
|
inputSchema: z.object({
|
|
149
155
|
spec: z
|
|
150
156
|
.string()
|
|
@@ -406,6 +412,10 @@ export const harnessRetire = buildTool({
|
|
|
406
412
|
// ---------------------------------------------------------------------------
|
|
407
413
|
export const storeMigrate = buildTool({
|
|
408
414
|
name: "StoreMigrate",
|
|
415
|
+
operativeArgs: [
|
|
416
|
+
{ field: "dir", kind: "path", default: ".", beneath: "all" },
|
|
417
|
+
{ field: "to", kind: "path", beneath: "all" },
|
|
418
|
+
],
|
|
409
419
|
description: "Migrate a harness's durable store to another store root: sessions and audit day files copied VERBATIM by @crewhaus/harness-lifecycle's own export path, every copied file then re-hashed at the destination, and a store-migration.json receipt written recording each file with its sha256. The source is not modified (beyond the audit evidence record the export appends), so the rollback is the source itself and re-running is safe: a second run reports what was already there. It REFUSES a destination that overlaps a live store, a destination already holding a receipt from a DIFFERENT source, and an overwrite of existing files unless overwrite is set. It also refuses a version-CHANGING migration outright rather than quietly copying records unchanged: the record transforms live in apps/cli, not here. What the export path does not carry — memories, prompts, graders, the registry, the policy files — is listed under notMigrated instead of being left silent. dryRun defaults to true.",
|
|
410
420
|
inputSchema: z.object({
|
|
411
421
|
to: z.string().min(1).describe("the destination store root, inside the workspace"),
|
|
@@ -428,7 +438,7 @@ export const storeMigrate = buildTool({
|
|
|
428
438
|
}),
|
|
429
439
|
destructive: true,
|
|
430
440
|
requireJustification: true,
|
|
431
|
-
execute: async (input) => {
|
|
441
|
+
execute: async (input, ctx) => {
|
|
432
442
|
const tool = "StoreMigrate";
|
|
433
443
|
const dryRun = input.dryRun ?? true;
|
|
434
444
|
const harness = containExistingDir(tool, input.dir ?? ".");
|
|
@@ -522,6 +532,17 @@ export const storeMigrate = buildTool({
|
|
|
522
532
|
const escaping = containWritePaths(tool, dest.value, written);
|
|
523
533
|
if (escaping !== undefined)
|
|
524
534
|
return refusal(tool, escaping.code, escaping.reason);
|
|
535
|
+
// 0.8.0 — no copy lands in the run's own record (`RuntimeBridge
|
|
536
|
+
// .protectedRoots`): a destination of `.crewhaus` would write
|
|
537
|
+
// `.crewhaus/sessions/<id>.jsonl` over the live session log. Refused in
|
|
538
|
+
// every mode, as StateImport and CopyPath refuse.
|
|
539
|
+
const protectedRoots = protectedRootsOf(ctx);
|
|
540
|
+
if (protectedRoots.length > 0) {
|
|
541
|
+
const into = written.find((rel) => protectedRootHolding(path.join(dest.value.real, rel), protectedRoots) !== undefined);
|
|
542
|
+
if (into !== undefined) {
|
|
543
|
+
return protectedWriteRefusal(tool, `migrating onto ${input.to} (${into})`);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
525
546
|
const destState = inspectDestination(dest.value.real, written);
|
|
526
547
|
if (!destState.ok)
|
|
527
548
|
return refusal(tool, destState.code, destState.reason);
|
|
@@ -624,7 +645,7 @@ export const storeMigrate = buildTool({
|
|
|
624
645
|
const files = [];
|
|
625
646
|
const mismatched = [];
|
|
626
647
|
for (const rel of appliedPaths) {
|
|
627
|
-
const abs = path.join(dest.value.real,
|
|
648
|
+
const abs = path.join(dest.value.real, rel);
|
|
628
649
|
const digest = hashFile(abs);
|
|
629
650
|
if (!digest.ok) {
|
|
630
651
|
mismatched.push({ rel, problem: "missing", detail: digest.reason });
|
|
@@ -708,6 +729,7 @@ export const storeMigrate = buildTool({
|
|
|
708
729
|
// ---------------------------------------------------------------------------
|
|
709
730
|
export const retentionEnforce = buildTool({
|
|
710
731
|
name: "RetentionEnforce",
|
|
732
|
+
operativeArgs: [{ field: "dir", kind: "path", default: ".", beneath: "all" }],
|
|
711
733
|
description: "Run a retention sweep or purge over a harness's stores: delete sessions past the age rule in .crewhaus/retention.json, honouring its pins and audit windows, and append a retention_enforcement record to the audit chain on a real run. The age rule, the pins, the windows and the audit-chain exclusion are all @crewhaus/harness-lifecycle's. dryRun defaults to true and reports the selection by COUNT and by the oldest and newest timestamps in it, so a misconfigured window is visible before it runs rather than after. It REFUSES a selection that covers every session in the store (unless allowDeleteAll says that is the intent), a purge cutoff in the future, a selection over maxDeletions, and — with no override at all — a selection containing a record whose timestamp is at or before 1971, because a timestamp that low is a broken clock rather than data that old and every age rule reads it as infinitely old. Audit data is never deleted. A store that cannot be enumerated is reported as unreadable, never as empty.",
|
|
712
734
|
inputSchema: z.object({
|
|
713
735
|
action: z
|
|
@@ -904,6 +926,10 @@ export const retentionEnforce = buildTool({
|
|
|
904
926
|
// ---------------------------------------------------------------------------
|
|
905
927
|
export const knowledgeSync = buildTool({
|
|
906
928
|
name: "KnowledgeSync",
|
|
929
|
+
operativeArgs: [
|
|
930
|
+
{ field: "dir", kind: "path", default: ".", beneath: "all" },
|
|
931
|
+
{ field: "sharedDir", kind: "path", default: SHARED_DIR_DEFAULT, beneath: "all" },
|
|
932
|
+
],
|
|
907
933
|
description: "Push a harness's memories, grader and prompt fragments into a shared knowledge store, or pull the store's into the harness. Deduped by content hash and redacted by @crewhaus/harness-lifecycle, which drops any artifact still carrying a credential-shaped token after masking. A push requires the harness to have opted in (a .crewhaus/knowledge.json marker) and requires allowWithoutPiiRedaction, because @crewhaus/pii-redactor is not a dependency here: credential masking runs, but names, emails and phone numbers are NOT removed. Shared records that failed validation — a forged content hash, an oversized body — are COUNTED and reported rather than silently skipped, because a poisoned shared store is untrusted input, and a sync that moves more than maxArtifacts is refused. The text of artifacts dropped for still looking secret is never echoed back. dryRun defaults to true.",
|
|
908
934
|
inputSchema: z.object({
|
|
909
935
|
direction: z
|
|
@@ -1097,7 +1123,7 @@ export const knowledgeSync = buildTool({
|
|
|
1097
1123
|
const missing = after.ok
|
|
1098
1124
|
? plan.memories.filter((m) => !landedHashes.has(m.contentHash)).map((m) => m.contentHash)
|
|
1099
1125
|
: [];
|
|
1100
|
-
const fragmentsMissing = plan.fragments.filter((f) => !existsSync(path.join(shared.value.real,
|
|
1126
|
+
const fragmentsMissing = plan.fragments.filter((f) => !existsSync(path.join(shared.value.real, sharedFragmentRelPath(f))));
|
|
1101
1127
|
return json({
|
|
1102
1128
|
...common,
|
|
1103
1129
|
status: "applied",
|
|
@@ -1210,7 +1236,7 @@ export const knowledgeSync = buildTool({
|
|
|
1210
1236
|
// check reported as a total one.
|
|
1211
1237
|
const fragmentsMissing = plan.fragments
|
|
1212
1238
|
.map((f) => pulledFragmentRelPath(f))
|
|
1213
|
-
.filter((rel) => !existsSync(path.join(harnessDir.value.real,
|
|
1239
|
+
.filter((rel) => !existsSync(path.join(harnessDir.value.real, rel)));
|
|
1214
1240
|
return json({
|
|
1215
1241
|
...common,
|
|
1216
1242
|
status: "applied",
|
package/dist/lib/migrate.js
CHANGED
|
@@ -168,7 +168,7 @@ export function inspectDestination(destAbs, plannedRelPaths) {
|
|
|
168
168
|
// DANGLING one as absent — so a link left at a destination path read
|
|
169
169
|
// as "nothing here", `overwrite` was never asked for, and the copy
|
|
170
170
|
// went through the link to whatever it pointed at.
|
|
171
|
-
lstatSync(path.join(destAbs,
|
|
171
|
+
lstatSync(path.join(destAbs, rel));
|
|
172
172
|
conflicts.push(rel);
|
|
173
173
|
}
|
|
174
174
|
catch (err) {
|
package/dist/lib/result.d.ts
CHANGED
|
@@ -24,6 +24,13 @@ export type Loaded<T> = {
|
|
|
24
24
|
export declare function fail(code: FailCode, reason: string): Failure;
|
|
25
25
|
/** The JSON a tool returns when it will not proceed. */
|
|
26
26
|
export declare function refusal(tool: string, code: FailCode, reason: string, extra?: {}): string;
|
|
27
|
+
/**
|
|
28
|
+
* True when `rel` resolves to a path longer than any path can be
|
|
29
|
+
* ({@link MAX_PATH_CHARS}). It cannot be opened or created, so it leads
|
|
30
|
+
* nowhere and is no escape; `contain` refuses it, naming the length and the
|
|
31
|
+
* limit, and anything that touches it meets the filesystem's own refusal.
|
|
32
|
+
*/
|
|
33
|
+
export declare function pastPathLimit(rel: string): boolean;
|
|
27
34
|
/**
|
|
28
35
|
* Resolve a caller-supplied path inside the workspace.
|
|
29
36
|
*
|
package/dist/lib/result.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { statSync } from "node:fs";
|
|
14
14
|
import * as path from "node:path";
|
|
15
|
-
import { ToolPermissionError, resolveSafe } from "../paths";
|
|
15
|
+
import { MAX_PATH_CHARS, ToolPermissionError, resolveSafe } from "../paths";
|
|
16
16
|
/** Compact JSON — the reader is a model, and every byte is context. */
|
|
17
17
|
export const json = (value) => JSON.stringify(value);
|
|
18
18
|
/**
|
|
@@ -39,6 +39,15 @@ export function fail(code, reason) {
|
|
|
39
39
|
export function refusal(tool, code, reason, extra = {}) {
|
|
40
40
|
return json({ tool, status: "refused", code, reason, ...extra });
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* True when `rel` resolves to a path longer than any path can be
|
|
44
|
+
* ({@link MAX_PATH_CHARS}). It cannot be opened or created, so it leads
|
|
45
|
+
* nowhere and is no escape; `contain` refuses it, naming the length and the
|
|
46
|
+
* limit, and anything that touches it meets the filesystem's own refusal.
|
|
47
|
+
*/
|
|
48
|
+
export function pastPathLimit(rel) {
|
|
49
|
+
return path.resolve(process.cwd(), rel).length > MAX_PATH_CHARS;
|
|
50
|
+
}
|
|
42
51
|
/**
|
|
43
52
|
* Resolve a caller-supplied path inside the workspace.
|
|
44
53
|
*
|
|
@@ -59,7 +68,7 @@ export function contain(toolName, rel) {
|
|
|
59
68
|
if (err instanceof ToolPermissionError) {
|
|
60
69
|
// The error's own message carries the path unrendered; rebuild it so a
|
|
61
70
|
// control character in the caller's input cannot reach the output.
|
|
62
|
-
return fail("refused", `tool "${toolName}" rejected path "${renderPath(rel)}": resolved location escapes the workspace root`);
|
|
71
|
+
return fail("refused", `tool "${toolName}" rejected path "${renderPath(rel)}": ${err.reason ?? "resolved location escapes the workspace root"}`);
|
|
63
72
|
}
|
|
64
73
|
throw err;
|
|
65
74
|
}
|
|
@@ -90,6 +99,9 @@ export function containWritePaths(toolName, root, rels) {
|
|
|
90
99
|
const shownRoot = root.rel === "" ? "." : root.rel;
|
|
91
100
|
for (const rel of rels) {
|
|
92
101
|
const under = root.rel === "" ? rel : `${root.rel}/${rel}`;
|
|
102
|
+
// Too long to open or create: it leads nowhere, so it is no escape.
|
|
103
|
+
if (pastPathLimit(under))
|
|
104
|
+
continue;
|
|
93
105
|
if (!contain(toolName, under).ok) {
|
|
94
106
|
return fail("refused", `"${renderPath(rel)}" under "${renderPath(shownRoot)}" resolves outside the workspace root — a symlink on that path leads out, so the write would land on the link's target rather than inside "${renderPath(shownRoot)}". Remove the link and run again; there is no flag for writing through it.`);
|
|
95
107
|
}
|
package/dist/lib/tree.js
CHANGED
|
@@ -168,7 +168,7 @@ export function verifyAgainst(destRoot, manifest, manifestComplete = true) {
|
|
|
168
168
|
const mismatched = [];
|
|
169
169
|
let verified = 0;
|
|
170
170
|
for (const entry of manifest) {
|
|
171
|
-
const abs = path.join(destRoot,
|
|
171
|
+
const abs = path.join(destRoot, entry.rel);
|
|
172
172
|
let stat;
|
|
173
173
|
try {
|
|
174
174
|
stat = lstatSync(abs);
|
package/dist/paths.d.ts
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
import { CrewhausError } from "@crewhaus/errors";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* The longest path this resolves, in UTF-16 code units; a longer one is
|
|
4
|
+
* refused before it is walked. Nothing that long can be opened or created:
|
|
5
|
+
* PATH_MAX is 1,024 bytes on macOS and 4,096 on Linux, Windows stops at
|
|
6
|
+
* 32,767 UTF-16 units, and a path's UTF-8 form is never shorter than its
|
|
7
|
+
* UTF-16 one. The limit is twice that because the part of a path that exists
|
|
8
|
+
* is itself under PATH_MAX, so the part that does not is over PATH_MAX on its
|
|
9
|
+
* own: no spelling of the place reaches it, not even one through a symlink
|
|
10
|
+
* that shortens the part that exists.
|
|
11
|
+
*/
|
|
12
|
+
export declare const MAX_PATH_CHARS: number;
|
|
13
|
+
/**
|
|
14
|
+
* Raised when a caller-supplied path resolves outside the workspace root, or
|
|
15
|
+
* is longer than any path can be.
|
|
16
|
+
*/
|
|
3
17
|
export declare class ToolPermissionError extends CrewhausError {
|
|
4
18
|
readonly name = "ToolPermissionError";
|
|
5
19
|
readonly toolName: string;
|
|
6
20
|
readonly path: string;
|
|
7
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Why, when it is not that the location escapes the workspace root: a path
|
|
23
|
+
* longer than any path can be. A caller that rewords the refusal says this.
|
|
24
|
+
*/
|
|
25
|
+
readonly reason: string | undefined;
|
|
26
|
+
constructor(toolName: string, attemptedPath: string, reason?: string);
|
|
8
27
|
}
|
|
9
28
|
/**
|
|
10
29
|
* A validated path, in both forms the tools need.
|
package/dist/paths.js
CHANGED
|
@@ -11,15 +11,45 @@
|
|
|
11
11
|
import { lstatSync, readlinkSync, realpathSync } from "node:fs";
|
|
12
12
|
import * as path from "node:path";
|
|
13
13
|
import { CrewhausError } from "@crewhaus/errors";
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* The longest path this resolves, in UTF-16 code units; a longer one is
|
|
16
|
+
* refused before it is walked. Nothing that long can be opened or created:
|
|
17
|
+
* PATH_MAX is 1,024 bytes on macOS and 4,096 on Linux, Windows stops at
|
|
18
|
+
* 32,767 UTF-16 units, and a path's UTF-8 form is never shorter than its
|
|
19
|
+
* UTF-16 one. The limit is twice that because the part of a path that exists
|
|
20
|
+
* is itself under PATH_MAX, so the part that does not is over PATH_MAX on its
|
|
21
|
+
* own: no spelling of the place reaches it, not even one through a symlink
|
|
22
|
+
* that shortens the part that exists.
|
|
23
|
+
*/
|
|
24
|
+
export const MAX_PATH_CHARS = 2 * (process.platform === "darwin" ? 1_024 : process.platform === "win32" ? 32_767 : 4_096);
|
|
25
|
+
/** A path as a refusal quotes it: whole, unless it is past {@link MAX_PATH_CHARS}. */
|
|
26
|
+
function shownPath(given) {
|
|
27
|
+
return given.length > MAX_PATH_CHARS ? `${given.slice(0, 64)}…` : given;
|
|
28
|
+
}
|
|
29
|
+
/** Why a path past {@link MAX_PATH_CHARS} is refused: its length and the limit. */
|
|
30
|
+
function tooLong(abs) {
|
|
31
|
+
return `it is ${abs.length} characters once resolved, over the ${MAX_PATH_CHARS}-character limit: no path that long can be opened or created`;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Raised when a caller-supplied path resolves outside the workspace root, or
|
|
35
|
+
* is longer than any path can be.
|
|
36
|
+
*/
|
|
15
37
|
export class ToolPermissionError extends CrewhausError {
|
|
16
38
|
name = "ToolPermissionError";
|
|
17
39
|
toolName;
|
|
18
40
|
path;
|
|
19
|
-
|
|
20
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Why, when it is not that the location escapes the workspace root: a path
|
|
43
|
+
* longer than any path can be. A caller that rewords the refusal says this.
|
|
44
|
+
*/
|
|
45
|
+
reason;
|
|
46
|
+
constructor(toolName, attemptedPath, reason) {
|
|
47
|
+
super("tool", reason === undefined
|
|
48
|
+
? `tool "${toolName}" rejected path "${attemptedPath}": resolved location escapes the workspace root`
|
|
49
|
+
: `tool "${toolName}" rejected path "${shownPath(attemptedPath)}": ${reason}`);
|
|
21
50
|
this.toolName = toolName;
|
|
22
51
|
this.path = attemptedPath;
|
|
52
|
+
this.reason = reason;
|
|
23
53
|
}
|
|
24
54
|
}
|
|
25
55
|
/** The workspace root, resolved. Every path is contained within it. */
|
|
@@ -67,15 +97,7 @@ function nameExists(p) {
|
|
|
67
97
|
function resolveLocation(target, depth = 0) {
|
|
68
98
|
if (depth > 40)
|
|
69
99
|
throw new Error(`symlink chain at "${target}" is too long to resolve`);
|
|
70
|
-
|
|
71
|
-
const tail = [];
|
|
72
|
-
while (!nameExists(probe)) {
|
|
73
|
-
tail.unshift(path.basename(probe));
|
|
74
|
-
const parent = path.dirname(probe);
|
|
75
|
-
if (parent === probe)
|
|
76
|
-
break; // reached the filesystem root
|
|
77
|
-
probe = parent;
|
|
78
|
-
}
|
|
100
|
+
const { probe, tail } = deepestName(target);
|
|
79
101
|
let probeReal;
|
|
80
102
|
try {
|
|
81
103
|
probeReal = realpathSync(probe);
|
|
@@ -97,7 +119,41 @@ function resolveLocation(target, depth = 0) {
|
|
|
97
119
|
const base = realpathSync(path.dirname(probe));
|
|
98
120
|
probeReal = resolveLocation(path.resolve(base, link), depth + 1);
|
|
99
121
|
}
|
|
100
|
-
|
|
122
|
+
// One string, not one argument per name: Bun's `path.join` keeps only
|
|
123
|
+
// (argument count mod 65,536) of its arguments.
|
|
124
|
+
return tail.length > 0 ? path.join(probeReal, tail) : probeReal;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* `target`, an absolute path, split where its deepest prefix that exists as
|
|
128
|
+
* a NAME ends: that prefix, and the names below it, which do not exist, as
|
|
129
|
+
* one string ("" when `target` itself exists). This is `path.dirname` and
|
|
130
|
+
* `path.basename` worked by index on `target` itself: handing them each
|
|
131
|
+
* shorter prefix in turn copied the rest of the path once per missing name,
|
|
132
|
+
* the square of a count the caller picks.
|
|
133
|
+
*/
|
|
134
|
+
function deepestName(target) {
|
|
135
|
+
const top = path.parse(target).root.length;
|
|
136
|
+
const isSep = (i) => target[i] === "/" || target[i] === path.sep;
|
|
137
|
+
let probe = target;
|
|
138
|
+
let start = target.length;
|
|
139
|
+
let stop = -1;
|
|
140
|
+
while (!nameExists(probe)) {
|
|
141
|
+
// `path.basename(probe)` is `target.slice(start, end)`, and
|
|
142
|
+
// `path.dirname(probe)` is `target.slice(0, up)`.
|
|
143
|
+
let end = probe.length;
|
|
144
|
+
while (end > top && isSep(end - 1))
|
|
145
|
+
end--;
|
|
146
|
+
if (stop < 0)
|
|
147
|
+
stop = end;
|
|
148
|
+
start = end;
|
|
149
|
+
while (start > top && !isSep(start - 1))
|
|
150
|
+
start--;
|
|
151
|
+
const up = start > top ? start - 1 : top;
|
|
152
|
+
if (up === probe.length)
|
|
153
|
+
break; // reached the filesystem root
|
|
154
|
+
probe = target.slice(0, up);
|
|
155
|
+
}
|
|
156
|
+
return { probe, tail: stop < 0 ? "" : target.slice(start, stop) };
|
|
101
157
|
}
|
|
102
158
|
export function resolveSafe(toolName, rel, root = workspaceRoot()) {
|
|
103
159
|
const rootResolved = path.resolve(root);
|
|
@@ -107,6 +163,9 @@ export function resolveSafe(toolName, rel, root = workspaceRoot()) {
|
|
|
107
163
|
if (abs !== rootResolved && !abs.startsWith(`${rootResolved}${path.sep}`)) {
|
|
108
164
|
throw new ToolPermissionError(toolName, rel);
|
|
109
165
|
}
|
|
166
|
+
// Longer than any path can be: refused before the walk below reads it.
|
|
167
|
+
if (abs.length > MAX_PATH_CHARS)
|
|
168
|
+
throw new ToolPermissionError(toolName, rel, tooLong(abs));
|
|
110
169
|
let real;
|
|
111
170
|
try {
|
|
112
171
|
const rootReal = realpathSync(rootResolved);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewhaus/tool-lifecycle",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Deterministic harness lifecycle: retirement, store migration, retention enforcement and knowledge sync",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,17 +8,19 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"types": "./dist/index.d.ts",
|
|
11
|
-
"import": "./dist/index.js"
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
12
13
|
}
|
|
13
14
|
},
|
|
14
15
|
"scripts": {
|
|
15
16
|
"test": "bun test src"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@crewhaus/errors": "0.
|
|
19
|
-
"@crewhaus/harness-lifecycle": "0.
|
|
20
|
-
"@crewhaus/tool-builder": "0.
|
|
21
|
-
"@crewhaus/tool-catalog": "0.
|
|
19
|
+
"@crewhaus/errors": "0.8.0",
|
|
20
|
+
"@crewhaus/harness-lifecycle": "0.8.0",
|
|
21
|
+
"@crewhaus/tool-builder": "0.8.0",
|
|
22
|
+
"@crewhaus/tool-catalog": "0.8.0",
|
|
23
|
+
"@crewhaus/tool-safety": "0.8.0",
|
|
22
24
|
"zod": "^3.23.8"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|
|
@@ -42,5 +44,8 @@
|
|
|
42
44
|
"publishConfig": {
|
|
43
45
|
"access": "public"
|
|
44
46
|
},
|
|
45
|
-
"files": ["dist", "README.md", "LICENSE", "NOTICE"]
|
|
47
|
+
"files": ["dist", "README.md", "LICENSE", "NOTICE"],
|
|
48
|
+
"engines": {
|
|
49
|
+
"bun": ">=1.3.14"
|
|
50
|
+
}
|
|
46
51
|
}
|