공개 문서

learn/canonical/knot/install-knot-wiki.sh.md

아래는 learn/canonical/knot/install-knot-wiki.sh.md 와 동일한 원문입니다. Markdown과 HTML 변환 결과를 각각 복사할 수 있습니다.

공개 문서 원문 (Markdown)

# tools/knot/install-knot-wiki.sh

> Hub reference copy — MAS 정본: `tools/knot/install-knot-wiki.sh`

```bash
#!/usr/bin/env bash
# Install knot knowledge wiki scaffold (vendor-neutral markdown vault).
# Upstream: https://github.com/netwaif/knot — upstream calls it "vault"; local LAB folder: knot-wiki
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
SCAFFOLD="$ROOT/tools/knot/scaffold"
TARGET="${1:-$ROOT/knot-wiki}"

usage() {
  cat <<EOF
Usage: install-knot-wiki.sh [TARGET_DIR]

Install knot wiki scaffold (default: \$ROOT/knot-wiki — LAB).
Sets KNOT_WIKI in tools/knot/env.example for shell hook.

Options via env:
  KNOT_SKIP_GIT=1   skip git init on new vault

Examples:
  bash tools/knot/install-knot-wiki.sh
  bash tools/knot/install-knot-wiki.sh ~/Desktop/MultiAgentSystem/knot-wiki
  source tools/knot/env.example
EOF
}

if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
  usage
  exit 0
fi

if [[ ! -d "$SCAFFOLD" ]]; then
  echo "[FAIL] scaffold missing: $SCAFFOLD" >&2
  exit 1
fi

if [[ -e "$TARGET" && -n "$(ls -A "$TARGET" 2>/dev/null)" ]]; then
  echo "[FAIL] target not empty: $TARGET" >&2
  echo "       use empty dir or omit existing wiki" >&2
  exit 1
fi

mkdir -p "$TARGET"
if command -v rsync >/dev/null 2>&1; then
  rsync -a "$SCAFFOLD/" "$TARGET/"
else
  cp -a "$SCAFFOLD/." "$TARGET/"
fi

if [[ "${KNOT_SKIP_GIT:-0}" != "1" ]] && [[ ! -d "$TARGET/.git" ]]; then
  git -C "$TARGET" init -q
  git -C "$TARGET" add -A
  git -C "$TARGET" commit -q -m "chore: knot wiki scaffold from MultiAgentSystem tools/knot"
  echo "[OK] git init + initial commit"
fi

ENV_EXAMPLE="$ROOT/tools/knot/env.example"
mkdir -p "$(dirname "$ENV_EXAMPLE")"
cat > "$ENV_EXAMPLE" <<EOF
# Source in shell: export KNOT_WIKI="$TARGET"
export KNOT_WIKI="$TARGET"
# Runner: claude (default) | codex | agy | gemini
export KNOT_RUNNER=claude
EOF

LINT_PY="$TARGET/ops/scripts/lint.py"
[[ -f "$LINT_PY" ]] || LINT_PY="$TARGET/scripts/lint.py"
if python3 "$LINT_PY" "$TARGET" >/dev/null 2>&1; then
  echo "[OK] lint.py PASS (empty wiki)"
else
  echo "[WARN] lint.py reported issues — run: python3 $LINT_PY" >&2
fi

echo
echo "== knot wiki installed =="
echo "  KNOT_WIKI=$TARGET"
echo "  ingest:  bash tools/knot/run-knot.sh ingest"
echo "  query:   bash tools/knot/run-knot.sh query \"질문\""
echo "  lint:    bash tools/knot/run-knot.sh lint"
echo "  docs:    docs/KNOT-HARNESS-INTEGRATION.md"
```

공개 문서 변환 코드 (HTML)

<h1>tools/knot/install-knot-wiki.sh</h1>
<blockquote>
<p>Hub reference copy — MAS 정본: <code>tools/knot/install-knot-wiki.sh</code></p>
</blockquote>
<pre><code class="language-bash">#!/usr/bin/env bash
# Install knot knowledge wiki scaffold (vendor-neutral markdown vault).
# Upstream: https://github.com/netwaif/knot — upstream calls it &quot;vault&quot;; local LAB folder: knot-wiki
set -euo pipefail

ROOT=&quot;$(cd &quot;$(dirname &quot;$0&quot;)/../..&quot; &amp;&amp; pwd)&quot;
SCAFFOLD=&quot;$ROOT/tools/knot/scaffold&quot;
TARGET=&quot;${1:-$ROOT/knot-wiki}&quot;

usage() {
  cat &lt;&lt;EOF
Usage: install-knot-wiki.sh [TARGET_DIR]

Install knot wiki scaffold (default: \$ROOT/knot-wiki — LAB).
Sets KNOT_WIKI in tools/knot/env.example for shell hook.

Options via env:
  KNOT_SKIP_GIT=1   skip git init on new vault

Examples:
  bash tools/knot/install-knot-wiki.sh
  bash tools/knot/install-knot-wiki.sh ~/Desktop/MultiAgentSystem/knot-wiki
  source tools/knot/env.example
EOF
}

if [[ &quot;${1:-}&quot; == &quot;-h&quot; || &quot;${1:-}&quot; == &quot;--help&quot; ]]; then
  usage
  exit 0
fi

if [[ ! -d &quot;$SCAFFOLD&quot; ]]; then
  echo &quot;[FAIL] scaffold missing: $SCAFFOLD&quot; &gt;&amp;2
  exit 1
fi

if [[ -e &quot;$TARGET&quot; &amp;&amp; -n &quot;$(ls -A &quot;$TARGET&quot; 2&gt;/dev/null)&quot; ]]; then
  echo &quot;[FAIL] target not empty: $TARGET&quot; &gt;&amp;2
  echo &quot;       use empty dir or omit existing wiki&quot; &gt;&amp;2
  exit 1
fi

mkdir -p &quot;$TARGET&quot;
if command -v rsync &gt;/dev/null 2&gt;&amp;1; then
  rsync -a &quot;$SCAFFOLD/&quot; &quot;$TARGET/&quot;
else
  cp -a &quot;$SCAFFOLD/.&quot; &quot;$TARGET/&quot;
fi

if [[ &quot;${KNOT_SKIP_GIT:-0}&quot; != &quot;1&quot; ]] &amp;&amp; [[ ! -d &quot;$TARGET/.git&quot; ]]; then
  git -C &quot;$TARGET&quot; init -q
  git -C &quot;$TARGET&quot; add -A
  git -C &quot;$TARGET&quot; commit -q -m &quot;chore: knot wiki scaffold from MultiAgentSystem tools/knot&quot;
  echo &quot;[OK] git init + initial commit&quot;
fi

ENV_EXAMPLE=&quot;$ROOT/tools/knot/env.example&quot;
mkdir -p &quot;$(dirname &quot;$ENV_EXAMPLE&quot;)&quot;
cat &gt; &quot;$ENV_EXAMPLE&quot; &lt;&lt;EOF
# Source in shell: export KNOT_WIKI=&quot;$TARGET&quot;
export KNOT_WIKI=&quot;$TARGET&quot;
# Runner: claude (default) | codex | agy | gemini
export KNOT_RUNNER=claude
EOF

LINT_PY=&quot;$TARGET/ops/scripts/lint.py&quot;
[[ -f &quot;$LINT_PY&quot; ]] || LINT_PY=&quot;$TARGET/scripts/lint.py&quot;
if python3 &quot;$LINT_PY&quot; &quot;$TARGET&quot; &gt;/dev/null 2&gt;&amp;1; then
  echo &quot;[OK] lint.py PASS (empty wiki)&quot;
else
  echo &quot;[WARN] lint.py reported issues — run: python3 $LINT_PY&quot; &gt;&amp;2
fi

echo
echo &quot;== knot wiki installed ==&quot;
echo &quot;  KNOT_WIKI=$TARGET&quot;
echo &quot;  ingest:  bash tools/knot/run-knot.sh ingest&quot;
echo &quot;  query:   bash tools/knot/run-knot.sh query \&quot;질문\&quot;&quot;
echo &quot;  lint:    bash tools/knot/run-knot.sh lint&quot;
echo &quot;  docs:    docs/KNOT-HARNESS-INTEGRATION.md&quot;
</code></pre>