#!/usr/bin/env bash
# intern-admin workspace：创建 knowledge/ 树与 memory/；INDEX.md、FAQ.md 由 Agent 按需创建。
# 须先于 intern-qa 完成，以便其 setup_links.sh 将 knowledge/ 链到本工作区上级同名目录。
#
# 用法：安装器 post_install 调用；或：
#   WORKSPACE=/path/to/workspace-intern ./scripts/init_workspace.sh
#   OPENCLAW_WORKSPACE=... ./scripts/init_workspace.sh
#   ./scripts/init_workspace.sh /path/to/workspace-intern

set -euo pipefail

WS="${WORKSPACE:-${OPENCLAW_WORKSPACE:-${1:-}}}"
if [[ -z "$WS" ]]; then
  echo "init_workspace: set WORKSPACE or OPENCLAW_WORKSPACE, or pass workspace root as first arg." >&2
  exit 1
fi

WS="$(cd "$WS" && pwd)"

# 一次 mkdir -p 建齐 BOOTSTRAP 约定路径（父目录会自动创建，不必逐条拆开写）
mkdir -p \
  "$WS/knowledge/images/"{media,emf_raw} \
  "$WS/knowledge/attachments" \
  "$WS/knowledge/archive" \
  "$WS/memory"

echo "init_workspace: knowledge/ + memory/ ready under ${WS}"
