@awiki/cli 0.0.1-beta.2

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 (119) hide show
  1. package/.github/workflows/release.yml +44 -0
  2. package/.goreleaser.yml +44 -0
  3. package/AGENTS.md +60 -0
  4. package/CLAUDE.md +192 -0
  5. package/README.md +2 -0
  6. package/docs/architecture/awiki-command-v2.md +955 -0
  7. package/docs/architecture/awiki-skill-architecture.md +475 -0
  8. package/docs/architecture/awiki-v2-architecture.md +1063 -0
  9. package/docs/architecture//345/217/202/350/200/203/346/226/207/346/241/243/cli-init.md +1008 -0
  10. package/docs/architecture//345/217/202/350/200/203/346/226/207/346/241/243/output-format.md +407 -0
  11. package/docs/architecture//345/217/202/350/200/203/346/226/207/346/241/243/overall-init.md +741 -0
  12. package/docs/harness/review-spec.md +474 -0
  13. package/docs/installation.md +372 -0
  14. package/docs/plan/awiki-v2-implementation-plan.md +903 -0
  15. package/docs/plan/phase-0/adr-index.md +56 -0
  16. package/docs/plan/phase-0/audit-findings.md +251 -0
  17. package/docs/plan/phase-0/capability-mapping.md +108 -0
  18. package/docs/plan/phase-0/implementation-constraints.md +363 -0
  19. package/docs/publish.md +169 -0
  20. package/go.mod +29 -0
  21. package/go.sum +73 -0
  22. package/internal/anpsdk/registry.go +63 -0
  23. package/internal/authsdk/session.go +351 -0
  24. package/internal/buildinfo/buildinfo.go +34 -0
  25. package/internal/cli/app.go +136 -0
  26. package/internal/cli/app_test.go +88 -0
  27. package/internal/cli/debug.go +104 -0
  28. package/internal/cli/group.go +263 -0
  29. package/internal/cli/id.go +473 -0
  30. package/internal/cli/init.go +134 -0
  31. package/internal/cli/msg.go +228 -0
  32. package/internal/cli/page.go +267 -0
  33. package/internal/cli/root.go +499 -0
  34. package/internal/cli/runtime.go +232 -0
  35. package/internal/cli/upgrade.go +60 -0
  36. package/internal/cmdmeta/catalog.go +203 -0
  37. package/internal/cmdmeta/catalog_test.go +21 -0
  38. package/internal/config/config.go +399 -0
  39. package/internal/config/config_test.go +104 -0
  40. package/internal/config/write.go +37 -0
  41. package/internal/content/service.go +314 -0
  42. package/internal/content/service_test.go +165 -0
  43. package/internal/content/types.go +44 -0
  44. package/internal/docs/topics.go +110 -0
  45. package/internal/doctor/doctor.go +306 -0
  46. package/internal/identity/client.go +267 -0
  47. package/internal/identity/did.go +85 -0
  48. package/internal/identity/did_test.go +50 -0
  49. package/internal/identity/layout.go +206 -0
  50. package/internal/identity/legacy.go +378 -0
  51. package/internal/identity/public.go +70 -0
  52. package/internal/identity/public_test.go +73 -0
  53. package/internal/identity/readiness.go +74 -0
  54. package/internal/identity/service.go +826 -0
  55. package/internal/identity/store.go +385 -0
  56. package/internal/identity/store_test.go +180 -0
  57. package/internal/identity/types.go +204 -0
  58. package/internal/message/auth.go +167 -0
  59. package/internal/message/group_service.go +838 -0
  60. package/internal/message/group_wire.go +350 -0
  61. package/internal/message/group_wire_test.go +67 -0
  62. package/internal/message/helpers.go +61 -0
  63. package/internal/message/http_client.go +334 -0
  64. package/internal/message/proof.go +156 -0
  65. package/internal/message/proof_test.go +61 -0
  66. package/internal/message/service.go +696 -0
  67. package/internal/message/service_test.go +97 -0
  68. package/internal/message/types.go +155 -0
  69. package/internal/message/wire.go +100 -0
  70. package/internal/message/wire_test.go +49 -0
  71. package/internal/message/ws_proxy_client.go +151 -0
  72. package/internal/output/output.go +350 -0
  73. package/internal/output/output_test.go +48 -0
  74. package/internal/runtime/config.go +117 -0
  75. package/internal/runtime/config_test.go +46 -0
  76. package/internal/runtime/listener/files.go +65 -0
  77. package/internal/runtime/listener/manager.go +142 -0
  78. package/internal/runtime/listener/server.go +983 -0
  79. package/internal/runtime/listener/server_test.go +319 -0
  80. package/internal/runtime/listener/sysproc_unix.go +17 -0
  81. package/internal/runtime/listener/sysproc_windows.go +13 -0
  82. package/internal/runtime/listener/types.go +21 -0
  83. package/internal/runtime/listener/wsclient.go +299 -0
  84. package/internal/runtime/listener/wsclient_test.go +41 -0
  85. package/internal/store/dao.go +632 -0
  86. package/internal/store/dao_test.go +87 -0
  87. package/internal/store/helpers.go +197 -0
  88. package/internal/store/import.go +499 -0
  89. package/internal/store/import_test.go +103 -0
  90. package/internal/store/open.go +71 -0
  91. package/internal/store/query.go +151 -0
  92. package/internal/store/schema.go +277 -0
  93. package/internal/store/schema_test.go +56 -0
  94. package/internal/store/types.go +177 -0
  95. package/internal/update/update.go +368 -0
  96. package/package.json +17 -0
  97. package/scripts/install.js +171 -0
  98. package/scripts/release/release-prerelease.sh +86 -0
  99. package/scripts/release/tag-release.sh +66 -0
  100. package/scripts/release/withdraw-release.sh +78 -0
  101. package/scripts/run.js +69 -0
  102. package/skills/README.md +32 -0
  103. package/skills/awiki-bundle/SKILL.md +76 -0
  104. package/skills/awiki-debug/SKILL.md +80 -0
  105. package/skills/awiki-group/SKILL.md +111 -0
  106. package/skills/awiki-id/SKILL.md +123 -0
  107. package/skills/awiki-msg/SKILL.md +131 -0
  108. package/skills/awiki-page/SKILL.md +93 -0
  109. package/skills/awiki-people/SKILL.md +66 -0
  110. package/skills/awiki-runtime/SKILL.md +137 -0
  111. package/skills/awiki-shared/SKILL.md +124 -0
  112. package/skills/awiki-workflow-discovery/SKILL.md +93 -0
  113. package/skills/awiki-workflow-onboarding/SKILL.md +119 -0
  114. package/skills/manifests/skills.yaml +260 -0
  115. package/skills/templates/bundle-skill-template.md +42 -0
  116. package/skills/templates/debug-skill-template.md +44 -0
  117. package/skills/templates/domain-skill-template.md +56 -0
  118. package/skills/templates/shared-skill-template.md +46 -0
  119. package/skills/templates/workflow-skill-template.md +46 -0
@@ -0,0 +1,142 @@
1
+ package listener
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "os"
7
+ "os/exec"
8
+ "os/signal"
9
+ "path/filepath"
10
+ "syscall"
11
+ "time"
12
+
13
+ appconfig "github.com/agentconnect/awiki-cli/internal/config"
14
+ runtimecfg "github.com/agentconnect/awiki-cli/internal/runtime"
15
+ )
16
+
17
+ func StatusFor(resolved *appconfig.Resolved) (Status, error) {
18
+ pidFile, logFile, statusFile, socketPath, err := paths(resolved)
19
+ if err != nil {
20
+ return Status{}, err
21
+ }
22
+ status := Status{
23
+ Mode: runtimecfg.Resolve(resolved).Mode,
24
+ PIDFile: pidFile,
25
+ LogFile: logFile,
26
+ StatusFile: statusFile,
27
+ SocketPath: socketPath,
28
+ }
29
+ if saved, err := readStatus(statusFile); err == nil {
30
+ status = saved
31
+ status.PIDFile = pidFile
32
+ status.LogFile = logFile
33
+ status.StatusFile = statusFile
34
+ status.SocketPath = socketPath
35
+ }
36
+ pid, err := readPID(pidFile)
37
+ if err == nil {
38
+ status.PID = pid
39
+ status.Running = processExists(pid)
40
+ }
41
+ if !status.Running {
42
+ status.Warnings = append(status.Warnings, "listener process is not running")
43
+ }
44
+ if _, err := os.Stat(socketPath); err != nil {
45
+ status.Warnings = append(status.Warnings, "listener socket is not available")
46
+ }
47
+ return status, nil
48
+ }
49
+
50
+ func Start(resolved *appconfig.Resolved) (Status, error) {
51
+ if runtimecfg.Resolve(resolved).Mode != runtimecfg.ModeWebSocket {
52
+ return Status{}, fmt.Errorf("runtime mode must be websocket before starting the listener")
53
+ }
54
+ status, err := StatusFor(resolved)
55
+ if err == nil && status.Running {
56
+ return status, nil
57
+ }
58
+ executable, err := os.Executable()
59
+ if err != nil {
60
+ return Status{}, err
61
+ }
62
+ if err := os.MkdirAll(filepath.Dir(status.LogFile), 0o700); err != nil {
63
+ return Status{}, err
64
+ }
65
+ logFile, err := os.OpenFile(status.LogFile, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o600)
66
+ if err != nil {
67
+ return Status{}, err
68
+ }
69
+ defer logFile.Close()
70
+ command := exec.Command(executable, "runtime", "listener", "run")
71
+ command.Stdout = logFile
72
+ command.Stderr = logFile
73
+ command.Env = os.Environ()
74
+ setSysProcAttr(command)
75
+ if err := command.Start(); err != nil {
76
+ return Status{}, err
77
+ }
78
+ pid := command.Process.Pid
79
+ if err := writePID(status.PIDFile, pid); err != nil {
80
+ return Status{}, err
81
+ }
82
+ for index := 0; index < 20; index++ {
83
+ time.Sleep(250 * time.Millisecond)
84
+ status, _ = StatusFor(resolved)
85
+ if status.Running {
86
+ return status, nil
87
+ }
88
+ }
89
+ return StatusFor(resolved)
90
+ }
91
+
92
+ func Stop(resolved *appconfig.Resolved) (Status, error) {
93
+ status, err := StatusFor(resolved)
94
+ if err != nil {
95
+ return Status{}, err
96
+ }
97
+ if status.PID != 0 && processExists(status.PID) {
98
+ process, err := os.FindProcess(status.PID)
99
+ if err == nil {
100
+ _ = process.Signal(syscall.SIGTERM)
101
+ }
102
+ for index := 0; index < 20; index++ {
103
+ time.Sleep(250 * time.Millisecond)
104
+ if !processExists(status.PID) {
105
+ break
106
+ }
107
+ }
108
+ }
109
+ _ = os.Remove(status.PIDFile)
110
+ _ = os.Remove(status.SocketPath)
111
+ _ = os.Remove(status.StatusFile)
112
+ return StatusFor(resolved)
113
+ }
114
+
115
+ func Restart(resolved *appconfig.Resolved) (Status, error) {
116
+ if _, err := Stop(resolved); err != nil {
117
+ return Status{}, err
118
+ }
119
+ return Start(resolved)
120
+ }
121
+
122
+ func RunForeground(resolved *appconfig.Resolved) error {
123
+ supervisor, err := NewSupervisor(resolved)
124
+ if err != nil {
125
+ return err
126
+ }
127
+ defer supervisor.Close()
128
+ ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
129
+ defer stop()
130
+ return supervisor.Run(ctx)
131
+ }
132
+
133
+ func processExists(pid int) bool {
134
+ if pid <= 0 {
135
+ return false
136
+ }
137
+ process, err := os.FindProcess(pid)
138
+ if err != nil {
139
+ return false
140
+ }
141
+ return process.Signal(syscall.Signal(0)) == nil
142
+ }