@savvy-web/silk-core 0.1.3 → 0.2.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/index.d.ts CHANGED
@@ -896,6 +896,82 @@ export declare function publishesBuiltLinkDirectory(manifest: unknown): boolean;
896
896
  */
897
897
  export declare function savvyInstallBlock(hook: SavvyInstallHook): Section;
898
898
  //#endregion
899
+ //#region src/schemas/SavvyOkfSection.d.ts
900
+ /**
901
+ * Section identity for the OKF bundle sync block.
902
+ *
903
+ * `toolName` is `"savvy-okf"`; pair with {@link savvyOkfSync}.
904
+ *
905
+ * @remarks
906
+ * The key is spelled uppercase because the kit renders it verbatim into the
907
+ * markers (`# --- BEGIN SAVVY-OKF MANAGED SECTION ---`), matching the casing of
908
+ * every other Silk Suite section already written into consumer hook files.
909
+ *
910
+ * @since 0.2.0
911
+ * @public
912
+ */
913
+ export declare const SavvyOkfSection: SectionId;
914
+ /**
915
+ * OKF bundle sync shared across Silk Suite `pre-commit` hook files.
916
+ *
917
+ * @remarks
918
+ * Runs `okfit sync --staged` over the repo's `okf/` bundle so the `generated.at`
919
+ * stamp on every staged concept lands in the SAME commit as the edit that moved
920
+ * it, rather than surfacing as drift on the next validate.
921
+ *
922
+ * **Precondition:** a `SavvyBaseSection` block must precede this one in the
923
+ * hook file. Unlike `savvyToolchainCheck` and `savvyInstallDeps`, this block is
924
+ * NOT self-contained — it reads `ROOT`, `in_ci` and `pm_exec` from the
925
+ * preamble, because its only home is `pre-commit`, which always carries it.
926
+ *
927
+ * Three guards keep it a silent no-op where it has nothing to do:
928
+ *
929
+ * - CI, where the checkout is never committed from and the bundle is validated
930
+ * by its own job.
931
+ * - No `okf/` directory at the repo root — the repo carries no bundle.
932
+ * - No local `okfit` binary. The probe is `-x "$ROOT/node_modules/.bin/okfit"`
933
+ * rather than `command -v okfit` because the tool runs through `pm_exec`,
934
+ * which resolves the LOCAL devDependency and never a global install; a
935
+ * global-only `okfit` would pass `command -v` and then fail under `pm_exec`.
936
+ * `node_modules/.bin` is common to all four supported package managers, so
937
+ * one probe covers them.
938
+ *
939
+ * The positional argument is `"$ROOT"`, the PROJECT root `okfit` starts config
940
+ * discovery from — not the bundle directory. Passing `"$ROOT/okf"` makes the
941
+ * tool look for the bundle at `okf/okf` and exit 3.
942
+ *
943
+ * Once it runs, a non-zero exit FAILS the commit (`|| exit 1`): a bundle the
944
+ * tool cannot sync is a broken bundle, and letting the commit through would
945
+ * land it silently. `--staged` re-adds whatever it writes, so the hook needs no
946
+ * `git add` of its own.
947
+ *
948
+ * The default `--staged` modes are `generated` and `index`, so the derived
949
+ * `index.md` files are re-stamped in the same commit too — but only while the
950
+ * bundle is clean apart from what is staged. Index mode reads concepts from
951
+ * DISK, not from the git index, and `--staged` re-adds what it writes, so an
952
+ * untracked or partially staged concept would otherwise let an unrelated
953
+ * commit land an `index.md` entry linking a file that commit does not
954
+ * contain. When `git status --porcelain -- okf` shows any unstaged or
955
+ * untracked entry (second status column non-blank), the hook narrows to
956
+ * `--only generated` for that commit and the index catches up on the next
957
+ * clean one.
958
+ *
959
+ * @returns The sync shell, with no surrounding markers or trailing newline.
960
+ *
961
+ * @since 0.2.0
962
+ * @public
963
+ */
964
+ export declare function savvyOkfSync(): string;
965
+ /**
966
+ * Build the OKF bundle sync block for `pre-commit`.
967
+ *
968
+ * @returns A shell `Section` (`commentStyle: hash`) keyed `SAVVY-OKF`.
969
+ *
970
+ * @since 0.2.0
971
+ * @public
972
+ */
973
+ export declare function savvyOkfBlock(): Section;
974
+ //#endregion
899
975
  //#region src/schemas/SavvySections.d.ts
900
976
  /**
901
977
  * Section identity for the shared package-manager preamble.
package/index.js CHANGED
@@ -7,9 +7,10 @@ import { pr_body_exports } from "./pr-body/index.js";
7
7
  import { BiomeSyncOptions, BiomeSyncResult } from "./schemas/BiomeConfig.js";
8
8
  import { ConfigDiscoveryOptions, ConfigLocation, ConfigSource } from "./schemas/ConfigDiscoverySchemas.js";
9
9
  import { LIFECYCLE_SCRIPTS_CONFIG_KEY, SavvyInstallSection, publishesBuiltLinkDirectory, savvyInstallBlock, savvyInstallDeps } from "./schemas/SavvyInstallSection.js";
10
+ import { SavvyOkfSection, savvyOkfBlock, savvyOkfSync } from "./schemas/SavvyOkfSection.js";
10
11
  import { SavvyBaseSection, SavvyHooksSection, SavvyToolchainSection, savvyBasePreamble, savvyHooksHygiene, savvyToolSection, savvyToolchainCheck } from "./schemas/SavvySections.js";
11
12
  import { ChangesetConfigFile, SilkChangesetConfigFile } from "./schemas/VersioningSchemas.js";
12
13
  import { trimTrailingSlashes } from "./utils/TrailingSlash.js";
13
14
  import { AnalyzedWorkspace, SilkPublishConfig, WorkspaceAnalysis } from "./schemas/WorkspaceAnalysisSchemas.js";
14
15
 
15
- export { AnalyzedWorkspace, BiomeSyncError, BiomeSyncOptions, BiomeSyncResult, ChangesetConfigError, ChangesetConfigFile, ConfigDiscoveryOptions, ConfigLocation, ConfigNotFoundError, ConfigSource, LIFECYCLE_SCRIPTS_CONFIG_KEY, pr_body_exports as PrBody, PublishTargetBindingError, SavvyBaseSection, SavvyHooksSection, SavvyInstallSection, SavvyToolchainSection, SilkChangesetConfigFile, SilkPublishConfig, WorkspaceAnalysis, WorkspaceAnalysisError, publishesBuiltLinkDirectory, savvyBasePreamble, savvyHooksHygiene, savvyInstallBlock, savvyInstallDeps, savvyToolSection, savvyToolchainCheck, trimTrailingSlashes };
16
+ export { AnalyzedWorkspace, BiomeSyncError, BiomeSyncOptions, BiomeSyncResult, ChangesetConfigError, ChangesetConfigFile, ConfigDiscoveryOptions, ConfigLocation, ConfigNotFoundError, ConfigSource, LIFECYCLE_SCRIPTS_CONFIG_KEY, pr_body_exports as PrBody, PublishTargetBindingError, SavvyBaseSection, SavvyHooksSection, SavvyInstallSection, SavvyOkfSection, SavvyToolchainSection, SilkChangesetConfigFile, SilkPublishConfig, WorkspaceAnalysis, WorkspaceAnalysisError, publishesBuiltLinkDirectory, savvyBasePreamble, savvyHooksHygiene, savvyInstallBlock, savvyInstallDeps, savvyOkfBlock, savvyOkfSync, savvyToolSection, savvyToolchainCheck, trimTrailingSlashes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@savvy-web/silk-core",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "description": "Platform-free domain core of the Silk Suite: schemas, tagged errors, and the PR-body contract",
6
6
  "homepage": "https://github.com/savvy-web/systems/tree/main/packages/silk-core",
@@ -0,0 +1,95 @@
1
+ import { CommentStyle, SectionId } from "@effected/templates";
2
+
3
+ //#region src/schemas/SavvyOkfSection.ts
4
+ /**
5
+ * Section identity for the OKF bundle sync block.
6
+ *
7
+ * `toolName` is `"savvy-okf"`; pair with {@link savvyOkfSync}.
8
+ *
9
+ * @remarks
10
+ * The key is spelled uppercase because the kit renders it verbatim into the
11
+ * markers (`# --- BEGIN SAVVY-OKF MANAGED SECTION ---`), matching the casing of
12
+ * every other Silk Suite section already written into consumer hook files.
13
+ *
14
+ * @since 0.2.0
15
+ * @public
16
+ */
17
+ const SavvyOkfSection = SectionId.make({
18
+ key: "SAVVY-OKF",
19
+ commentStyle: CommentStyle.hash
20
+ });
21
+ /**
22
+ * OKF bundle sync shared across Silk Suite `pre-commit` hook files.
23
+ *
24
+ * @remarks
25
+ * Runs `okfit sync --staged` over the repo's `okf/` bundle so the `generated.at`
26
+ * stamp on every staged concept lands in the SAME commit as the edit that moved
27
+ * it, rather than surfacing as drift on the next validate.
28
+ *
29
+ * **Precondition:** a `SavvyBaseSection` block must precede this one in the
30
+ * hook file. Unlike `savvyToolchainCheck` and `savvyInstallDeps`, this block is
31
+ * NOT self-contained — it reads `ROOT`, `in_ci` and `pm_exec` from the
32
+ * preamble, because its only home is `pre-commit`, which always carries it.
33
+ *
34
+ * Three guards keep it a silent no-op where it has nothing to do:
35
+ *
36
+ * - CI, where the checkout is never committed from and the bundle is validated
37
+ * by its own job.
38
+ * - No `okf/` directory at the repo root — the repo carries no bundle.
39
+ * - No local `okfit` binary. The probe is `-x "$ROOT/node_modules/.bin/okfit"`
40
+ * rather than `command -v okfit` because the tool runs through `pm_exec`,
41
+ * which resolves the LOCAL devDependency and never a global install; a
42
+ * global-only `okfit` would pass `command -v` and then fail under `pm_exec`.
43
+ * `node_modules/.bin` is common to all four supported package managers, so
44
+ * one probe covers them.
45
+ *
46
+ * The positional argument is `"$ROOT"`, the PROJECT root `okfit` starts config
47
+ * discovery from — not the bundle directory. Passing `"$ROOT/okf"` makes the
48
+ * tool look for the bundle at `okf/okf` and exit 3.
49
+ *
50
+ * Once it runs, a non-zero exit FAILS the commit (`|| exit 1`): a bundle the
51
+ * tool cannot sync is a broken bundle, and letting the commit through would
52
+ * land it silently. `--staged` re-adds whatever it writes, so the hook needs no
53
+ * `git add` of its own.
54
+ *
55
+ * The default `--staged` modes are `generated` and `index`, so the derived
56
+ * `index.md` files are re-stamped in the same commit too — but only while the
57
+ * bundle is clean apart from what is staged. Index mode reads concepts from
58
+ * DISK, not from the git index, and `--staged` re-adds what it writes, so an
59
+ * untracked or partially staged concept would otherwise let an unrelated
60
+ * commit land an `index.md` entry linking a file that commit does not
61
+ * contain. When `git status --porcelain -- okf` shows any unstaged or
62
+ * untracked entry (second status column non-blank), the hook narrows to
63
+ * `--only generated` for that commit and the index catches up on the next
64
+ * clean one.
65
+ *
66
+ * @returns The sync shell, with no surrounding markers or trailing newline.
67
+ *
68
+ * @since 0.2.0
69
+ * @public
70
+ */
71
+ function savvyOkfSync() {
72
+ return `if ! in_ci && [ -d "$ROOT/okf" ] && [ -x "$ROOT/node_modules/.bin/okfit" ]; then
73
+ # Index mode reads concepts from disk, so skip it while okf/ carries untracked or
74
+ # unstaged work: a commit must never link a concept it does not contain.
75
+ if git -C "$ROOT" status --porcelain --untracked-files=all -- okf | grep -q '^.[^ ]'; then
76
+ pm_exec okfit sync --staged --only generated "$ROOT" || exit 1
77
+ else
78
+ pm_exec okfit sync --staged "$ROOT" || exit 1
79
+ fi
80
+ fi`;
81
+ }
82
+ /**
83
+ * Build the OKF bundle sync block for `pre-commit`.
84
+ *
85
+ * @returns A shell `Section` (`commentStyle: hash`) keyed `SAVVY-OKF`.
86
+ *
87
+ * @since 0.2.0
88
+ * @public
89
+ */
90
+ function savvyOkfBlock() {
91
+ return SavvyOkfSection.section(savvyOkfSync());
92
+ }
93
+
94
+ //#endregion
95
+ export { SavvyOkfSection, savvyOkfBlock, savvyOkfSync };