Auto-create project-branches referenced in transcript prompts (#5077)

This commit is contained in:
Chris Penner 2024-06-12 06:28:12 -07:00 committed by GitHub
parent 335512e331
commit 815c1b1f1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
34 changed files with 47 additions and 209 deletions

View File

@ -24,11 +24,13 @@ import U.Codebase.Projects qualified as Projects
import U.Codebase.Reference qualified as C.Reference
import U.Codebase.Referent qualified as C.Referent
import U.Codebase.Sqlite.DbId (ObjectId)
import U.Codebase.Sqlite.DbId qualified as Db
import U.Codebase.Sqlite.NameLookups (PathSegments (..), ReversedName (..))
import U.Codebase.Sqlite.NamedRef qualified as S
import U.Codebase.Sqlite.ObjectType qualified as OT
import U.Codebase.Sqlite.Operations (NamesInPerspective (..))
import U.Codebase.Sqlite.Operations qualified as Ops
import U.Codebase.Sqlite.ProjectBranch (ProjectBranch (..))
import U.Codebase.Sqlite.Queries qualified as Q
import U.Codebase.Sqlite.V2.HashHandle (v2HashHandle)
import Unison.Builtin qualified as Builtins
@ -41,6 +43,7 @@ import Unison.Codebase.SqliteCodebase.Branch.Cache (BranchCache)
import Unison.Codebase.SqliteCodebase.Conversions qualified as Cv
import Unison.ConstructorReference (GConstructorReference (..))
import Unison.ConstructorType qualified as CT
import Unison.Core.Project (ProjectBranchName, ProjectName)
import Unison.DataDeclaration (Decl)
import Unison.DataDeclaration qualified as Decl
import Unison.Hash (Hash)
@ -731,3 +734,15 @@ makeMaybeCachedTransaction size action = do
pure \x -> do
conn <- Sqlite.unsafeGetConnection
Sqlite.unsafeIO (Cache.applyDefined cache (\x -> Sqlite.unsafeUnTransaction (action x) conn) x)
insertProjectAndBranch :: Db.ProjectId -> ProjectName -> Db.ProjectBranchId -> ProjectBranchName -> Sqlite.Transaction ()
insertProjectAndBranch projectId projectName branchId branchName = do
Q.insertProject projectId projectName
Q.insertProjectBranch
ProjectBranch
{ projectId,
branchId,
name = branchName,
parentBranchId = Nothing
}
Q.setMostRecentBranch projectId branchId

View File

@ -10,7 +10,6 @@ import Data.Text qualified as Text
import Data.UUID.V4 qualified as UUID
import System.Random.Shuffle qualified as RandomShuffle
import U.Codebase.Sqlite.DbId
import U.Codebase.Sqlite.ProjectBranch qualified as Sqlite
import U.Codebase.Sqlite.Queries qualified as Queries
import Unison.Cli.DownloadUtils (downloadProjectBranchFromShare)
import Unison.Cli.Monad (Cli)
@ -22,11 +21,11 @@ import Unison.Codebase qualified as Codebase
import Unison.Codebase.Branch qualified as Branch
import Unison.Codebase.Editor.Output qualified as Output
import Unison.Codebase.Path qualified as Path
import Unison.Codebase.SqliteCodebase.Operations qualified as Ops
import Unison.NameSegment qualified as NameSegment
import Unison.Prelude
import Unison.Project (ProjectAndBranch (..), ProjectBranchName, ProjectName)
import Unison.Project (ProjectAndBranch (..), ProjectName)
import Unison.Share.API.Hash qualified as Share.API
import Unison.Sqlite qualified as Sqlite
import Unison.Sync.Common qualified as Sync.Common
import Witch (unsafeFrom)
@ -73,7 +72,7 @@ projectCreate tryDownloadingBase maybeProjectName = do
projectName : projectNames ->
Queries.projectExistsByName projectName >>= \case
False -> do
insertProjectAndBranch projectId projectName branchId branchName
Ops.insertProjectAndBranch projectId projectName branchId branchName
pure projectName
True -> loop projectNames
loop randomProjectNames
@ -81,7 +80,7 @@ projectCreate tryDownloadingBase maybeProjectName = do
Cli.runTransactionWithRollback \rollback -> do
Queries.projectExistsByName projectName >>= \case
False -> do
insertProjectAndBranch projectId projectName branchId branchName
Ops.insertProjectAndBranch projectId projectName branchId branchName
pure projectName
True -> rollback (Output.ProjectNameAlreadyExists projectName)
@ -152,18 +151,6 @@ projectCreate tryDownloadingBase maybeProjectName = do
Nothing -> "project.create"
Just projectName -> "project.create " <> into @Text projectName
insertProjectAndBranch :: ProjectId -> ProjectName -> ProjectBranchId -> ProjectBranchName -> Sqlite.Transaction ()
insertProjectAndBranch projectId projectName branchId branchName = do
Queries.insertProject projectId projectName
Queries.insertProjectBranch
Sqlite.ProjectBranch
{ projectId,
branchId,
name = branchName,
parentBranchId = Nothing
}
Queries.setMostRecentBranch projectId branchId
-- An infinite list of random project names that looks like
--
-- [

View File

@ -31,6 +31,7 @@ import Data.List (isSubsequenceOf)
import Data.Map qualified as Map
import Data.Text qualified as Text
import Data.These (These (..))
import Data.UUID.V4 qualified as UUID
import Ki qualified
import Network.HTTP.Client qualified as HTTP
import System.Directory (doesFileExist)
@ -39,7 +40,11 @@ import System.Exit (die)
import System.IO qualified as IO
import System.IO.Error (catchIOError)
import Text.Megaparsec qualified as P
import U.Codebase.Sqlite.DbId qualified as Db
import U.Codebase.Sqlite.Operations qualified as Operations
import U.Codebase.Sqlite.Project (Project (..))
import U.Codebase.Sqlite.ProjectBranch (ProjectBranch (..))
import U.Codebase.Sqlite.Queries qualified as Q
import Unison.Auth.CredentialManager qualified as AuthN
import Unison.Auth.HTTPClient qualified as AuthN
import Unison.Auth.Tokens qualified as AuthN
@ -70,6 +75,7 @@ import Unison.Project (ProjectAndBranch (..), ProjectAndBranchNames (ProjectAndB
import Unison.Runtime.Interface qualified as RTI
import Unison.Server.Backend qualified as Backend
import Unison.Server.CodebaseServer qualified as Server
import Unison.Sqlite qualified as Sqlite
import Unison.Symbol (Symbol)
import Unison.Syntax.Parser qualified as Parser
import Unison.Util.Pretty qualified as Pretty
@ -349,10 +355,24 @@ run verbosity dir stanzas codebase runtime sbRuntime nRuntime config ucmVersion
if curPath == path
then pure Nothing
else pure $ Just (SwitchBranchI (Path.absoluteToPath' path))
UcmContextProject (ProjectAndBranch projectName branchName) -> do
ProjectAndBranch project branch <-
ProjectUtils.expectProjectAndBranchByTheseNames (These projectName branchName)
let projectAndBranchIds = ProjectAndBranch (project ^. #projectId) (branch ^. #branchId)
UcmContextProject (ProjectAndBranch projectName branchName) -> Cli.runTransaction do
Project {projectId, name = projectName} <-
Q.loadProjectByName projectName
>>= \case
Nothing -> do
projectId <- Sqlite.unsafeIO (Db.ProjectId <$> UUID.nextRandom)
Q.insertProject projectId projectName
pure $ Project {projectId, name = projectName}
Just project -> pure project
projectBranch <-
Q.loadProjectBranchByName projectId branchName >>= \case
Nothing -> do
branchId <- Sqlite.unsafeIO (Db.ProjectBranchId <$> UUID.nextRandom)
let projectBranch = ProjectBranch {projectId, parentBranchId = Nothing, branchId, name = branchName}
Q.insertProjectBranch projectBranch
pure projectBranch
Just projBranch -> pure projBranch
let projectAndBranchIds = ProjectAndBranch projectBranch.projectId projectBranch.branchId
pure
if curPath == ProjectUtils.projectBranchPath projectAndBranchIds
then Nothing

View File

@ -4,7 +4,6 @@ When we start out, `./scheme-libs/racket` contains a bunch of library files that
Next, we'll download the jit project and generate a few Racket files from it.
```ucm
.> project.create-empty jit-setup
jit-setup/main> lib.install @unison/internal/releases/0.0.17
```

View File

@ -1,10 +1,9 @@
```ucm
.> project.create-empty diffs
diffs/main> builtins.merge
```
```unison
term =
term =
_ = "Here's some text"
1 + 1
@ -17,7 +16,7 @@ diffs/main> branch.create new
```
```unison
term =
term =
_ = "Here's some different text"
1 + 2

View File

@ -1,27 +1,11 @@
```ucm
.> project.create-empty diffs
🎉 I've created the project diffs.
🎨 Type `ui` to explore this project's code in your browser.
🔭 Discover libraries at https://share.unison-lang.org
📖 Use `help-topic projects` to learn more about projects.
Write your first Unison code with UCM:
1. Open scratch.u.
2. Write some Unison code and save the file.
3. In UCM, type `add` to save it to your new project.
🎉 🥳 Happy coding!
diffs/main> builtins.merge
Done.
```
```unison
term =
term =
_ = "Here's some text"
1 + 1
@ -59,7 +43,7 @@ diffs/main> branch.create new
```
```unison
term =
term =
_ = "Here's some different text"
1 + 2

View File

@ -5,7 +5,6 @@
This is a regression test, previously `delete.namespace` allowed a delete as long as the deletions had a name _anywhere_ in your codebase, it should only check the current project branch.
```ucm:hide
.> project.create-empty myproject
myproject/main> builtins.merge
```

View File

@ -2,7 +2,6 @@ Deleting the branch you are on takes you to its parent (though this is impossibl
your working directory with each command).
```ucm
.> project.create-empty foo
foo/main> branch topic
foo/topic> delete.branch /topic
```

View File

@ -2,22 +2,6 @@ Deleting the branch you are on takes you to its parent (though this is impossibl
your working directory with each command).
```ucm
.> project.create-empty foo
🎉 I've created the project foo.
🎨 Type `ui` to explore this project's code in your browser.
🔭 Discover libraries at https://share.unison-lang.org
📖 Use `help-topic projects` to learn more about projects.
Write your first Unison code with UCM:
1. Open scratch.u.
2. Write some Unison code and save the file.
3. In UCM, type `add` to save it to your new project.
🎉 🥳 Happy coding!
foo/main> branch topic
Done. I've created the topic branch based off of main.

View File

@ -2,7 +2,6 @@ If `foo#old` exists in old, and `foo#new` exists in new, you might think `upgrad
`#old` with references to `#new`. And it will... !!unless!! `#old` still exists in new.
```ucm:hide
.> project.create-empty foo
foo/main> builtins.merge lib.builtin
```

View File

@ -1,5 +1,4 @@
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio lib.builtin
```

View File

@ -1,5 +1,4 @@
```ucm
.> project.create-empty test-ls
test-ls/main> builtins.merge
```

View File

@ -1,20 +1,4 @@
```ucm
.> project.create-empty test-ls
🎉 I've created the project test-ls.
🎨 Type `ui` to explore this project's code in your browser.
🔭 Discover libraries at https://share.unison-lang.org
📖 Use `help-topic projects` to learn more about projects.
Write your first Unison code with UCM:
1. Open scratch.u.
2. Write some Unison code and save the file.
3. In UCM, type `add` to save it to your new project.
🎉 🥳 Happy coding!
test-ls/main> builtins.merge
Done.

View File

@ -1,5 +1,4 @@
```ucm:hide
.> project.create-empty myproj
myproj/main> builtins.merge
```

View File

@ -1,5 +1,4 @@
```ucm:hide
.> project.create-empty myproject
myproject/main> builtins.merge
```

View File

@ -1,5 +1,4 @@
```ucm:hide
.> project.create-empty foo
foo/main> builtins.merge
```

View File

@ -1,5 +1,4 @@
```ucm
.> project.create-empty test-5055
test-5055/main> builtins.merge
```

View File

@ -1,20 +1,4 @@
```ucm
.> project.create-empty test-5055
🎉 I've created the project test-5055.
🎨 Type `ui` to explore this project's code in your browser.
🔭 Discover libraries at https://share.unison-lang.org
📖 Use `help-topic projects` to learn more about projects.
Write your first Unison code with UCM:
1. Open scratch.u.
2. Write some Unison code and save the file.
3. In UCM, type `add` to save it to your new project.
🎉 🥳 Happy coding!
test-5055/main> builtins.merge
Done.

View File

@ -40,7 +40,6 @@ Namespace args
Project Branch args
```ucm
.> project.create-empty myproject
myproject/main> branch mybranch
.> debug.fuzzy-options switch _
```

View File

@ -65,22 +65,6 @@ Namespace args
Project Branch args
```ucm
.> project.create-empty myproject
🎉 I've created the project myproject.
🎨 Type `ui` to explore this project's code in your browser.
🔭 Discover libraries at https://share.unison-lang.org
📖 Use `help-topic projects` to learn more about projects.
Write your first Unison code with UCM:
1. Open scratch.u.
2. Write some Unison code and save the file.
3. In UCM, type `add` to save it to your new project.
🎉 🥳 Happy coding!
myproject/main> branch mybranch
Done. I've created the mybranch branch based off of main.

View File

@ -9,7 +9,6 @@ contains both additions.
## Basic merge: two unconflicted adds
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -52,7 +51,6 @@ project/alice> view foo bar
If Alice and Bob also happen to add the same definition, that's not a conflict.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
project/main> branch alice
```
@ -94,7 +92,6 @@ project/alice> view foo bar
Updates that occur in one branch are propagated to the other. In this example, Alice updates `foo`, while Bob adds a new dependent `bar` of the original `foo`. When Bob's branch is merged into Alice's, her update to `foo` is propagated to his `bar`.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -150,7 +147,6 @@ We classify something as an update if its "syntactic hash"—not its normal Unis
Let's see an example. We have `foo`, which depends on `bar` and `baz`. Alice updates `bar` (propagating to `foo`), and Bob updates `baz` (propagating to `foo`). When we merge their updates, both updates will be reflected in the final `foo`.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -215,7 +211,6 @@ project/alice> display foo
Of course, it's also possible for Alice's update to propagate to one of Bob's updates. In this example, `foo` depends on `bar` which depends on `baz`. Alice updates `baz`, propagating to `bar` and `foo`, while Bob updates `bar` (to something that still depends on `foo`), propagating to `baz`. The merged result will have Alice's update to `foo` incorporated into Bob's updated `bar`, and both updates will propagate to `baz`.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -286,7 +281,6 @@ project/alice> display foo
We don't currently consider "update + delete" a conflict like Git does. In this situation, the delete is just ignored, allowing the update to proceed.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -334,7 +328,6 @@ In a future version, we'd like to give the user a warning at least.
Library dependencies don't cause merge conflicts, the library dependencies are just unioned together. If two library dependencies have the same name but different namespace hashes, then the merge algorithm makes up two fresh names.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -389,7 +382,6 @@ project/alice> view foo bar baz
If Bob is equals Alice, then merging Bob into Alice looks like this.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -408,7 +400,6 @@ project/alice> merge /bob
If Bob is behind Alice, then merging Bob into Alice looks like this.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -437,7 +428,6 @@ project/alice> merge /bob
If Bob is ahead of Alice, then merging Bob into Alice looks like this.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -470,7 +460,6 @@ This can cause merge failures due to out-of-scope identifiers, and the user may
In this example, Alice deletes `foo`, while Bob adds a new dependent of `foo`.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -514,7 +503,6 @@ It may be Alice's and Bob's changes merge together cleanly in the sense that the
In this example, Alice updates a `Text` to a `Nat`, while Bob adds a new dependent of the `Text`. Upon merging, propagating Alice's update to Bob's dependent causes a typechecking failure.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -564,7 +552,6 @@ Alice and Bob may disagree about the definition of a term. In this case, the con
are presented to the user to resolve.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -629,7 +616,6 @@ project/merge-bob-into-alice> view bar baz
Ditto for types; if the hashes don't match, it's a conflict. In this example, Alice and Bob do different things to the same constructor. However, any explicit changes to the same type will result in a conflict, including changes that could concievably be merged (e.g. Alice and Bob both add a new constructor, or edit different constructors).
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -673,7 +659,6 @@ project/alice> merge /bob
We model the renaming of a type's constructor as an update, so if Alice updates a type and Bob renames one of its constructors (even without changing its structure), we consider it a conflict.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -717,7 +702,6 @@ project/alice> merge /bob
Here is another example demonstrating that constructor renames are modeled as updates.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -756,7 +740,6 @@ project/alice> merge bob
A constructor on one side can conflict with a regular term definition on the other.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -798,7 +781,6 @@ project/alice> merge bob
Here's a subtle situation where a new type is added on each side of the merge, and an existing term is replaced with a constructor of one of the types.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -848,7 +830,6 @@ project/alice> merge bob
Here's a more involved example that demonstrates the same idea.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -928,7 +909,6 @@ which is a parse error.
We will resolve this situation automatically in a future version.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -978,7 +958,6 @@ There are a number of conditions under which we can't perform a merge, and the u
If `foo` and `bar` are aliases in the nearest common ancestor, but not in Alice's branch, then we don't know whether to update Bob's dependents to Alice's `foo` or Alice's `bar` (and vice-versa).
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -1036,7 +1015,6 @@ conflict involving a builtin, we can't perform a merge.
One way to fix this in the future would be to introduce a syntax for defining aliases in the scratch file.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -1075,7 +1053,6 @@ project/alice> merge /bob
Each naming of a decl may not have more than one name for each constructor, within the decl's namespace.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -1122,7 +1099,6 @@ project/alice> merge /bob
Each naming of a decl must have a name for each constructor, within the decl's namespace.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -1170,7 +1146,6 @@ project/alice> merge /bob
A decl cannot be aliased within the namespace of another of its aliased.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -1219,7 +1194,6 @@ project/alice> merge /bob
Constructors may only exist within the corresponding decl's namespace.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -1264,7 +1238,6 @@ project/alice> merge bob
By convention, `lib` can only namespaces; each of these represents a library dependencies. Individual terms and types are not allowed at the top level of `lib`.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -1309,7 +1282,6 @@ Here's an example. We'll delete a constructor name from the LCA and still be abl
together.
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```
@ -1374,7 +1346,6 @@ project/alice> merge /bob
```ucm:hide
.> project.create-empty project
project/main> builtins.mergeio
```

View File

@ -1,6 +1,3 @@
```ucm
.> project.create-empty test
```
```ucm:error
test/main> pull @aryairani/test-almost-empty/main lib.base_latest
test/main> pull @aryairani/test-almost-empty/main a.b

View File

@ -1,22 +1,4 @@
```ucm
.> project.create-empty test
🎉 I've created the project test.
🎨 Type `ui` to explore this project's code in your browser.
🔭 Discover libraries at https://share.unison-lang.org
📖 Use `help-topic projects` to learn more about projects.
Write your first Unison code with UCM:
1. Open scratch.u.
2. Write some Unison code and save the file.
3. In UCM, type `add` to save it to your new project.
🎉 🥳 Happy coding!
```
```ucm
test/main> pull @aryairani/test-almost-empty/main lib.base_latest
The use of `pull` to install libraries is now deprecated.

View File

@ -1,7 +1,6 @@
The `release.draft` command drafts a release from the current branch.
```ucm:hide
.> project.create-empty foo
foo/main> builtins.merge
```

View File

@ -29,7 +29,6 @@ foo.a = 5
# reset branch
```ucm
.> project.create-empty foo
foo/main> history
```

View File

@ -103,22 +103,6 @@ foo.a = 5
# reset branch
```ucm
.> project.create-empty foo
🎉 I've created the project foo.
🎨 Type `ui` to explore this project's code in your browser.
🔭 Discover libraries at https://share.unison-lang.org
📖 Use `help-topic projects` to learn more about projects.
Write your first Unison code with UCM:
1. Open scratch.u.
2. Write some Unison code and save the file.
3. In UCM, type `add` to save it to your new project.
🎉 🥳 Happy coding!
foo/main> history
☝️ The namespace is empty.

View File

@ -1,8 +1,6 @@
The `switch` command switches to an existing project or branch.
```ucm:hide
.> project.create-empty foo
.> project.create-empty bar
foo/main> builtins.merge
bar/main> builtins.merge
```

View File

@ -69,7 +69,6 @@ add b = b
## Tab complete projects and branches
```ucm
.> project.create-empty myproject
myproject/main> branch mybranch
myproject/main> debug.tab-complete branch.delete /mybr
myproject/main> debug.tab-complete project.rename my

View File

@ -173,22 +173,6 @@ add b = b
## Tab complete projects and branches
```ucm
.> project.create-empty myproject
🎉 I've created the project myproject.
🎨 Type `ui` to explore this project's code in your browser.
🔭 Discover libraries at https://share.unison-lang.org
📖 Use `help-topic projects` to learn more about projects.
Write your first Unison code with UCM:
1. Open scratch.u.
2. Write some Unison code and save the file.
3. In UCM, type `add` to save it to your new project.
🎉 🥳 Happy coding!
myproject/main> branch mybranch
Done. I've created the mybranch branch based off of main.

View File

@ -1,5 +1,4 @@
```ucm:hide
.> project.create-empty myproject
myproject/main> builtins.merge lib.builtin
```

View File

@ -1,5 +1,4 @@
```ucm:hide
.> project.create-empty proj
proj/main> builtins.merge lib.builtin
```

View File

@ -1,5 +1,4 @@
```ucm:hide
.> project.create-empty proj
proj/main> builtins.merge lib.builtin
```

View File

@ -1,5 +1,4 @@
```ucm:hide
.> project.create-empty myproject
myproject/main> builtins.merge lib.builtin
```

View File

@ -1,5 +1,4 @@
```ucm:hide
.> project.create-empty myproject
myproject/main> builtins.merge lib.builtin
```