@tanagram/cli 0.2.0 → 0.2.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/install.js +3 -1
- package/main.go +9 -0
- package/metrics/metrics.go +32 -11
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -4,6 +4,7 @@ const { execSync } = require('child_process');
|
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const os = require('os');
|
|
7
|
+
const pkg = require('./package.json');
|
|
7
8
|
|
|
8
9
|
const GO_VERSION = '1.21.0';
|
|
9
10
|
const GO_CACHE_DIR = path.join(os.homedir(), '.tanagram', `go-${GO_VERSION}`);
|
|
@@ -80,7 +81,8 @@ function buildBinary(goCommand) {
|
|
|
80
81
|
console.log('🔧 Building Tanagram CLI...');
|
|
81
82
|
|
|
82
83
|
try {
|
|
83
|
-
|
|
84
|
+
const ldflags = `-X 'main.Version=${pkg.version}'`;
|
|
85
|
+
execSync(`"${goCommand}" build -ldflags "${ldflags}" -o "${binaryPath}" .`, {
|
|
84
86
|
cwd: __dirname,
|
|
85
87
|
stdio: 'inherit',
|
|
86
88
|
env: {
|
package/main.go
CHANGED
|
@@ -9,7 +9,11 @@ import (
|
|
|
9
9
|
"github.com/tanagram/cli/tui"
|
|
10
10
|
)
|
|
11
11
|
|
|
12
|
+
// Version is set in install.js via `-X` ldflags
|
|
13
|
+
var Version = "dev"
|
|
14
|
+
|
|
12
15
|
func main() {
|
|
16
|
+
metrics.SetVersion(Version)
|
|
13
17
|
metrics.Init()
|
|
14
18
|
|
|
15
19
|
exitCode := 0
|
|
@@ -114,6 +118,9 @@ func main() {
|
|
|
114
118
|
return
|
|
115
119
|
}
|
|
116
120
|
return
|
|
121
|
+
case "version", "-v", "--version":
|
|
122
|
+
fmt.Println(Version)
|
|
123
|
+
return
|
|
117
124
|
case "help", "-h", "--help":
|
|
118
125
|
printHelp()
|
|
119
126
|
return
|
|
@@ -148,6 +155,7 @@ COMMANDS:
|
|
|
148
155
|
list Show all cached policies
|
|
149
156
|
config claude Setup Claude Code hook automatically
|
|
150
157
|
config list Show hook installation status
|
|
158
|
+
version Show the CLI version
|
|
151
159
|
help Show this help message
|
|
152
160
|
|
|
153
161
|
EXAMPLES:
|
|
@@ -158,6 +166,7 @@ EXAMPLES:
|
|
|
158
166
|
tanagram list # View all cached policies
|
|
159
167
|
tanagram config claude # Setup Claude Code hooks in ~/.claude/settings.json
|
|
160
168
|
tanagram config list # Show where hooks are installed
|
|
169
|
+
tanagram version # Show the version
|
|
161
170
|
|
|
162
171
|
INSTRUCTION FILES:
|
|
163
172
|
Tanagram looks for instruction files in your git repository:
|
package/metrics/metrics.go
CHANGED
|
@@ -2,6 +2,7 @@ package metrics
|
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
4
|
"os"
|
|
5
|
+
"os/user"
|
|
5
6
|
"runtime"
|
|
6
7
|
"time"
|
|
7
8
|
|
|
@@ -14,8 +15,14 @@ var (
|
|
|
14
15
|
// Injected at build time via -ldflags
|
|
15
16
|
posthogWriteKey = "phc_sMsUvf0nK50rZdztSlX9rDJqIreLcXj4dyGS0tORQpQ"
|
|
16
17
|
posthogHost = "https://us.i.posthog.com"
|
|
18
|
+
version = "dev"
|
|
17
19
|
)
|
|
18
20
|
|
|
21
|
+
// SetVersion sets the CLI version
|
|
22
|
+
func SetVersion(v string) {
|
|
23
|
+
version = v
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
// Init initializes the PostHog client
|
|
20
27
|
// Similar to PosthogService.py and webui/app/lib/posthog.ts
|
|
21
28
|
func Init() {
|
|
@@ -71,10 +78,12 @@ func Track(event string, properties map[string]interface{}) {
|
|
|
71
78
|
|
|
72
79
|
// Add context dimensions similar to MetricsService
|
|
73
80
|
properties["$process_person_profile"] = false // Match Python implementation
|
|
74
|
-
properties["_deployment_env"] = getDeploymentEnv()
|
|
75
81
|
properties["os"] = runtime.GOOS
|
|
76
82
|
properties["arch"] = runtime.GOARCH
|
|
77
83
|
properties["cli_version"] = getVersion()
|
|
84
|
+
properties["os_user"] = getUser()
|
|
85
|
+
properties["hostname"] = getHostname()
|
|
86
|
+
properties["cwd"] = getCwd()
|
|
78
87
|
|
|
79
88
|
// Build properties - include all custom properties from the caller
|
|
80
89
|
props := posthog.NewProperties()
|
|
@@ -98,25 +107,37 @@ func Track(event string, properties map[string]interface{}) {
|
|
|
98
107
|
// getDistinctId returns a stable anonymous identifier
|
|
99
108
|
// Similar to user_id_for_github_dot_com() pattern
|
|
100
109
|
func getDistinctId() string {
|
|
101
|
-
|
|
110
|
+
return "cli_" + getHostname()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// getHostname returns the computer's hostname
|
|
114
|
+
func getHostname() string {
|
|
102
115
|
hostname, err := os.Hostname()
|
|
103
116
|
if err != nil {
|
|
104
117
|
return "unknown"
|
|
105
118
|
}
|
|
106
|
-
return
|
|
119
|
+
return hostname
|
|
107
120
|
}
|
|
108
121
|
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if
|
|
113
|
-
return
|
|
122
|
+
// getUser returns the current OS user's login name
|
|
123
|
+
func getUser() string {
|
|
124
|
+
u, err := user.Current()
|
|
125
|
+
if err != nil {
|
|
126
|
+
return "unknown"
|
|
127
|
+
}
|
|
128
|
+
return u.Username
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// getCwd returns the current working directory
|
|
132
|
+
func getCwd() string {
|
|
133
|
+
cwd, err := os.Getwd()
|
|
134
|
+
if err != nil {
|
|
135
|
+
return "unknown"
|
|
114
136
|
}
|
|
115
|
-
return
|
|
137
|
+
return cwd
|
|
116
138
|
}
|
|
117
139
|
|
|
118
140
|
// getVersion returns the CLI version
|
|
119
141
|
func getVersion() string {
|
|
120
|
-
|
|
121
|
-
return "0.1.14"
|
|
142
|
+
return version
|
|
122
143
|
}
|