@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.
- package/.github/workflows/release.yml +44 -0
- package/.goreleaser.yml +44 -0
- package/AGENTS.md +60 -0
- package/CLAUDE.md +192 -0
- package/README.md +2 -0
- package/docs/architecture/awiki-command-v2.md +955 -0
- package/docs/architecture/awiki-skill-architecture.md +475 -0
- package/docs/architecture/awiki-v2-architecture.md +1063 -0
- package/docs/architecture//345/217/202/350/200/203/346/226/207/346/241/243/cli-init.md +1008 -0
- package/docs/architecture//345/217/202/350/200/203/346/226/207/346/241/243/output-format.md +407 -0
- package/docs/architecture//345/217/202/350/200/203/346/226/207/346/241/243/overall-init.md +741 -0
- package/docs/harness/review-spec.md +474 -0
- package/docs/installation.md +372 -0
- package/docs/plan/awiki-v2-implementation-plan.md +903 -0
- package/docs/plan/phase-0/adr-index.md +56 -0
- package/docs/plan/phase-0/audit-findings.md +251 -0
- package/docs/plan/phase-0/capability-mapping.md +108 -0
- package/docs/plan/phase-0/implementation-constraints.md +363 -0
- package/docs/publish.md +169 -0
- package/go.mod +29 -0
- package/go.sum +73 -0
- package/internal/anpsdk/registry.go +63 -0
- package/internal/authsdk/session.go +351 -0
- package/internal/buildinfo/buildinfo.go +34 -0
- package/internal/cli/app.go +136 -0
- package/internal/cli/app_test.go +88 -0
- package/internal/cli/debug.go +104 -0
- package/internal/cli/group.go +263 -0
- package/internal/cli/id.go +473 -0
- package/internal/cli/init.go +134 -0
- package/internal/cli/msg.go +228 -0
- package/internal/cli/page.go +267 -0
- package/internal/cli/root.go +499 -0
- package/internal/cli/runtime.go +232 -0
- package/internal/cli/upgrade.go +60 -0
- package/internal/cmdmeta/catalog.go +203 -0
- package/internal/cmdmeta/catalog_test.go +21 -0
- package/internal/config/config.go +399 -0
- package/internal/config/config_test.go +104 -0
- package/internal/config/write.go +37 -0
- package/internal/content/service.go +314 -0
- package/internal/content/service_test.go +165 -0
- package/internal/content/types.go +44 -0
- package/internal/docs/topics.go +110 -0
- package/internal/doctor/doctor.go +306 -0
- package/internal/identity/client.go +267 -0
- package/internal/identity/did.go +85 -0
- package/internal/identity/did_test.go +50 -0
- package/internal/identity/layout.go +206 -0
- package/internal/identity/legacy.go +378 -0
- package/internal/identity/public.go +70 -0
- package/internal/identity/public_test.go +73 -0
- package/internal/identity/readiness.go +74 -0
- package/internal/identity/service.go +826 -0
- package/internal/identity/store.go +385 -0
- package/internal/identity/store_test.go +180 -0
- package/internal/identity/types.go +204 -0
- package/internal/message/auth.go +167 -0
- package/internal/message/group_service.go +838 -0
- package/internal/message/group_wire.go +350 -0
- package/internal/message/group_wire_test.go +67 -0
- package/internal/message/helpers.go +61 -0
- package/internal/message/http_client.go +334 -0
- package/internal/message/proof.go +156 -0
- package/internal/message/proof_test.go +61 -0
- package/internal/message/service.go +696 -0
- package/internal/message/service_test.go +97 -0
- package/internal/message/types.go +155 -0
- package/internal/message/wire.go +100 -0
- package/internal/message/wire_test.go +49 -0
- package/internal/message/ws_proxy_client.go +151 -0
- package/internal/output/output.go +350 -0
- package/internal/output/output_test.go +48 -0
- package/internal/runtime/config.go +117 -0
- package/internal/runtime/config_test.go +46 -0
- package/internal/runtime/listener/files.go +65 -0
- package/internal/runtime/listener/manager.go +142 -0
- package/internal/runtime/listener/server.go +983 -0
- package/internal/runtime/listener/server_test.go +319 -0
- package/internal/runtime/listener/sysproc_unix.go +17 -0
- package/internal/runtime/listener/sysproc_windows.go +13 -0
- package/internal/runtime/listener/types.go +21 -0
- package/internal/runtime/listener/wsclient.go +299 -0
- package/internal/runtime/listener/wsclient_test.go +41 -0
- package/internal/store/dao.go +632 -0
- package/internal/store/dao_test.go +87 -0
- package/internal/store/helpers.go +197 -0
- package/internal/store/import.go +499 -0
- package/internal/store/import_test.go +103 -0
- package/internal/store/open.go +71 -0
- package/internal/store/query.go +151 -0
- package/internal/store/schema.go +277 -0
- package/internal/store/schema_test.go +56 -0
- package/internal/store/types.go +177 -0
- package/internal/update/update.go +368 -0
- package/package.json +17 -0
- package/scripts/install.js +171 -0
- package/scripts/release/release-prerelease.sh +86 -0
- package/scripts/release/tag-release.sh +66 -0
- package/scripts/release/withdraw-release.sh +78 -0
- package/scripts/run.js +69 -0
- package/skills/README.md +32 -0
- package/skills/awiki-bundle/SKILL.md +76 -0
- package/skills/awiki-debug/SKILL.md +80 -0
- package/skills/awiki-group/SKILL.md +111 -0
- package/skills/awiki-id/SKILL.md +123 -0
- package/skills/awiki-msg/SKILL.md +131 -0
- package/skills/awiki-page/SKILL.md +93 -0
- package/skills/awiki-people/SKILL.md +66 -0
- package/skills/awiki-runtime/SKILL.md +137 -0
- package/skills/awiki-shared/SKILL.md +124 -0
- package/skills/awiki-workflow-discovery/SKILL.md +93 -0
- package/skills/awiki-workflow-onboarding/SKILL.md +119 -0
- package/skills/manifests/skills.yaml +260 -0
- package/skills/templates/bundle-skill-template.md +42 -0
- package/skills/templates/debug-skill-template.md +44 -0
- package/skills/templates/domain-skill-template.md +56 -0
- package/skills/templates/shared-skill-template.md +46 -0
- 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
|
+
}
|