openartifacts-publish~20261014-230833.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/sh
  2. SOURCE=${1:-}
  3. STAGED_HTML=${2:-}
  4. case "$#" in
  5. 1) ;;
  6. 2) ;;
  7. *)
  8. printf '%s\n' "Usage: sh openartifacts-publish.sh <source-note-path> [staged-html-path]" >&2
  9. exit 1
  10. ;;
  11. esac
  12. [ -n "$SOURCE" ] && { [ "$#" -eq 1 ] || [ -n "$STAGED_HTML" ]; } || {
  13. printf '%s\n' "Usage: sh openartifacts-publish.sh <source-note-path> [staged-html-path]" >&2
  14. exit 1
  15. }
  16. OBSIDIAN_CLI=${COPILOT_OBSIDIAN_CLI:-}
  17. WORKSPACE_ROOT=${OPENARTIFACTS_WORKSPACE_ROOT:-}
  18. [ -n "$WORKSPACE_ROOT" ] || {
  19. printf '%s\n' "The owning Obsidian workspace is unavailable." >&2
  20. exit 1
  21. }
  22. [ -n "$OBSIDIAN_CLI" ] || {
  23. printf '%s\n' "A compatible Obsidian CLI is unavailable." >&2
  24. exit 1
  25. }
  26. cd "$WORKSPACE_ROOT" || {
  27. printf '%s\n' "The owning Obsidian workspace is unavailable." >&2
  28. exit 1
  29. }
  30. VAULT_NAME=${WORKSPACE_ROOT%/}
  31. VAULT_NAME=${VAULT_NAME##*/}
  32. [ -n "$VAULT_NAME" ] || {
  33. printf '%s\n' "The owning Obsidian vault is unavailable." >&2
  34. exit 1
  35. }
  36. SOURCE_B64=$(printf '%s' "$SOURCE" | base64 | tr -d '\r\n')
  37. if [ "$#" -eq 1 ]; then
  38. CODE="(()=>{const decode=(value)=>new TextDecoder().decode(Uint8Array.from(atob(value),(char)=>char.charCodeAt(0)));const bridge=app.plugins.plugins.copilot?.openArtifactsAgentBridge;if(!bridge)throw new Error('Copilot OpenArtifacts host is unavailable.');return bridge.reviewAgentManage(decode('$SOURCE_B64')).then(JSON.stringify);})()"
  39. else
  40. HTML_B64=$(printf '%s' "$STAGED_HTML" | base64 | tr -d '\r\n')
  41. CODE="(()=>{const decode=(value)=>new TextDecoder().decode(Uint8Array.from(atob(value),(char)=>char.charCodeAt(0)));const bridge=app.plugins.plugins.copilot?.openArtifactsAgentBridge;if(!bridge)throw new Error('Copilot OpenArtifacts host is unavailable.');return bridge.reviewAgentPublish(decode('$SOURCE_B64'),decode('$HTML_B64')).then(JSON.stringify);})()"
  42. fi
  43. CLI_OUTPUT=$("$OBSIDIAN_CLI" "vault=$VAULT_NAME" eval "code=$CODE") || exit $?
  44. CLI_RESULT=$(printf '%s\n' "$CLI_OUTPUT" | sed -n '/^=> {/p' | sed -n '$p')
  45. case "$CLI_RESULT" in
  46. "=> {"*)
  47. OUTCOME=${CLI_RESULT#"=> "}
  48. printf '%s\n' "$OUTCOME"
  49. exit 0
  50. ;;
  51. *)
  52. printf '%s\n' "Copilot could not complete the OpenArtifacts review." >&2
  53. exit 1
  54. ;;
  55. esac