Skip to content

Commit 8b03202

Browse files
committed
feat: add --share flag to ctx add for automatic hub publishing
When --share is passed, ctx add writes the entry locally AND publishes it to the shared hub in one step. Best-effort: hub publish failure does not block the local write. Uses the existing encrypted connection config from ctx connect register. Signed-off-by: Murat Parlakisik <parlakisik@gmail.com>
1 parent 467fc87 commit 8b03202

6 files changed

Lines changed: 28 additions & 0 deletions

File tree

internal/assets/commands/flags.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ add.rationale:
2424
short: 'Rationale for decisions: why this choice over alternatives (required for decisions)'
2525
add.section:
2626
short: Target section within file
27+
add.share:
28+
short: Also publish to the shared hub
2729
agent.budget:
2830
short: Token budget for context packet
2931
agent.cooldown:

internal/cli/add/cmd/root/cmd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func Cmd() *cobra.Command {
4646
consequence string
4747
lesson string
4848
application string
49+
share bool
4950
)
5051

5152
short, long := desc.Command(cmd.DescKeyAdd)
@@ -72,6 +73,7 @@ func Cmd() *cobra.Command {
7273
Consequence: consequence,
7374
Lesson: lesson,
7475
Application: application,
76+
Share: share,
7577
})
7678
},
7779
}
@@ -117,6 +119,10 @@ func Cmd() *cobra.Command {
117119
c, &application,
118120
cFlag.Application, cFlag.ShortApplication, flag.DescKeyAddApplication,
119121
)
122+
flagbind.BoolFlag(
123+
c, &share,
124+
cFlag.Share, flag.DescKeyAddShare,
125+
)
120126

121127
return c
122128
}

internal/cli/add/cmd/root/run.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@
77
package root
88

99
import (
10+
"path/filepath"
1011
"strings"
1112

1213
"github.com/spf13/cobra"
1314

1415
coreEntry "github.com/ActiveMemory/ctx/internal/cli/add/core/entry"
1516
"github.com/ActiveMemory/ctx/internal/cli/add/core/example"
1617
"github.com/ActiveMemory/ctx/internal/cli/add/core/extract"
18+
corePub "github.com/ActiveMemory/ctx/internal/cli/connect/core/publish"
1719
"github.com/ActiveMemory/ctx/internal/cli/system/core/state"
1820
cfgEntry "github.com/ActiveMemory/ctx/internal/config/entry"
1921
cfgTrace "github.com/ActiveMemory/ctx/internal/config/trace"
2022
"github.com/ActiveMemory/ctx/internal/entity"
2123
"github.com/ActiveMemory/ctx/internal/entry"
2224
errAdd "github.com/ActiveMemory/ctx/internal/err/add"
25+
"github.com/ActiveMemory/ctx/internal/hub"
2326
"github.com/ActiveMemory/ctx/internal/trace"
2427
writeAdd "github.com/ActiveMemory/ctx/internal/write/add"
2528
)
@@ -74,6 +77,18 @@ func Run(cmd *cobra.Command, args []string, flags entity.AddConfig) error {
7477

7578
writeAdd.Added(cmd, fName)
7679

80+
// Best-effort: publish to shared hub if --share is set.
81+
if flags.Share {
82+
pubEntry := hub.PublishEntry{
83+
Type: fType,
84+
Content: content,
85+
Origin: filepath.Base(state.Dir()),
86+
}
87+
_ = corePub.Run(
88+
cmd, []hub.PublishEntry{pubEntry},
89+
)
90+
}
91+
7792
if fType == cfgEntry.Task && coreEntry.NeedsSpec(content) {
7893
writeAdd.SpecNudge(cmd)
7994
}

internal/config/embed/flag/add.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ const (
2424
DescKeyAddRationale = "add.rationale"
2525
// DescKeyAddSection is the description key for the add section flag.
2626
DescKeyAddSection = "add.section"
27+
// DescKeyAddShare is the description key for the add share flag.
28+
DescKeyAddShare = "add.share"
2729
)

internal/config/flag/flag.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ const (
100100
Peers = "peers"
101101
Port = "port"
102102
Serve = "serve"
103+
Share = "share"
103104
Shared = "shared"
104105
Show = "show"
105106
Stop = "stop"

internal/entity/add.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type EntryParams struct {
4343
// - Consequence: Consequence flag for decisions
4444
// - Lesson: Lesson flag for learnings
4545
// - Application: Application flag for learnings
46+
// - Share: Also publish to the shared hub
4647
type AddConfig struct {
4748
Priority string
4849
Section string
@@ -52,4 +53,5 @@ type AddConfig struct {
5253
Consequence string
5354
Lesson string
5455
Application string
56+
Share bool
5557
}

0 commit comments

Comments
 (0)