okf-catalog 0.1.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 (107) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/LICENSE +202 -0
  3. package/NOTICE +10 -0
  4. package/README.md +87 -0
  5. package/dist/bundle/cat-file.js +94 -0
  6. package/dist/bundle/cat-file.js.map +1 -0
  7. package/dist/bundle/contract.js +60 -0
  8. package/dist/bundle/contract.js.map +1 -0
  9. package/dist/bundle/frontmatter.js +106 -0
  10. package/dist/bundle/frontmatter.js.map +1 -0
  11. package/dist/bundle/git-tree.js +109 -0
  12. package/dist/bundle/git-tree.js.map +1 -0
  13. package/dist/bundle/index-file.js +90 -0
  14. package/dist/bundle/index-file.js.map +1 -0
  15. package/dist/bundle/links.js +57 -0
  16. package/dist/bundle/links.js.map +1 -0
  17. package/dist/bundle/load.js +363 -0
  18. package/dist/bundle/load.js.map +1 -0
  19. package/dist/bundle/manifest.js +95 -0
  20. package/dist/bundle/manifest.js.map +1 -0
  21. package/dist/bundle/markdown.js +210 -0
  22. package/dist/bundle/markdown.js.map +1 -0
  23. package/dist/bundle/model.js +7 -0
  24. package/dist/bundle/model.js.map +1 -0
  25. package/dist/bundle/page.js +374 -0
  26. package/dist/bundle/page.js.map +1 -0
  27. package/dist/bundle/paths.js +36 -0
  28. package/dist/bundle/paths.js.map +1 -0
  29. package/dist/bundle/reserved.js +56 -0
  30. package/dist/bundle/reserved.js.map +1 -0
  31. package/dist/bundle/timestamp.js +49 -0
  32. package/dist/bundle/timestamp.js.map +1 -0
  33. package/dist/catalog/model.js +32 -0
  34. package/dist/catalog/model.js.map +1 -0
  35. package/dist/catalog/nearest.js +56 -0
  36. package/dist/catalog/nearest.js.map +1 -0
  37. package/dist/catalog/outputs.js +438 -0
  38. package/dist/catalog/outputs.js.map +1 -0
  39. package/dist/catalog/provenance.js +37 -0
  40. package/dist/catalog/provenance.js.map +1 -0
  41. package/dist/catalog/runtime.js +2 -0
  42. package/dist/catalog/runtime.js.map +1 -0
  43. package/dist/catalog/text.js +140 -0
  44. package/dist/catalog/text.js.map +1 -0
  45. package/dist/cli.js +81 -0
  46. package/dist/cli.js.map +1 -0
  47. package/dist/commands/check.js +155 -0
  48. package/dist/commands/check.js.map +1 -0
  49. package/dist/commands/pack.js +182 -0
  50. package/dist/commands/pack.js.map +1 -0
  51. package/dist/commands/serve.js +452 -0
  52. package/dist/commands/serve.js.map +1 -0
  53. package/dist/config/company-config.js +272 -0
  54. package/dist/config/company-config.js.map +1 -0
  55. package/dist/derive/derived-document.js +42 -0
  56. package/dist/derive/derived-document.js.map +1 -0
  57. package/dist/engine/qmd-render.js +54 -0
  58. package/dist/engine/qmd-render.js.map +1 -0
  59. package/dist/engine/qmd.js +241 -0
  60. package/dist/engine/qmd.js.map +1 -0
  61. package/dist/fs/cache-dir.js +140 -0
  62. package/dist/fs/cache-dir.js.map +1 -0
  63. package/dist/fs/company-lock.js +162 -0
  64. package/dist/fs/company-lock.js.map +1 -0
  65. package/dist/fs/walk.js +168 -0
  66. package/dist/fs/walk.js.map +1 -0
  67. package/dist/log.js +65 -0
  68. package/dist/log.js.map +1 -0
  69. package/dist/mcp/server.js +30 -0
  70. package/dist/mcp/server.js.map +1 -0
  71. package/dist/mcp/stdio.js +45 -0
  72. package/dist/mcp/stdio.js.map +1 -0
  73. package/dist/mcp/tools.js +249 -0
  74. package/dist/mcp/tools.js.map +1 -0
  75. package/dist/report/report.js +43 -0
  76. package/dist/report/report.js.map +1 -0
  77. package/dist/search/engine.js +2 -0
  78. package/dist/search/engine.js.map +1 -0
  79. package/dist/search/query.js +91 -0
  80. package/dist/search/query.js.map +1 -0
  81. package/dist/search/search.js +224 -0
  82. package/dist/search/search.js.map +1 -0
  83. package/dist/search/snippet.js +95 -0
  84. package/dist/search/snippet.js.map +1 -0
  85. package/dist/serve/poller.js +119 -0
  86. package/dist/serve/poller.js.map +1 -0
  87. package/dist/serve/runtime.js +390 -0
  88. package/dist/serve/runtime.js.map +1 -0
  89. package/dist/source/git-runner.js +232 -0
  90. package/dist/source/git-runner.js.map +1 -0
  91. package/dist/source/git.js +457 -0
  92. package/dist/source/git.js.map +1 -0
  93. package/dist/source/local.js +20 -0
  94. package/dist/source/local.js.map +1 -0
  95. package/dist/source/source.js +2 -0
  96. package/dist/source/source.js.map +1 -0
  97. package/npm-shrinkwrap.json +5482 -0
  98. package/package.json +80 -0
  99. package/plugin/claude-code/.claude-plugin/plugin.json +15 -0
  100. package/plugin/claude-code/.mcp.json +10 -0
  101. package/plugin/claude-code/skills/okf-catalog/SKILL.md +15 -0
  102. package/recipes/publish/README.md +32 -0
  103. package/recipes/publish/checkers.lock +435 -0
  104. package/recipes/publish/checkers.txt +5 -0
  105. package/recipes/publish/pack.sh +60 -0
  106. package/recipes/publish/publish.yml +88 -0
  107. package/recipes/publish/push.sh +63 -0
@@ -0,0 +1,60 @@
1
+ #!/bin/sh
2
+ # Checks the source bundle with the OKF checkers, packs it with okf-catalog, checks the result, and prints the
3
+ # commit it recorded. Nothing is pushed here: push.sh does that, in a job that holds the write token (D46).
4
+ #
5
+ # usage: pack.sh --config <path> --source <bundle folder> --out <folder> [--commit <sha>]
6
+ # needs: sh, git, okf-catalog (or OKF_CATALOG_BIN, such as "node dist/cli.js"), and the checkers you enable on PATH.
7
+ # settings: OKFLINT_MANIFEST (okflint's manifest file; unset leaves okflint out), OKF_SCHEMA (1, strict, or unset).
8
+ set -eu
9
+
10
+ usage() {
11
+ echo "usage: pack.sh --config <path> --source <bundle folder> --out <folder> [--commit <sha>]" >&2
12
+ exit 2
13
+ }
14
+
15
+ COMMIT=""
16
+ while [ $# -gt 0 ]; do
17
+ case "$1" in
18
+ --config) CONFIG=$2; shift 2 ;;
19
+ --source) SOURCE=$2; shift 2 ;;
20
+ --out) OUT=$2; shift 2 ;;
21
+ --commit) COMMIT=$2; shift 2 ;;
22
+ *) usage ;;
23
+ esac
24
+ done
25
+ [ -n "${CONFIG:-}" ] && [ -n "${SOURCE:-}" ] && [ -n "${OUT:-}" ] || usage
26
+
27
+ OKF_CATALOG_BIN="${OKF_CATALOG_BIN:-okf-catalog}"
28
+ if [ -z "$COMMIT" ]; then
29
+ COMMIT=$(git -C "$SOURCE" rev-parse HEAD)
30
+ fi
31
+
32
+ # The checkers are the company's gates, run when their setting is given: OKFLINT_MANIFEST names okflint's own
33
+ # manifest file (okflint 0.5.0 exits 2 without one); OKF_SCHEMA is 1, or strict to fail on warnings (okf-schema
34
+ # 0.12.0 fails the specification's own example on its log.md, so a company decides). They run on the source,
35
+ # then the pack, then on what will be published.
36
+ case "${OKF_SCHEMA:-}" in
37
+ ""|1|strict) ;;
38
+ *) echo "OKF_SCHEMA must be unset, 1 or strict" >&2; exit 2 ;;
39
+ esac
40
+ if [ -n "${OKFLINT_MANIFEST:-}" ]; then
41
+ okflint validate --manifest "$OKFLINT_MANIFEST" "$SOURCE" >&2
42
+ fi
43
+ if [ "${OKF_SCHEMA:-}" = 1 ]; then
44
+ okf-schema validate --path "$SOURCE" >&2
45
+ elif [ "${OKF_SCHEMA:-}" = strict ]; then
46
+ okf-schema validate --path "$SOURCE" --strict >&2
47
+ fi
48
+ # OKF_CATALOG_BIN may carry arguments ("node dist/cli.js"), so it is split on purpose.
49
+ # shellcheck disable=SC2086
50
+ $OKF_CATALOG_BIN pack --config "$CONFIG" --from "$SOURCE" --out "$OUT" --commit "$COMMIT" >&2
51
+ if [ -n "${OKFLINT_MANIFEST:-}" ]; then
52
+ okflint validate --manifest "$OKFLINT_MANIFEST" "$OUT" >&2
53
+ fi
54
+ if [ "${OKF_SCHEMA:-}" = 1 ]; then
55
+ okf-schema validate --path "$OUT" >&2
56
+ elif [ "${OKF_SCHEMA:-}" = strict ]; then
57
+ okf-schema validate --path "$OUT" --strict >&2
58
+ fi
59
+
60
+ echo "$COMMIT"
@@ -0,0 +1,88 @@
1
+ # Copy this file into the repository that holds the company's bundle, as .github/workflows/publish.yml, and set the
2
+ # four values under `env`. It runs on a push to the source branch, never on the published branch; a read-only job
3
+ # checks and packs, and a second job with the write token runs git alone. See README.md beside this file.
4
+ name: publish knowledge bundle
5
+
6
+ on:
7
+ push:
8
+ branches:
9
+ - main # the source branch; never the published branch
10
+
11
+ permissions: {}
12
+
13
+ concurrency:
14
+ group: okf-catalog-publish
15
+ cancel-in-progress: false
16
+
17
+ env:
18
+ BUNDLE_PATH: kb
19
+ CONFIG_PATH: okf-catalog.yaml
20
+ PUBLISHED_BRANCH: published
21
+ # The checkers are your gates: okflint needs its own manifest file (unset leaves it out); OKF_SCHEMA is 1, or
22
+ # strict to fail on warnings, or empty to leave okf-schema out.
23
+ OKFLINT_MANIFEST: okf-base.yaml
24
+ OKF_SCHEMA: "1"
25
+ # The server package from a pinned commit of its repository, never a bare package name (the npm name is unclaimed).
26
+ OKF_CATALOG_SOURCE: "github:drathm/okf-catalog#0000000000000000000000000000000000000000"
27
+
28
+ jobs:
29
+ build:
30
+ runs-on: ubuntu-latest
31
+ permissions:
32
+ contents: read
33
+ outputs:
34
+ commit: ${{ steps.pack.outputs.commit }}
35
+ steps:
36
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
37
+ with:
38
+ persist-credentials: false
39
+ - uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
40
+ with:
41
+ node-version: "22"
42
+ - uses: astral-sh/setup-uv@0c5e2b8115b80b4c7c5ddf6ffdd634974642d182 # v5.4.1
43
+ with:
44
+ version: "0.11.19"
45
+ - name: install the server package from its pinned source, then the checkers from its lock
46
+ run: |
47
+ # The server package carries the recipe's scripts and the hash-pinned checker lock; this file is the
48
+ # only thing a company copies. The package builds itself on install (its `prepare` script).
49
+ NODE_LLAMA_CPP_SKIP_DOWNLOAD=1 npm install --global "$OKF_CATALOG_SOURCE"
50
+ RECIPE="$(npm root -g)/okf-catalog/recipes/publish"
51
+ echo "RECIPE=$RECIPE" >> "$GITHUB_ENV"
52
+ uv venv --python 3.12 "$RUNNER_TEMP/checkers"
53
+ uv pip install --python "$RUNNER_TEMP/checkers/bin/python" --require-hashes -r "$RECIPE/checkers.lock"
54
+ echo "$RUNNER_TEMP/checkers/bin" >> "$GITHUB_PATH"
55
+ - name: check, pack, check
56
+ id: pack
57
+ run: |
58
+ commit=$(sh "$RECIPE/pack.sh" --config "$CONFIG_PATH" --source "$BUNDLE_PATH" --out "$RUNNER_TEMP/bundle" --commit "$GITHUB_SHA")
59
+ echo "commit=$commit" >> "$GITHUB_OUTPUT"
60
+ # One archive, so file names the artifact store would refuse (quotes, colons, stars) travel untouched;
61
+ # push.sh rides along, so the publish job installs nothing and runs git alone.
62
+ cp "$RECIPE/push.sh" "$RUNNER_TEMP/push.sh"
63
+ tar -C "$RUNNER_TEMP" -cf "$RUNNER_TEMP/bundle.tar" bundle push.sh
64
+ - uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
65
+ with:
66
+ name: bundle
67
+ path: ${{ runner.temp }}/bundle.tar
68
+ if-no-files-found: error
69
+
70
+ publish:
71
+ needs: build
72
+ runs-on: ubuntu-latest
73
+ permissions:
74
+ contents: write
75
+ steps:
76
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
77
+ with:
78
+ fetch-depth: 1
79
+ - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
80
+ with:
81
+ name: bundle
82
+ path: ${{ runner.temp }}
83
+ - name: commit the bundle onto the published branch and push
84
+ env:
85
+ SOURCE_COMMIT: ${{ needs.build.outputs.commit }}
86
+ run: |
87
+ tar -C "$RUNNER_TEMP" -xf "$RUNNER_TEMP/bundle.tar"
88
+ sh "$RUNNER_TEMP/push.sh" --repo "$GITHUB_WORKSPACE" --bundle "$RUNNER_TEMP/bundle" --commit "$SOURCE_COMMIT" --branch "$PUBLISHED_BRANCH"
@@ -0,0 +1,63 @@
1
+ #!/bin/sh
2
+ # Commits a packed bundle onto the published branch, on top of its current tip, and pushes it without force. It
3
+ # works through a checkout whose remote already carries the credentials (in GitHub Actions, the checkout step's),
4
+ # so no credential ever appears in a URL here, and it never touches that checkout's index or working tree: the
5
+ # bundle is staged into an index of its own and written as a tree with git's plumbing.
6
+ #
7
+ # usage: push.sh --repo <checkout> --bundle <packed folder> --commit <sha> [--remote origin] [--branch published]
8
+ set -eu
9
+
10
+ usage() {
11
+ echo "usage: push.sh --repo <checkout> --bundle <packed folder> --commit <sha> [--remote origin] [--branch published]" >&2
12
+ exit 2
13
+ }
14
+
15
+ REMOTE=origin
16
+ BRANCH=published
17
+ while [ $# -gt 0 ]; do
18
+ case "$1" in
19
+ --repo) REPO=$2; shift 2 ;;
20
+ --bundle) BUNDLE=$2; shift 2 ;;
21
+ --commit) COMMIT=$2; shift 2 ;;
22
+ --remote) REMOTE=$2; shift 2 ;;
23
+ --branch) BRANCH=$2; shift 2 ;;
24
+ *) usage ;;
25
+ esac
26
+ done
27
+ [ -n "${REPO:-}" ] && [ -n "${BUNDLE:-}" ] && [ -n "${COMMIT:-}" ] || usage
28
+ BUNDLE=$(cd "$BUNDLE" && pwd)
29
+
30
+ GIT_DIR=$(git -C "$REPO" rev-parse --absolute-git-dir)
31
+ export GIT_DIR
32
+ export GIT_AUTHOR_NAME="okf-catalog publish" GIT_AUTHOR_EMAIL="okf-catalog-publish@invalid"
33
+ export GIT_COMMITTER_NAME="okf-catalog publish" GIT_COMMITTER_EMAIL="okf-catalog-publish@invalid"
34
+
35
+ TMP=$(mktemp -d)
36
+ trap 'rm -rf "$TMP"' EXIT
37
+ GIT_INDEX_FILE="$TMP/index"
38
+ export GIT_INDEX_FILE
39
+
40
+ # The new commit's parent is the branch's current tip, so a race is rejected by the remote and the next run follows.
41
+ PARENT=""
42
+ if git fetch -q "$REMOTE" "refs/heads/$BRANCH" 2>/dev/null; then
43
+ PARENT=$(git rev-parse --verify -q "FETCH_HEAD^{commit}")
44
+ fi
45
+
46
+ # Stage every file of the packed folder into the private index as a plain blob, with no filter, no line-ending
47
+ # rule and no ignore rule (git add would apply the person's configuration and change the bytes pack hashed).
48
+ (cd "$BUNDLE" && find . -type f | sed 's|^\./||' | LC_ALL=C sort) > "$TMP/files"
49
+ while IFS= read -r file; do
50
+ blob=$(git hash-object -w --no-filters -- "$BUNDLE/$file")
51
+ git update-index --add --cacheinfo "100644,$blob,$file"
52
+ done < "$TMP/files"
53
+ TREE=$(git write-tree)
54
+
55
+ # The message carries the source commit through a variable, never text from an event.
56
+ MESSAGE="publish $COMMIT"
57
+ if [ -n "$PARENT" ]; then
58
+ NEW=$(printf '%s\n' "$MESSAGE" | git commit-tree "$TREE" -p "$PARENT")
59
+ else
60
+ NEW=$(printf '%s\n' "$MESSAGE" | git commit-tree "$TREE")
61
+ fi
62
+ git push -q "$REMOTE" "$NEW:refs/heads/$BRANCH"
63
+ echo "published $COMMIT to $BRANCH as $NEW"